-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[V3] Code standards (black code format pass) #1650
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,18 +40,16 @@ | |
|
||
|
||
class Admin: | ||
|
||
def __init__(self, config=Config): | ||
self.conf = config.get_conf(self, 8237492837454039, | ||
force_registration=True) | ||
self.conf = config.get_conf(self, 8237492837454039, force_registration=True) | ||
|
||
self.conf.register_global( | ||
serverlocked=False | ||
) | ||
self.conf.register_global(serverlocked=False) | ||
|
||
self.conf.register_guild( | ||
announce_ignore=False, | ||
announce_channel=None, # Integer ID | ||
selfroles=[] # List of integer ID's | ||
selfroles=[], # List of integer ID's | ||
) | ||
|
||
self.__current_announcer = None | ||
|
@@ -63,8 +61,7 @@ def __unload(self): | |
pass | ||
|
||
@staticmethod | ||
async def complain(ctx: commands.Context, message: str, | ||
**kwargs): | ||
async def complain(ctx: commands.Context, message: str, **kwargs): | ||
await ctx.send(message.format(**kwargs)) | ||
|
||
def is_announcing(self) -> bool: | ||
|
@@ -78,8 +75,7 @@ def is_announcing(self) -> bool: | |
return self.__current_announcer.active or False | ||
|
||
@staticmethod | ||
def pass_heirarchy_check(ctx: commands.Context, | ||
role: discord.Role) -> bool: | ||
def pass_heirarchy_check(ctx: commands.Context, role: discord.Role) -> bool: | ||
""" | ||
Determines if the bot has a higher role than the given one. | ||
:param ctx: | ||
|
@@ -89,8 +85,7 @@ def pass_heirarchy_check(ctx: commands.Context, | |
return ctx.guild.me.top_role > role | ||
|
||
@staticmethod | ||
def pass_user_heirarchy_check(ctx: commands.Context, | ||
role: discord.Role) -> bool: | ||
def pass_user_heirarchy_check(ctx: commands.Context, role: discord.Role) -> bool: | ||
""" | ||
Determines if a user is allowed to add/remove/edit the given role. | ||
:param ctx: | ||
|
@@ -99,43 +94,40 @@ def pass_user_heirarchy_check(ctx: commands.Context, | |
""" | ||
return ctx.author.top_role > role | ||
|
||
async def _addrole(self, ctx: commands.Context, member: discord.Member, | ||
role: discord.Role): | ||
async def _addrole(self, ctx: commands.Context, member: discord.Member, role: discord.Role): | ||
try: | ||
await member.add_roles(role) | ||
except discord.Forbidden: | ||
if not self.pass_heirarchy_check(ctx, role): | ||
await self.complain(ctx, HIERARCHY_ISSUE, role=role, | ||
member=member) | ||
await self.complain(ctx, HIERARCHY_ISSUE, role=role, member=member) | ||
else: | ||
await self.complain(ctx, GENERIC_FORBIDDEN) | ||
else: | ||
await ctx.send("I successfully added {role.name} to" | ||
" {member.display_name}".format( | ||
role=role, member=member | ||
)) | ||
await ctx.send( | ||
"I successfully added {role.name} to" | ||
" {member.display_name}".format(role=role, member=member) | ||
) | ||
|
||
async def _removerole(self, ctx: commands.Context, member: discord.Member, | ||
role: discord.Role): | ||
async def _removerole(self, ctx: commands.Context, member: discord.Member, role: discord.Role): | ||
try: | ||
await member.remove_roles(role) | ||
except discord.Forbidden: | ||
if not self.pass_heirarchy_check(ctx, role): | ||
await self.complain(ctx, HIERARCHY_ISSUE, role=role, | ||
member=member) | ||
await self.complain(ctx, HIERARCHY_ISSUE, role=role, member=member) | ||
else: | ||
await self.complain(ctx, GENERIC_FORBIDDEN) | ||
else: | ||
await ctx.send("I successfully removed {role.name} from" | ||
" {member.display_name}".format( | ||
role=role, member=member | ||
)) | ||
await ctx.send( | ||
"I successfully removed {role.name} from" | ||
" {member.display_name}".format(role=role, member=member) | ||
) | ||
|
||
@commands.command() | ||
@commands.guild_only() | ||
@checks.admin_or_permissions(manage_roles=True) | ||
async def addrole(self, ctx: commands.Context, rolename: discord.Role, *, | ||
user: MemberDefaultAuthor=None): | ||
async def addrole( | ||
self, ctx: commands.Context, rolename: discord.Role, *, user: MemberDefaultAuthor = None | ||
): | ||
""" | ||
Adds a role to a user. If user is left blank it defaults to the | ||
author of the command. | ||
|
@@ -151,8 +143,9 @@ async def addrole(self, ctx: commands.Context, rolename: discord.Role, *, | |
@commands.command() | ||
@commands.guild_only() | ||
@checks.admin_or_permissions(manage_roles=True) | ||
async def removerole(self, ctx: commands.Context, rolename: discord.Role, *, | ||
user: MemberDefaultAuthor=None): | ||
async def removerole( | ||
self, ctx: commands.Context, rolename: discord.Role, *, user: MemberDefaultAuthor = None | ||
): | ||
""" | ||
Removes a role from a user. If user is left blank it defaults to the | ||
author of the command. | ||
|
@@ -173,9 +166,10 @@ async def editrole(self, ctx: commands.Context): | |
if ctx.invoked_subcommand is None: | ||
await ctx.send_help() | ||
|
||
@editrole.command(name="colour", aliases=["color", ]) | ||
async def editrole_colour(self, ctx: commands.Context, role: discord.Role, | ||
value: discord.Colour): | ||
@editrole.command(name="colour", aliases=["color"]) | ||
async def editrole_colour( | ||
self, ctx: commands.Context, role: discord.Role, value: discord.Colour | ||
): | ||
"""Edits a role's colour | ||
|
||
Use double quotes if the role contains spaces. | ||
|
@@ -185,8 +179,7 @@ async def editrole_colour(self, ctx: commands.Context, role: discord.Role, | |
!editrole colour \"The Transistor\" #ff0000 | ||
!editrole colour Test #ff9900""" | ||
author = ctx.author | ||
reason = "{}({}) changed the colour of role '{}'".format( | ||
author.name, author.id, role.name) | ||
reason = "{}({}) changed the colour of role '{}'".format(author.name, author.id, role.name) | ||
|
||
if not self.pass_user_heirarchy_check(ctx, role): | ||
await self.complain(ctx, USER_HIERARCHY_ISSUE) | ||
|
@@ -211,7 +204,8 @@ async def edit_role_name(self, ctx: commands.Context, role: discord.Role, *, nam | |
author = ctx.message.author | ||
old_name = role.name | ||
reason = "{}({}) changed the name of role '{}' to '{}'".format( | ||
author.name, author.id, old_name, name) | ||
author.name, author.id, old_name, name | ||
) | ||
|
||
if not self.pass_user_heirarchy_check(ctx, role): | ||
await self.complain(ctx, USER_HIERARCHY_ISSUE) | ||
|
@@ -240,8 +234,7 @@ async def announce(self, ctx: commands.Context, *, message: str): | |
await ctx.send("The announcement has begun.") | ||
else: | ||
prefix = ctx.prefix | ||
await self.complain(ctx, RUNNING_ANNOUNCEMENT, | ||
prefix=prefix) | ||
await self.complain(ctx, RUNNING_ANNOUNCEMENT, prefix=prefix) | ||
|
||
@announce.command(name="cancel") | ||
@checks.is_owner() | ||
|
@@ -259,22 +252,20 @@ async def announce_cancel(self, ctx): | |
@announce.command(name="channel") | ||
@commands.guild_only() | ||
@checks.guildowner_or_permissions(administrator=True) | ||
async def announce_channel(self, ctx, *, channel: discord.TextChannel=None): | ||
async def announce_channel(self, ctx, *, channel: discord.TextChannel = None): | ||
""" | ||
Changes the channel on which the bot makes announcements. | ||
""" | ||
if channel is None: | ||
channel = ctx.channel | ||
await self.conf.guild(ctx.guild).announce_channel.set(channel.id) | ||
|
||
await ctx.send("The announcement channel has been set to {}".format( | ||
channel.mention | ||
)) | ||
await ctx.send("The announcement channel has been set to {}".format(channel.mention)) | ||
|
||
@announce.command(name="ignore") | ||
@commands.guild_only() | ||
@checks.guildowner_or_permissions(administrator=True) | ||
async def announce_ignore(self, ctx, *, guild: discord.Guild=None): | ||
async def announce_ignore(self, ctx, *, guild: discord.Guild = None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it add spaces around the |
||
""" | ||
Toggles whether the announcements will ignore the given server. | ||
Defaults to the current server if none is provided. | ||
|
@@ -287,9 +278,7 @@ async def announce_ignore(self, ctx, *, guild: discord.Guild=None): | |
|
||
verb = "will" if ignored else "will not" | ||
|
||
await ctx.send("The server {} {} receive announcements.".format( | ||
guild.name, verb | ||
)) | ||
await ctx.send("The server {} {} receive announcements.".format(guild.name, verb)) | ||
|
||
async def _valid_selfroles(self, guild: discord.Guild) -> Tuple[discord.Role]: | ||
""" | ||
|
@@ -384,8 +373,10 @@ async def serverlock(self, ctx: commands.Context): | |
|
||
await ctx.send("The bot {} serverlocked.".format(verb)) | ||
|
||
# region Event Handlers | ||
# region Event Handlers | ||
async def on_guild_join(self, guild: discord.Guild): | ||
if await self._serverlock_check(guild): | ||
return | ||
|
||
|
||
# endregion |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,8 @@ | |
|
||
|
||
class Announcer: | ||
def __init__(self, ctx: commands.Context, | ||
message: str, | ||
config=None): | ||
|
||
def __init__(self, ctx: commands.Context, message: str, config=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here it does not add spaces around the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of them has a type annotation and the other does not. It's consistent and compliant. |
||
""" | ||
:param ctx: | ||
:param message: | ||
|
@@ -65,10 +64,7 @@ async def announcer(self): | |
try: | ||
await channel.send(self.message) | ||
except discord.Forbidden: | ||
await bot_owner.send("I could not announce to server: {}".format( | ||
g.id | ||
)) | ||
await bot_owner.send("I could not announce to server: {}".format(g.id)) | ||
await asyncio.sleep(0.5) | ||
|
||
self.active = False | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did this even come from. Is that compliant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's compliant and a style choice.