Skip to content

Commit

Permalink
[All] Fix all points in the repo review (https://cogboard.discord.red…
Browse files Browse the repository at this point in the history
  • Loading branch information
AAA3A-AAA3A committed Jun 14, 2023
1 parent ed18b97 commit 52bbeef
Show file tree
Hide file tree
Showing 95 changed files with 1,623 additions and 942 deletions.
2 changes: 2 additions & 0 deletions README.rst
Expand Up @@ -109,6 +109,8 @@ Credits

* Individual credits in each cog.

* Thanks to Flame for his review of my repo and his (very) detailed advices on how to improve my cogs/codes!

* Thanks to 26, Aika, Yami, Jack, Flame, Draper, Zeph and others for the discussions that helped me develop my cogs!

* Thanks to Kreusada because his repo served as a model for mine! Everything in the documentation uses the layout of his.
Expand Down
1 change: 1 addition & 0 deletions acronymgame/acronymgame.py
Expand Up @@ -28,6 +28,7 @@ def __init__(self, bot: Red) -> None:
self.cogsutils: CogsUtils = CogsUtils(cog=self)

@commands.guild_only()
@commands.bot_has_permissions(embed_links=True)
@commands.hybrid_command(aliases=["acro", "acronym"])
async def acronymgame(self, ctx: commands.Context) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion acronymgame/utils_version.json
@@ -1 +1 @@
{"needed_utils_version": 4.18}
{"needed_utils_version": 4.19}
2 changes: 1 addition & 1 deletion acronymgame/view.py
Expand Up @@ -220,7 +220,7 @@ async def on_timeout(self) -> None:

def get_acronym(self) -> str:
return "".join(
[random.choice(string.ascii_uppercase) for __ in range(random.choice(range(4, 5)))]
[random.choice(string.ascii_uppercase) for __ in range(4)] # range(random.choice(range(4, 5)))
)

@discord.ui.button(label="Join Game", emoji="🎮", style=discord.ButtonStyle.success)
Expand Down
4 changes: 3 additions & 1 deletion antinuke/antinuke.py
Expand Up @@ -138,6 +138,8 @@ async def red_get_data_for_user(self, *, user_id: int) -> typing.Dict[str, io.By
@commands.Cog.listener()
async def on_guild_channel_delete(self, old_channel: discord.abc.GuildChannel) -> None:
"""Remove all permissions from a user if they delete a channel."""
if await self.bot.cog_disabled_in_guild(cog=self, guild=old_channel.guild):
return
config = await self.config.guild(old_channel.guild).all()
logschannel = config["logschannel"]
actual_state_enabled = config["enabled"]
Expand Down Expand Up @@ -262,7 +264,7 @@ async def resetuser(
if old_roles := [
r
for r in old_roles
if r.position < ctx.guild.me.top_role.position and not r.managed
if r.position < ctx.me.top_role.position and not r.managed
]:
# await user.edit(roles=old_roles, reason=f"All former roles of {user} ({user.id}) have been restored at the request of the server owner.")
await user.add_roles(
Expand Down
2 changes: 1 addition & 1 deletion antinuke/utils_version.json
@@ -1 +1 @@
{"needed_utils_version": 4.18}
{"needed_utils_version": 4.19}
2 changes: 2 additions & 0 deletions autotraceback/autotraceback.py
Expand Up @@ -82,6 +82,8 @@ async def traceback(self, ctx: commands.Context, public: bool = True) -> None:

@commands.Cog.listener()
async def on_command_error(self, ctx: commands.Context, error: commands.CommandError) -> None:
if await self.bot.cog_disabled_in_guild(cog=self, guild=ctx.guild):
return
if isinstance(error, IGNORED_ERRORS):
return
traceback_error = "".join(
Expand Down
2 changes: 1 addition & 1 deletion autotraceback/utils_version.json
@@ -1 +1 @@
{"needed_utils_version": 4.18}
{"needed_utils_version": 4.19}
45 changes: 24 additions & 21 deletions calculator/calculator.py
Expand Up @@ -76,26 +76,26 @@ async def calculate(self, expression: str) -> str:
pass
expression = "".join(lst)
expression = expression.replace(",", ".")
expression = expression.replace(":", "/")
expression = expression.replace(" ", "")
expression = expression.replace("π", str(pi))
expression = expression.replace("pi", str(pi))
expression = expression.replace("τ", str(tau))
expression = expression.replace("tau", str(tau))
expression = expression.replace("e", str(e))
expression = expression.replace("x", "*")
expression = expression.replace(":", "/")
expression = expression.replace("÷", "/")
expression = expression.replace("**2", "^2")
expression = expression.replace("**3", "^3")
expression = expression.replace("**", "^")
expression = expression.replace("x", "*")
expression = expression.replace("√", "sqrt")
for x in self.x:
if self.x[x] in expression:
expression = expression.replace(self.x[x], f"^{x}")
variables = {
"π": pi,
"pi": pi,
"τ": tau,
"tau": tau,
"e": e,
}
# if "sqrt" in expression and "^" not in expression:
try:
result = evaluate(expression)
except EvaluatorError:
result = evaluate(expression, variables=variables)
except (EvaluatorError, TypeError): # TypeError: 'Token' object is not subscriptable, for `A(5)`.
result = None
# else:
# engine_input = "{m:" + expression + "}"
Expand All @@ -107,7 +107,7 @@ async def calculate(self, expression: str) -> str:
result = "∞"
except Exception:
result = None
return f"{result}" if result is not None else _("Error!")
return f"{result}".replace(",", " ") if result is not None else _("Error!")

async def get_embed(
self, ctx: commands.Context, expression: str, result: str
Expand Down Expand Up @@ -146,27 +146,30 @@ async def input_formatter(self, expression: str, new: str) -> str:
lst.remove("|")
except Exception:
index = 0
if new in {"abs", "cos", "sin", "tan", "In", "√"}:
if new in {"abs", "cos", "sin", "tan", "ln", "√"}:
lst.insert(index, f"{new}(")
lst.insert(index + 1, ")")
elif new == "X²":
lst.insert(index, "²")
elif new == "X³":
lst.insert(index, "³")
elif new == "Xˣ":
lst.insert(index, "^")
elif len(lst) > 1 and lst[index - 1] == "^":
try:
lst.insert(index, self.x[new])
lst.remove("^")
index -= 1
except Exception:
lst.insert(index, new)
# lst.insert(index, "^")
lst.insert(index, "^(")
lst.insert(index + 1, ")")
# elif len(lst) > 1 and lst[index - 1] == "^":
# try:
# lst.insert(index, self.x[new])
# lst.remove("^")
# index -= 1
# except Exception:
# lst.insert(index, new)
else:
lst.insert(index, new)
lst.insert(index + 1, "|")
return "".join(lst)

@commands.bot_has_permissions(embed_links=True)
@commands.hybrid_command(name="calculate", aliases=["calc"])
async def _calculate(self, ctx: commands.Context, *, calculation: str = None) -> None:
"""Calculate a simple expression."""
Expand Down
2 changes: 1 addition & 1 deletion calculator/utils_version.json
@@ -1 +1 @@
{"needed_utils_version": 4.18}
{"needed_utils_version": 4.19}
2 changes: 1 addition & 1 deletion calculator/view.py
Expand Up @@ -111,7 +111,7 @@
"emoji": "📄",
"custom_id": "history_button",
},
{"style": 2, "label": "In", "emoji": None, "custom_id": "In"},
{"style": 2, "label": "ln", "emoji": None, "custom_id": "ln"},
{"style": 2, "label": "√", "emoji": None, "custom_id": "√"},
{"style": 1, "label": "-", "emoji": None, "custom_id": "-"},
{
Expand Down
1 change: 1 addition & 0 deletions clearchannel/clearchannel.py
Expand Up @@ -82,6 +82,7 @@ async def cog_load(self):
@commands.hybrid_command(name="clearchannel")
async def cleanup_channel(self, ctx: commands.Context, confirmation: bool = False) -> None:
"""Delete ALL messages from the current channel by duplicating it and then deleting it.
For security reasons, only the server owner and the bot owner can use the command. Use the "permissions" tool for more options.
"""
config = await self.config.guild(ctx.guild).all()
Expand Down
2 changes: 1 addition & 1 deletion clearchannel/utils_version.json
@@ -1 +1 @@
{"needed_utils_version": 4.18}
{"needed_utils_version": 4.19}
5 changes: 2 additions & 3 deletions cmdchannel/cmdchannel.py
Expand Up @@ -39,6 +39,8 @@ def __init__(self, bot: Red) -> None:

@commands.Cog.listener()
async def on_message_without_command(self, message: discord.Message) -> None:
if await self.bot.cog_disabled_in_guild(cog=self, guild=message.guild) or not await self.bot.allowed_by_whitelist_blacklist(who=message.author):
return
if message.webhook_id is not None or message.author.bot:
return
context = await self.bot.get_context(message)
Expand Down Expand Up @@ -74,7 +76,6 @@ async def channel(
) -> None:
"""Act as if the command had been typed in the channel of your choice.
The prefix must not be entered if it is a command. It will be a message only, if the command is invalid.
If you do not specify a channel, the current one will be used, unless the command you want to use is the name of an existing channel (help or test for example).
Use `[p]cmdchannel`!
"""
Expand Down Expand Up @@ -106,7 +107,6 @@ async def user(
) -> None:
"""Act as if the command had been typed by imitating the specified user.
The prefix must not be entered if it is a command. It will be a message only, if the command is invalid.
If you do not specify a user, the author will be used.
Use `[p]cmduser`!
"""
Expand Down Expand Up @@ -139,7 +139,6 @@ async def userchannel(
) -> None:
"""Act as if the command had been typed in the channel of your choice by imitating the specified user.
The prefix must not be entered if it is a command. It will be a message only, if the command is invalid.
If you do not specify a user, the author will be used.
Use `[p]cmduserchannel`!
"""
Expand Down
2 changes: 1 addition & 1 deletion cmdchannel/utils_version.json
@@ -1 +1 @@
{"needed_utils_version": 4.18}
{"needed_utils_version": 4.19}
11 changes: 7 additions & 4 deletions codesnippets/codesnippets.py
Expand Up @@ -22,20 +22,20 @@

GITHUB_RE = re.compile(
r"https://(?:www\.)?github\.com/(?P<repo>[a-zA-Z0-9-]+/[\w.-]+)/blob/(?P<path>[^#>]+)"
r"((\?[^#>]+)?(#L?(?P<start_line>\d+)(([-~:]|(\.\.))L?(?P<end_line>\d+))?))?"
r"((\?[^#>]+)?(#L?L?(?P<start_line>\d+)(([-~:]|(\.\.))L?L?(?P<end_line>\d+))?))?"
)
GITHUB_GIST_RE = re.compile(
r"https://(?:www\.)?gist\.github\.com/([a-zA-Z0-9-]+)/(?P<gist_id>[a-zA-Z0-9]+)/*"
r"(?P<revision>[a-zA-Z0-9]*)/*(#file-(?P<file_path>[^#>]+))?"
r"((\?[^#->]+)?(-L?(?P<start_line>\d+)(([-~:]|(\.\.))L?(?P<end_line>\d+))?))?"
r"((\?[^#->]+)?(-L?L?(?P<start_line>\d+)(([-~:]|(\.\.))L?L?(?P<end_line>\d+))?))?"
)
GITHUB_PR_DIFF_RE = re.compile(
r"https://(?:www\.)?github\.com/(?P<repo>[a-zA-Z0-9-]+/[\w.-]+)/pull/(?P<pr_number>\d+)"
r"((\?[^#>]+)?(#L?(?P<start_line>\d+)(([-~:]|(\.\.))L?(?P<end_line>\d+))?))?"
r"((\?[^#>]+)?(#L?L?(?P<start_line>\d+)(([-~:]|(\.\.))L?L?(?P<end_line>\d+))?))?"
)
GITHUB_COMMIT_DIFF_RE = re.compile(
r"https://(?:www\.)?github\.com/(?P<repo>[a-zA-Z0-9-]+/[\w.-]+)/commit/(?P<commit_hash>[a-zA-Z0-9]*)"
r"((\?[^#>]+)?(#L?(?P<start_line>\d+)(([-~:]|(\.\.))L?(?P<end_line>\d+))?))?"
r"((\?[^#>]+)?(#L?L?(?P<start_line>\d+)(([-~:]|(\.\.))L?L?(?P<end_line>\d+))?))?"
)
GITLAB_RE = re.compile(
r"https://(?:www\.)?gitlab\.com/(?P<repo>[\w.-]+/[\w.-]+)/\-/blob/(?P<path>[^#>]+)"
Expand Down Expand Up @@ -421,9 +421,12 @@ async def codesnippets(
_("No GitHub/Gist/GitLab/BitBucket/Pastebin/Hastebin URL found.")
)
await self.send_snippets(ctx, snippets=snippets)
ctx.count_messages = len(snippets)

@commands.Cog.listener()
async def on_message_without_command(self, message: discord.Message) -> None:
if await self.bot.cog_disabled_in_guild(cog=self, guild=message.guild) or not await self.bot.allowed_by_whitelist_blacklist(who=message.author):
return
if message.webhook_id is not None or message.author.bot:
return
if message.guild is None:
Expand Down
2 changes: 1 addition & 1 deletion codesnippets/utils_version.json
@@ -1 +1 @@
{"needed_utils_version": 4.18}
{"needed_utils_version": 4.19}

0 comments on commit 52bbeef

Please sign in to comment.