Skip to content

Comments

Update audit.py#1

Open
DiabeticTurtle wants to merge 30 commits intomainfrom
development
Open

Update audit.py#1
DiabeticTurtle wants to merge 30 commits intomainfrom
development

Conversation

@DiabeticTurtle
Copy link
Owner

No description provided.

Copy link
Contributor

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some food for thought. View full project report here.

Repository owner deleted a comment from code-review-doctor bot Sep 20, 2022
Repository owner deleted a comment from code-review-doctor bot Sep 20, 2022
Repository owner deleted a comment from code-review-doctor bot Sep 20, 2022
Copy link
Contributor

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth considering. View full project report here.


info_json = Path(__file__).parent.resolve() / "info.json"
with open(info_json, encoding="utf-8") as f:
__plugin_info__ = json.loads(f.read())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__plugin_info__ = json.loads(f.read())
__plugin_info__ = json.load(f)

This can be simplified by using json.load(...). Read more.

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f-string is easier to read, write, and less computationally expensive than legacy string formatting. More.

except Exception as exc:
err = f"{type(exc).__name__}: {str(exc)}"
raise commands.BadArgument(
"Error renaming {name}#{discrim}.\n```Haskell\n{error}\n```".format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, Consider using f-string instead.

Copy link
Contributor

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth considering. View full project report here.

from discord.ext import commands


class SafeFormat(object):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return SafeString('%s.%s}' % (self[:-1], name))
return SafeString(f'{self[:-1]}.{name}}}')

Similarly, Consider using f-string instead.

Copy link
Contributor

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
!= None
is not None

Same as above: Use is not.

"""
Warns the specified member.
"""
if member == None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if role == None:
if role is None:

Likewise, Use is.

if role == None:
no_role = True

if reason != None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if channel == None:
if channel is None:

Similarly, Use is.

Copy link
Contributor

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if channel == None:
if channel is None:

Likewise, Use is.

Copy link
Contributor

@code-review-doctor code-review-doctor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth considering. View full project report here.

Repository owner deleted a comment from code-review-doctor bot Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant