diff --git a/api/routers/webhooks.py b/api/routers/webhooks.py index 81af281..8126ba8 100644 --- a/api/routers/webhooks.py +++ b/api/routers/webhooks.py @@ -59,7 +59,7 @@ def send_memes(webhook: Webhook, subreddits: Iterable[str], quantity: int): tp.submit(send_meme, webhook, subreddits) for _ in range(quantity - sent) ] - new_sent = sum([r.result() for r in results]) + new_sent = sum(r.result() for r in results) skipped += (quantity - sent) - new_sent sent += new_sent return sent, skipped diff --git a/bot/cogs/coc.py b/bot/cogs/coc.py index a085b06..15bc178 100644 --- a/bot/cogs/coc.py +++ b/bot/cogs/coc.py @@ -44,11 +44,13 @@ async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent): if payload.user_id == self.bot.user.id: return - if self.session_message_id != 0: - if payload.message_id == self.session_message_id: - if payload.emoji.id == 859056281788743690: - if payload.user_id not in self.session_users: - self.session_users.append(payload.user_id) + if ( + self.session_message_id != 0 + and payload.message_id == self.session_message_id + and payload.emoji.id == 859056281788743690 + and payload.user_id not in self.session_users + ): + self.session_users.append(payload.user_id) if payload.message_id != coc_message: return @@ -66,11 +68,13 @@ async def on_raw_reaction_remove(self, payload: discord.RawReactionActionEvent): if payload.user_id == self.bot.user.id: return - if self.session_message_id != 0: - if payload.message_id == self.session_message_id: - if payload.emoji.id == 859056281788743690: - if payload.user_id in self.session_users: - self.session_users.remove(payload.user_id) + if ( + self.session_message_id != 0 + and payload.message_id == self.session_message_id + and payload.emoji.id == 859056281788743690 + and payload.user_id in self.session_users + ): + self.session_users.remove(payload.user_id) if payload.message_id != coc_message: return @@ -118,9 +122,8 @@ async def session_start(self, ctx: commands.context): ) for member in self.role.members: - if member != ctx.author: - if member.status != discord.Status.offline: - pager.add_line(member.mention + ", ") + if member != ctx.author and member.status != discord.Status.offline: + pager.add_line(f'{member.mention}, ') if not len(pager.pages): return await ctx.send( @@ -278,7 +281,7 @@ async def coc_invite(self, ctx: commands.Context, *, url: str = None): for member_id in self.session_users: if member_id != ctx.author.id: member = self.bot.get_user(member_id) - pager.add_line(member.mention + ", ") + pager.add_line(f'{member.mention}, ') if not len(pager.pages): return await ctx.send( diff --git a/bot/cogs/github.py b/bot/cogs/github.py index 67ef4bd..813e184 100644 --- a/bot/cogs/github.py +++ b/bot/cogs/github.py @@ -244,8 +244,7 @@ async def get_file_from_svg_url( i, b"" ) # removes everything that needs to be excluded (eg. the uncentered A+) drawing = svg2rlg(BytesIO(res)) - file = BytesIO(renderPM.drawToString(drawing, fmt=fmt)) - return file + return BytesIO(renderPM.drawToString(drawing, fmt=fmt)) def process_theme(self, theme): theme = theme.lower() @@ -258,7 +257,7 @@ def repo_desc_format(result): description = result["description"] if not description: return "" - return description if len(description) < 100 else (description[:100] + "...") + return description if len(description) < 100 else f'{description[:100]}...' async def github_request( self, diff --git a/bot/cogs/help_command.py b/bot/cogs/help_command.py index 9b157ff..1164c28 100644 --- a/bot/cogs/help_command.py +++ b/bot/cogs/help_command.py @@ -24,8 +24,7 @@ def get_command_signature(self, command): async def send_bot_help(self, mapping): embed = discord.Embed(title="Bot Commands", colour=self.COLOUR) - description = self.context.bot.description - if description: + if description := self.context.bot.description: embed.description = description for cog, cmds in mapping.items(): diff --git a/bot/cogs/rtfm.py b/bot/cogs/rtfm.py index 9a5bc8f..bda3ef6 100644 --- a/bot/cogs/rtfm.py +++ b/bot/cogs/rtfm.py @@ -74,8 +74,9 @@ def session(self) -> aiohttp.ClientSession: async def build(self, target) -> None: url = self.targets[target] req = await self.session.get( - self.url_overrides.get(target, url + "/objects.inv") + self.url_overrides.get(target, f'{url}/objects.inv') ) + if req.status != 200: warnings.warn( Warning( diff --git a/bot/cogs/stackexchange.py b/bot/cogs/stackexchange.py index 7ea54e1..afed50c 100644 --- a/bot/cogs/stackexchange.py +++ b/bot/cogs/stackexchange.py @@ -106,7 +106,7 @@ async def stack_profile(self, ctx: commands.Context, **kwargs): if not data["items"]: return await ctx.send("You don't have an account in this site!") profile = data["items"][0] - embed = Embed(title=site["name"] + " Profile", color=0x0077CC) + embed = Embed(title=f'{site["name"]} Profile', color=0x0077CC) embed.add_field(name="Username", value=profile["display_name"], inline=False) embed.add_field(name="Reputation", value=profile["reputation"], inline=False) @@ -152,7 +152,7 @@ async def stackexchange_search(self, ctx: commands.Context, **kwargs): embed.set_thumbnail(url=site["icon_url"]) if data["items"]: for i, q in enumerate(data["items"], 1): - tags = "\u2800".join(["`" + t + "`" for t in q["tags"]]) + tags = "\u2800".join([f'`{t}`' for t in q["tags"]]) embed.add_field( name=str(i) + " " + html.unescape(q["title"]), value=search_result_template.format(site=site, q=q, tags=tags), diff --git a/bot/cogs/utils.py b/bot/cogs/utils.py index abd3d7b..9a48795 100644 --- a/bot/cogs/utils.py +++ b/bot/cogs/utils.py @@ -125,10 +125,11 @@ async def source(self, ctx: commands.Context, *, command=None): if command is None: return await ctx.send( embed=Embed( - description=f"My source can be found [here](https://github.com/TechStruck/TechStruck-Bot)!", - color=0x8ADCED + description='My source can be found [here](https://github.com/TechStruck/TechStruck-Bot)!', + color=0x8ADCED, + ) ) - ) + if command == "help": src = type(self.bot.help_command) @@ -143,7 +144,7 @@ async def source(self, ctx: commands.Context, *, command=None): color=0x8ADCED ) ) - + src = cmd.callback.__code__ module = cmd.callback.__module__ filename = src.co_filename diff --git a/bot/core.py b/bot/core.py index 9e4127d..819a52f 100644 --- a/bot/core.py +++ b/bot/core.py @@ -77,9 +77,13 @@ async def setprefix(self, ctx: commands.Context, *, prefix: str): async def prefix(self, ctx: commands.Context): """View current prefix of bot""" await ctx.send( - f"My prefix here is `" - + (self.bot.prefix_cache[ctx.guild.id] if ctx.guild else ".") - + "`" + ( + ( + 'My prefix here is `' + + (self.bot.prefix_cache[ctx.guild.id] if ctx.guild else ".") + ) + + "`" + ) ) @commands.command() diff --git a/bot/utils/embed_flag_input.py b/bot/utils/embed_flag_input.py index 167d627..ae8d011 100644 --- a/bot/utils/embed_flag_input.py +++ b/bot/utils/embed_flag_input.py @@ -67,11 +67,12 @@ def process_message_mentions(message: str) -> str: return "" for _type, _id in re.findall(r"(role|user):(\d{18})", message): message = message.replace( - _type + ":" + _id, f"<@!{_id}>" if _type == "user" else f"<@&{_id}>" + f'{_type}:{_id}', f"<@!{_id}>" if _type == "user" else f"<@&{_id}>" ) + for label in ("mention", "ping"): for role in ("everyone", "here"): - message = message.replace(label + ":" + role, f"@{role}") + message = message.replace(f'{label}:{role}', f"@{role}") return message @@ -172,7 +173,7 @@ def dict_to_embed(data: Dict[str, str], author: Union[User, Member] = None): setattr(embed, field, value) for field in "thumbnail", "image": if value := data.pop(field, None): - getattr(embed, "set_" + field)(url=value) + getattr(embed, f'set_{field}')(url=value) if data.pop("auto_author", False) and author: embed.set_author(name=author.display_name, icon_url=str(author.avatar_url)) diff --git a/bot/utils/fuzzy.py b/bot/utils/fuzzy.py index 8a40b73..d74a3aa 100644 --- a/bot/utils/fuzzy.py +++ b/bot/utils/fuzzy.py @@ -36,7 +36,7 @@ def partial_ratio(a, b): o = SequenceMatcher(None, short, long[start:end]) r = o.ratio() - if 100 * r > 99: + if r > 99 / 100: return 100 scores.append(r) @@ -157,9 +157,7 @@ def finder(text, collection, *, key=None, lazy=True): suggestions.append((len(r.group()), r.start(), item)) def sort_key(tup): - if key: - return tup[0], tup[1], key(tup[2]) - return tup + return (tup[0], tup[1], key(tup[2])) if key else tup if lazy: return (z for _, _, z in sorted(suggestions, key=sort_key)) diff --git a/utils/db_backup.py b/utils/db_backup.py index 56069bd..eb8c953 100644 --- a/utils/db_backup.py +++ b/utils/db_backup.py @@ -10,11 +10,13 @@ async def backup(): conn = await asyncpg.connect(str(config.database_uri)) tables = ("users", "thanks", "guilds", "jokes") - data = { - field: [dict(rec) for rec in await conn.fetch("SELECT * FROM {}".format(field))] + return { + field: [ + dict(rec) + for rec in await conn.fetch("SELECT * FROM {}".format(field)) + ] for field in tables } - return data def main(): diff --git a/utils/embed.py b/utils/embed.py index 50ec71f..810d531 100644 --- a/utils/embed.py +++ b/utils/embed.py @@ -38,11 +38,7 @@ def bot_type_converter(data, add_timestamp=False): embed_data = data.get("embed") file_names = data.get("files", []) - embed = None - - if embed_data: - embed = build_embed(embed_data) - + embed = build_embed(embed_data) if embed_data else None return text, embed, [File(fn) for fn in file_names]