Skip to content

Commit

Permalink
Formatting and final updates to deps
Browse files Browse the repository at this point in the history
  • Loading branch information
fourjr committed Jul 22, 2021
1 parent 0056ad9 commit 1a238b3
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 340 deletions.
225 changes: 133 additions & 92 deletions Pipfile.lock

Large diffs are not rendered by default.

49 changes: 11 additions & 38 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,7 @@ def command_perm(self, command_name: str) -> PermissionLevel:
logger.debug("Command %s not found.", command_name)
return PermissionLevel.INVALID
level = next(
(check.permission_level for check in command.checks if hasattr(check, "permission_level")),
None,
(check.permission_level for check in command.checks if hasattr(check, "permission_level")), None,
)
if level is None:
logger.debug("Command %s does not have a permission level.", command_name)
Expand Down Expand Up @@ -610,13 +609,7 @@ async def on_ready(self):

if self.config.get("data_collection"):
self.metadata_loop = tasks.Loop(
self.post_metadata,
seconds=0,
minutes=0,
hours=1,
count=None,
reconnect=True,
loop=None,
self.post_metadata, seconds=0, minutes=0, hours=1, count=None, reconnect=True, loop=None,
)
self.metadata_loop.before_loop(self.before_post_metadata)
self.metadata_loop.start()
Expand Down Expand Up @@ -769,8 +762,7 @@ def check_manual_blocked(self, author: discord.Member) -> bool:
end_time = re.search(r"%([^%]+?)%", blocked_reason)
if end_time is not None:
logger.warning(
r"Deprecated time message for user %s, block and unblock again to update.",
author.name,
r"Deprecated time message for user %s, block and unblock again to update.", author.name,
)

if end_time is not None:
Expand All @@ -791,11 +783,7 @@ async def _process_blocked(self, message):
return False

async def is_blocked(
self,
author: discord.User,
*,
channel: discord.TextChannel = None,
send_message: bool = False,
self, author: discord.User, *, channel: discord.TextChannel = None, send_message: bool = False,
) -> typing.Tuple[bool, str]:

member = self.guild.get_member(author.id)
Expand Down Expand Up @@ -826,9 +814,7 @@ async def is_blocked(
if send_message:
await channel.send(
embed=discord.Embed(
title="Message not sent!",
description=new_reason,
color=self.error_color,
title="Message not sent!", description=new_reason, color=self.error_color,
)
)
return True
Expand Down Expand Up @@ -927,8 +913,7 @@ async def process_dm_modmail(self, message: discord.Message) -> None:
description=self.config["disabled_current_thread_response"],
)
embed.set_footer(
text=self.config["disabled_current_thread_footer"],
icon_url=self.guild.icon_url,
text=self.config["disabled_current_thread_footer"], icon_url=self.guild.icon_url,
)
logger.info("A message was blocked from %s due to disabled Modmail.", message.author)
await self.add_reaction(message, blocked_emoji)
Expand Down Expand Up @@ -1289,18 +1274,14 @@ async def on_raw_reaction_add(self, payload):
await message.remove_reaction(payload.emoji, member)
await message.add_reaction(emoji_fmt) # bot adds as well

if self.config["dm_disabled"] in (
DMDisabled.NEW_THREADS,
DMDisabled.ALL_THREADS,
):
if self.config["dm_disabled"] in (DMDisabled.NEW_THREADS, DMDisabled.ALL_THREADS,):
embed = discord.Embed(
title=self.config["disabled_new_thread_title"],
color=self.error_color,
description=self.config["disabled_new_thread_response"],
)
embed.set_footer(
text=self.config["disabled_new_thread_footer"],
icon_url=self.guild.icon_url,
text=self.config["disabled_new_thread_footer"], icon_url=self.guild.icon_url,
)
logger.info(
"A new thread using react to contact was blocked from %s due to disabled Modmail.",
Expand Down Expand Up @@ -1359,9 +1340,7 @@ async def on_member_remove(self, member):
if thread:
if self.config["close_on_leave"]:
await thread.close(
closer=member.guild.me,
message=self.config["close_on_leave_reason"],
silent=True,
closer=member.guild.me, message=self.config["close_on_leave_reason"], silent=True,
)
else:
embed = discord.Embed(
Expand Down Expand Up @@ -1544,9 +1523,7 @@ async def autoupdate(self):
commit_data = data["data"]
user = data["user"]
embed.set_author(
name=user["username"] + " - Updating Bot",
icon_url=user["avatar_url"],
url=user["url"],
name=user["username"] + " - Updating Bot", icon_url=user["avatar_url"], url=user["url"],
)

embed.set_footer(text=f"Updating Modmail v{self.version} " f"-> v{latest.version}")
Expand Down Expand Up @@ -1575,11 +1552,7 @@ async def autoupdate(self):
pass

command = "git pull"
proc = await asyncio.create_subprocess_shell(
command,
stderr=PIPE,
stdout=PIPE,
)
proc = await asyncio.create_subprocess_shell(command, stderr=PIPE, stdout=PIPE,)
err = await proc.stderr.read()
err = err.decode("utf-8").rstrip()
res = await proc.stdout.read()
Expand Down
84 changes: 23 additions & 61 deletions cogs/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ async def setup(self, ctx):

if self.bot.modmail_guild is None:
embed = discord.Embed(
title="Error",
description="Modmail functioning guild not found.",
color=self.bot.error_color,
title="Error", description="Modmail functioning guild not found.", color=self.bot.error_color,
)
return await ctx.send(embed=embed)

Expand Down Expand Up @@ -184,9 +182,7 @@ async def snippet_raw(self, ctx, *, name: str.lower):
else:
val = truncate(escape_code_block(val), 2048 - 7)
embed = discord.Embed(
title=f'Raw snippet - "{name}":',
description=f"```\n{val}```",
color=self.bot.main_color,
title=f'Raw snippet - "{name}":', description=f"```\n{val}```", color=self.bot.main_color,
)

return await ctx.send(embed=embed)
Expand All @@ -208,9 +204,7 @@ async def snippet_add(self, ctx, name: str.lower, *, value: commands.clean_conte
"""
if name in self.bot.snippets:
embed = discord.Embed(
title="Error",
color=self.bot.error_color,
description=f"Snippet `{name}` already exists.",
title="Error", color=self.bot.error_color, description=f"Snippet `{name}` already exists.",
)
return await ctx.send(embed=embed)

Expand All @@ -234,9 +228,7 @@ async def snippet_add(self, ctx, name: str.lower, *, value: commands.clean_conte
await self.bot.config.update()

embed = discord.Embed(
title="Added snippet",
color=self.bot.main_color,
description="Successfully created snippet.",
title="Added snippet", color=self.bot.main_color, description="Successfully created snippet.",
)
return await ctx.send(embed=embed)

Expand Down Expand Up @@ -453,8 +445,7 @@ async def notify(self, ctx, *, user_or_role: Union[discord.Role, User, str.lower

if mention in mentions:
embed = discord.Embed(
color=self.bot.error_color,
description=f"{mention} is already going to be mentioned.",
color=self.bot.error_color, description=f"{mention} is already going to be mentioned.",
)
else:
mentions.append(mention)
Expand Down Expand Up @@ -489,8 +480,7 @@ async def unnotify(self, ctx, *, user_or_role: Union[discord.Role, User, str.low

if mention not in mentions:
embed = discord.Embed(
color=self.bot.error_color,
description=f"{mention} does not have a pending notification.",
color=self.bot.error_color, description=f"{mention} does not have a pending notification.",
)
else:
mentions.remove(mention)
Expand Down Expand Up @@ -526,8 +516,7 @@ async def subscribe(self, ctx, *, user_or_role: Union[discord.Role, User, str.lo

if mention in mentions:
embed = discord.Embed(
color=self.bot.error_color,
description=f"{mention} is already subscribed to this thread.",
color=self.bot.error_color, description=f"{mention} is already subscribed to this thread.",
)
else:
mentions.append(mention)
Expand Down Expand Up @@ -562,15 +551,13 @@ async def unsubscribe(self, ctx, *, user_or_role: Union[discord.Role, User, str.

if mention not in mentions:
embed = discord.Embed(
color=self.bot.error_color,
description=f"{mention} is not subscribed to this thread.",
color=self.bot.error_color, description=f"{mention} is not subscribed to this thread.",
)
else:
mentions.remove(mention)
await self.bot.config.update()
embed = discord.Embed(
color=self.bot.main_color,
description=f"{mention} is now unsubscribed from this thread.",
color=self.bot.main_color, description=f"{mention} is now unsubscribed from this thread.",
)
return await ctx.send(embed=embed)

Expand Down Expand Up @@ -697,8 +684,7 @@ async def logs(self, ctx, *, user: User = None):

if not any(not log["open"] for log in logs):
embed = discord.Embed(
color=self.bot.error_color,
description="This user does not have any previous logs.",
color=self.bot.error_color, description="This user does not have any previous logs.",
)
return await ctx.send(embed=embed)

Expand All @@ -725,8 +711,7 @@ async def logs_closed_by(self, ctx, *, user: User = None):

if not embeds:
embed = discord.Embed(
color=self.bot.error_color,
description="No log entries have been found for that query.",
color=self.bot.error_color, description="No log entries have been found for that query.",
)
return await ctx.send(embed=embed)

Expand All @@ -745,9 +730,7 @@ async def logs_delete(self, ctx, key_or_link: str):

if not success:
embed = discord.Embed(
title="Error",
description=f"Log entry `{key}` not found.",
color=self.bot.error_color,
title="Error", description=f"Log entry `{key}` not found.", color=self.bot.error_color,
)
else:
embed = discord.Embed(
Expand Down Expand Up @@ -800,8 +783,7 @@ async def logs_search(self, ctx, limit: Optional[int] = None, *, query):

if not embeds:
embed = discord.Embed(
color=self.bot.error_color,
description="No log entries have been found for that query.",
color=self.bot.error_color, description="No log entries have been found for that query.",
)
return await ctx.send(embed=embed)

Expand Down Expand Up @@ -1012,10 +994,7 @@ async def contact(

else:
thread = await self.bot.threads.create(
recipient=user,
creator=ctx.author,
category=category,
manual_trigger=manual_trigger,
recipient=user, creator=ctx.author, category=category, manual_trigger=manual_trigger,
)
if thread.cancelled:
return
Expand All @@ -1029,11 +1008,7 @@ async def contact(
else:
description = f"{ctx.author.name} has opened a Modmail thread."

em = discord.Embed(
title="New Thread",
description=description,
color=self.bot.main_color,
)
em = discord.Embed(title="New Thread", description=description, color=self.bot.main_color,)
if self.bot.config["show_timestamp"]:
em.timestamp = datetime.utcnow()
em.set_footer(icon_url=ctx.author.avatar_url)
Expand Down Expand Up @@ -1075,8 +1050,7 @@ async def blocked(self, ctx):
end_time = re.search(r"%([^%]+?)%", reason)
if end_time is not None:
logger.warning(
r"Deprecated time message for user %s, block and unblock again to update.",
id_,
r"Deprecated time message for user %s, block and unblock again to update.", id_,
)

if end_time is not None:
Expand Down Expand Up @@ -1107,8 +1081,7 @@ async def blocked(self, ctx):
end_time = re.search(r"%([^%]+?)%", reason)
if end_time is not None:
logger.warning(
r"Deprecated time message for role %s, block and unblock again to update.",
id_,
r"Deprecated time message for role %s, block and unblock again to update.", id_,
)

if end_time is not None:
Expand All @@ -1130,9 +1103,7 @@ async def blocked(self, ctx):
line = mention + f" - {reason or 'No Reason Provided'}\n"
if len(embed.description) + len(line) > 2048:
embed = discord.Embed(
title="Blocked Users (Continued)",
color=self.bot.main_color,
description=line,
title="Blocked Users (Continued)", color=self.bot.main_color, description=line,
)
embeds.append(embed)
else:
Expand All @@ -1149,9 +1120,7 @@ async def blocked(self, ctx):
line = mention + f" - {reason or 'No Reason Provided'}\n"
if len(embed.description) + len(line) > 2048:
embed = discord.Embed(
title="Blocked Roles (Continued)",
color=self.bot.main_color,
description=line,
title="Blocked Roles (Continued)", color=self.bot.main_color, description=line,
)
embeds.append(embed)
else:
Expand Down Expand Up @@ -1211,9 +1180,7 @@ async def blocked_whitelist(self, ctx, *, user: User = None):
)
else:
embed = discord.Embed(
title="Success",
color=self.bot.main_color,
description=f"{mention} is now whitelisted.",
title="Success", color=self.bot.main_color, description=f"{mention} is now whitelisted.",
)

return await ctx.send(embed=embed)
Expand Down Expand Up @@ -1291,9 +1258,7 @@ async def block(
)
else:
embed = discord.Embed(
title="Success",
color=self.bot.main_color,
description=f"{mention} is now blocked {reason}",
title="Success", color=self.bot.main_color, description=f"{mention} is now blocked {reason}",
)

if isinstance(user_or_role, discord.Role):
Expand Down Expand Up @@ -1356,9 +1321,7 @@ async def unblock(self, ctx, *, user_or_role: Union[User, Role] = None):
await self.bot.config.update()

embed = discord.Embed(
title="Success",
color=self.bot.main_color,
description=f"{mention} is no longer blocked.",
title="Success", color=self.bot.main_color, description=f"{mention} is no longer blocked.",
)
else:
embed = discord.Embed(
Expand Down Expand Up @@ -1415,8 +1378,7 @@ async def repair(self, ctx):

# Search cache for channel
user_id, thread = next(
((k, v) for k, v in self.bot.threads.cache.items() if v.channel == ctx.channel),
(-1, None),
((k, v) for k, v in self.bot.threads.cache.items() if v.channel == ctx.channel), (-1, None),
)
if thread is not None:
logger.debug("Found thread with tempered ID.")
Expand Down
Loading

0 comments on commit 1a238b3

Please sign in to comment.