Skip to content

Commit

Permalink
chore: Remove unused captcha utility code
Browse files Browse the repository at this point in the history
  • Loading branch information
rtk-rnjn committed Jun 27, 2024
1 parent 38bd97e commit c264032
Show file tree
Hide file tree
Showing 47 changed files with 772 additions and 387 deletions.
16 changes: 14 additions & 2 deletions cogs/afk/afk.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ async def _global(self, ctx: Context, *, text: Annotated[str, commands.clean_con
self.bot.afk_users.add(ctx.author.id)

@afk.command(name="for")
async def afk_till(self, ctx: Context, till: ShortTime, *, text: Annotated[str, commands.clean_content] = "AFK"):
async def afk_till(
self,
ctx: Context,
till: ShortTime,
*,
text: Annotated[str, commands.clean_content] = "AFK",
):
"""To set the AFK time."""
if till.dt.timestamp() - ctx.message.created_at.timestamp() <= 120:
return await ctx.send(f"{ctx.author.mention} time must be above 120s")
Expand All @@ -106,7 +112,13 @@ async def afk_till(self, ctx: Context, till: ShortTime, *, text: Annotated[str,
)

@afk.command(name="after")
async def afk_after(self, ctx: Context, after: ShortTime, *, text: Annotated[str, commands.clean_content] = "AFK"):
async def afk_after(
self,
ctx: Context,
after: ShortTime,
*,
text: Annotated[str, commands.clean_content] = "AFK",
):
"""To set the AFK future time."""
if after.dt.timestamp() - ctx.message.created_at.timestamp() <= 120:
return await ctx.send(f"{ctx.author.mention} time must be above 120s")
Expand Down
20 changes: 18 additions & 2 deletions cogs/automod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,15 @@ async def automod_add(self, ctx: Context, *, rule: str) -> None:

await self.bot.automod_configurations.update_one(
{"guild_id": ctx.guild.id},
{"$set": {rule: {"trigger": view.triggers, "condition": view.conditions, "action": view.actions}}},
{
"$set": {
rule: {
"trigger": view.triggers,
"condition": view.conditions,
"action": view.actions,
}
}
},
upsert=True,
)
await self.refresh_cache_specific(ctx.guild.id)
Expand All @@ -269,7 +277,15 @@ async def automod_edit(self, ctx: Context, *, rule: str) -> None:

await self.bot.automod_configurations.update_one(
{"guild_id": ctx.guild.id},
{"$set": {rule: {"trigger": view.triggers, "condition": view.conditions, "action": view.actions}}},
{
"$set": {
rule: {
"trigger": view.triggers,
"condition": view.conditions,
"action": view.actions,
}
}
},
)
await self.refresh_cache_specific(ctx.guild.id)
await ctx.reply(f"Rule `{rule}` has been updated.")
Expand Down
7 changes: 5 additions & 2 deletions cogs/automod/parsers/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def warn(
"warning_name": warning_name,
"reason": reason,
"moderator_id": moderator_id,
"expires_at": expires_at.timestamp() if expires_at is not None else None,
"expires_at": (expires_at.timestamp() if expires_at is not None else None),
},
},
}
Expand Down Expand Up @@ -100,7 +100,10 @@ async def count_during(self, *, before: datetime | None = None, after: datetime)

query = {
"guild_id": self.guild_id,
"warnings.timestamp": {"$gte": after.timestamp(), "$lte": before.timestamp()},
"warnings.timestamp": {
"$gte": after.timestamp(),
"$lte": before.timestamp(),
},
}
return await self.bot.automod_voilations.count_documents(query)

Expand Down
15 changes: 12 additions & 3 deletions cogs/autoresponder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,21 @@ async def execute_jinja(
template = await asyncio.to_thread(self.jinja_env.from_string, response)
return_data = await template.render_async(**variables)
if len(return_data) > 1990:
return f"Gave up executing {executing_what} - `{trigger}`.\nReason: `Response is too long`", True
return (
f"Gave up executing {executing_what} - `{trigger}`.\nReason: `Response is too long`",
True,
)
return return_data, False
except Exception as e:
return f"Gave up executing {executing_what}.\nReason: `{e.__class__.__name__}: {e}`", True
return (
f"Gave up executing {executing_what}.\nReason: `{e.__class__.__name__}: {e}`",
True,
)
except Exception as e:
return f"Gave up executing {executing_what} - `{trigger}`.\nReason: `{e.__class__.__name__}: {e}`", True
return (
f"Gave up executing {executing_what} - `{trigger}`.\nReason: `{e.__class__.__name__}: {e}`",
True,
)

@commands.command(name="jinja", aliases=["j2", "jinja2"])
async def jinja(self, ctx: Context, *, code: str) -> None:
Expand Down
8 changes: 7 additions & 1 deletion cogs/autoresponder/variables/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ async def _check_perms(self, **perms: bool) -> bool:
permissions = discord.Permissions(**perms)
return self.__guild.me.guild_permissions >= permissions

async def ban(self, member: JinjaMember, *, reason: str = None, delete_message_days: int = discord.utils.MISSING):
async def ban(
self,
member: JinjaMember,
*,
reason: str = None,
delete_message_days: int = discord.utils.MISSING,
):
"""Ban member from guild."""
if not await self._check_perms(ban_members=True):
return
Expand Down
54 changes: 32 additions & 22 deletions cogs/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ async def tel_config_block(self, ctx: Context, *, server: discord.Guild | int):

await self.bot.guild_configurations.update_one(
{"_id": ctx.guild.id},
{"$addToSet": {"telephone.blocked": server.id if isinstance(server, discord.Guild) else server}},
{"$addToSet": {"telephone.blocked": (server.id if isinstance(server, discord.Guild) else server)}},
upsert=True,
)
await ctx.reply(f"{ctx.author.mention} success! blocked: **{server.name}**")
Expand Down Expand Up @@ -487,7 +487,7 @@ async def enable(
ctx: Context,
command: Annotated[str, commands.clean_content],
*,
target: discord.TextChannel | discord.VoiceChannel | discord.Thread | discord.Role | None = None,
target: (discord.TextChannel | discord.VoiceChannel | discord.Thread | discord.Role | None) = None,
):
"""To enable the command."""
cmd = self.bot.get_command(command)
Expand All @@ -509,7 +509,7 @@ async def disable(
ctx: Context,
command: Annotated[str, commands.clean_content],
*,
target: discord.TextChannel | discord.VoiceChannel | discord.Thread | discord.Role | None = None,
target: (discord.TextChannel | discord.VoiceChannel | discord.Thread | discord.Role | None) = None,
):
"""To disable the command."""
cmd = self.bot.get_command(command)
Expand Down Expand Up @@ -545,42 +545,50 @@ async def cmd_config_list(self, ctx: Context, *, cmd: str):
)
.add_field(
name="Role Enable",
value="<@&" + ">, <@&".join(data.get(CMD_ROLE_ENABLE_, [0])) + ">" if data.get(CMD_ROLE_ENABLE_) else "N/A",
value=(
"<@&" + ">, <@&".join(data.get(CMD_ROLE_ENABLE_, [0])) + ">" if data.get(CMD_ROLE_ENABLE_) else "N/A"
),
inline=False,
)
.add_field(
name="Role Disable",
value="<@&" + ">, <@&".join(data.get(CMD_ROLE_DISABLE_, [0])) + ">"
if data.get(CMD_ROLE_DISABLE_)
else "N/A",
value=(
"<@&" + ">, <@&".join(data.get(CMD_ROLE_DISABLE_, [0])) + ">" if data.get(CMD_ROLE_DISABLE_) else "N/A"
),
inline=False,
)
.add_field(
name="Channel Enable",
value="<#" + ">, <#".join(data.get(CMD_CHANNEL_ENABLE_, [0])) + ">"
if data.get(CMD_CHANNEL_ENABLE_)
else "N/A",
value=(
"<#" + ">, <#".join(data.get(CMD_CHANNEL_ENABLE_, [0])) + ">" if data.get(CMD_CHANNEL_ENABLE_) else "N/A"
),
inline=False,
)
.add_field(
name="Channel Disable",
value="<#" + ">, <#".join(data.get(CMD_CHANNEL_DISABLE_, [0])) + ">"
if data.get(CMD_CHANNEL_DISABLE_)
else "N/A",
value=(
"<#" + ">, <#".join(data.get(CMD_CHANNEL_DISABLE_, [0])) + ">"
if data.get(CMD_CHANNEL_DISABLE_)
else "N/A"
),
inline=False,
)
.add_field(
name="Category Enable",
value="<#" + ">, <#".join(data.get(CMD_CATEGORY_ENABLE_, [0])) + ">"
if data.get(CMD_CATEGORY_ENABLE_)
else "N/A",
value=(
"<#" + ">, <#".join(data.get(CMD_CATEGORY_ENABLE_, [0])) + ">"
if data.get(CMD_CATEGORY_ENABLE_)
else "N/A"
),
inline=False,
)
.add_field(
name="Category Disable",
value="<#" + ">, <#".join(data.get(CMD_CATEGORY_DISABLE_, [0])) + ">"
if data.get(CMD_CATEGORY_DISABLE_)
else "N/A",
value=(
"<#" + ">, <#".join(data.get(CMD_CATEGORY_DISABLE_, [0])) + ">"
if data.get(CMD_CATEGORY_DISABLE_)
else "N/A"
),
inline=False,
)
.add_field(
Expand Down Expand Up @@ -760,9 +768,11 @@ def check(m: discord.Message) -> bool:
await self.bot.guild_configurations.update_one(
{"_id": ctx.guild.id},
{
OP: {f"stats_channels.{k}": v for k, v in PAYLOAD.items()}
if counter != "role"
else {"stats_channels.role": PAYLOAD_R},
OP: (
{f"stats_channels.{k}": v for k, v in PAYLOAD.items()}
if counter != "role"
else {"stats_channels.role": PAYLOAD_R}
),
},
upsert=True,
)
Expand Down
24 changes: 21 additions & 3 deletions cogs/config/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ async def _enable(
await update_db(ctx=ctx, key="CMD_GLOBAL_ENABLE", cmd=cmd_cog, value=True, op="$set")

elif isinstance(target, discord.TextChannel):
await update_db(ctx=ctx, key="CMD_CHANNEL_DISABLE", cmd=cmd_cog, value=ctx.channel.id, op="$pull")
await update_db(
ctx=ctx,
key="CMD_CHANNEL_DISABLE",
cmd=cmd_cog,
value=ctx.channel.id,
op="$pull",
)

elif isinstance(target, discord.Role):
await update_db(ctx=ctx, key="CMD_ROLE_DISABLE", cmd=cmd_cog, value=target.id, op="$pull")
Expand All @@ -61,9 +67,21 @@ async def _disable(
await update_db(ctx=ctx, key="CMD_GLOBAL_ENABLE", cmd=cmd_cog, value=False, op="$set")

elif isinstance(target, discord.TextChannel):
await update_db(ctx=ctx, key="CMD_CHANNEL_DISABLE", cmd=cmd_cog, value=ctx.channel.id, op="$addToSet")
await update_db(
ctx=ctx,
key="CMD_CHANNEL_DISABLE",
cmd=cmd_cog,
value=ctx.channel.id,
op="$addToSet",
)

elif isinstance(target, discord.Role):
await update_db(ctx=ctx, key="CMD_ROLE_DISABLE", cmd=cmd_cog, value=target.id, op="$addToSet")
await update_db(
ctx=ctx,
key="CMD_ROLE_DISABLE",
cmd=cmd_cog,
value=target.id,
op="$addToSet",
)

await ctx.send(get_text(ctx=ctx, cmd_cog=cmd_cog, target=target, tp="disable"))
Loading

0 comments on commit c264032

Please sign in to comment.