Conversation
There was a problem hiding this comment.
Some food for thought. View full project report here.
There was a problem hiding this comment.
Worth considering. View full project report here.
moderation/moderation.py
Outdated
|
|
||
| info_json = Path(__file__).parent.resolve() / "info.json" | ||
| with open(info_json, encoding="utf-8") as f: | ||
| __plugin_info__ = json.loads(f.read()) |
There was a problem hiding this comment.
| __plugin_info__ = json.loads(f.read()) | |
| __plugin_info__ = json.load(f) |
This can be simplified by using json.load(...). Read more.
moderation/moderation.py
Outdated
| try: | ||
| user = await self.bot.get_or_fetch_user(user_id) | ||
| except (discord.NotFound, Exception): | ||
| raise commands.BadArgument('"{}" not found. Invalid user ID.'.format(user_id)) |
There was a problem hiding this comment.
f-string is easier to read, write, and less computationally expensive than legacy string formatting. More.
moderation/moderation.py
Outdated
| except Exception as exc: | ||
| err = f"{type(exc).__name__}: {str(exc)}" | ||
| raise commands.BadArgument( | ||
| "Error renaming {name}#{discrim}.\n```Haskell\n{error}\n```".format( |
There was a problem hiding this comment.
Likewise, Consider using f-string instead.
There was a problem hiding this comment.
Worth considering. View full project report here.
| from discord.ext import commands | ||
|
|
||
|
|
||
| class SafeFormat(object): |
There was a problem hiding this comment.
| class SafeFormat(object): | |
| class SafeFormat: |
SafeFormat inherits from object by default, so explicitly inheriting from object is redundant. Removing it keeps the code simpler. Read more.
| self.__dict = kw | ||
|
|
||
| def __getitem__(self, name): | ||
| return self.__dict.get(name, SafeString('{%s}' % name)) |
There was a problem hiding this comment.
| return self.__dict.get(name, SafeString('{%s}' % name)) | |
| return self.__dict.get(name, SafeString(f'{{{name}}}')) |
f-string is easier to read, write, and less computationally expensive than legacy string formatting. Explained here.
| try: | ||
| super().__getattr__(name) | ||
| except AttributeError: | ||
| return SafeString('%s.%s}' % (self[:-1], name)) |
There was a problem hiding this comment.
| return SafeString('%s.%s}' % (self[:-1], name)) | |
| return SafeString(f'{self[:-1]}.{name}}}') |
Similarly, Consider using f-string instead.
There was a problem hiding this comment.
Some things to consider. View full project report here.
| async def on_guild_channel_create(self, channel): | ||
| """Sets up mute role permissions for the channel.""" | ||
| muterole = await self.db.find_one({"_id": "muterole"}) | ||
| if muterole == None: |
There was a problem hiding this comment.
| if muterole == None: | |
| if muterole is None: |
None is a singleton data type, so should be compared using is. More.
| return | ||
|
|
||
| role = channel.guild.get_role(muterole[str(channel.guild.id)]) | ||
| if role == None: |
There was a problem hiding this comment.
| if role == None: | |
| if role is None: |
Again, Use is.
| @checks.has_permissions(PermissionLevel.MODERATOR) | ||
| async def setlog(self, ctx, channel: discord.TextChannel = None): | ||
| """Sets up a log channel.""" | ||
| if channel == None: |
There was a problem hiding this comment.
| if channel == None: | |
| if channel is None: |
Similarly, Use is.
| ctx.guild.get_role( | ||
| (await self.db.find_one({"_id": "muterole"}))[str(ctx.guild.id)] | ||
| ) | ||
| != None |
There was a problem hiding this comment.
| != None | |
| is not None |
Same as above: Use is not.
| """ | ||
| Warns the specified member. | ||
| """ | ||
| if member == None: |
There was a problem hiding this comment.
| if member == None: | |
| if member is None: |
Same as above: Use is.
| return await ctx.send_help(ctx.command) | ||
| role = await self.db.find_one({"_id": "muterole"}) | ||
| no_role = False | ||
| if role == None: |
There was a problem hiding this comment.
| if role == None: | |
| if role is None: |
Similarly, Use is.
| no_role = True | ||
| elif str(ctx.guild.id) in role: | ||
| role = ctx.guild.get_role(role[str(ctx.guild.id)]) | ||
| if role == None: |
There was a problem hiding this comment.
| if role == None: | |
| if role is None: |
Likewise, Use is.
| if role == None: | ||
| no_role = True | ||
|
|
||
| if reason != None: |
There was a problem hiding this comment.
| if reason != None: | |
| if reason is not None: |
Likewise, Use is not.
| title="Error", | ||
| description=( | ||
| "You don't have a muted role set up.\n" | ||
| f"You will have to unmute them manually." |
There was a problem hiding this comment.
| f"You will have to unmute them manually." | |
| "You will have to unmute them manually." |
f-string is unnecessary here. This can just be a string. More details.
| Nukes (deletes EVERY message in) a channel. | ||
| You can mention a channel to nuke that one instead. | ||
| """ | ||
| if channel == None: |
There was a problem hiding this comment.
| if channel == None: | |
| if channel is None: |
Similarly, Use is.
There was a problem hiding this comment.
Some food for thought. View full project report here.
| return await ctx.send( | ||
| embed=discord.Embed( | ||
| title="Error", | ||
| description=f"You can only purge up to 2000 messages.", |
There was a problem hiding this comment.
| description=f"You can only purge up to 2000 messages.", | |
| description="You can only purge up to 2000 messages.", |
As above, f-string is unnecessary here.
| async def get_case(self): | ||
| """Gives the case number.""" | ||
| num = await self.db.find_one({"_id": "cases"}) | ||
| if num == None: |
There was a problem hiding this comment.
| if num == None: | |
| if num is None: |
As above, Use is.
| async def log(self, guild: discord.Guild, embed: discord.Embed): | ||
| """Sends logs to the log channel.""" | ||
| channel = await self.db.find_one({"_id": "logging"}) | ||
| if channel == None: |
There was a problem hiding this comment.
| if channel == None: | |
| if channel is None: |
As above, Use is.
| if not str(guild.id) in channel: | ||
| return | ||
| channel = self.bot.get_channel(channel[str(guild.id)]) | ||
| if channel == None: |
There was a problem hiding this comment.
| if channel == None: | |
| if channel is None: |
Likewise, Use is.
There was a problem hiding this comment.
Worth considering. View full project report here.
No description provided.