diff --git a/jarvis/__init__.py b/jarvis/__init__.py index e4b2a27..47d572b 100644 --- a/jarvis/__init__.py +++ b/jarvis/__init__.py @@ -4,7 +4,7 @@ import logging from dis_snek import Intents, Snake from mongoengine import connect -from jarvis import logo # noqa: F401 +# from jarvis import logo # noqa: F401 from jarvis import tasks, utils from jarvis.config import get_config from jarvis.events import guild, member, message @@ -56,7 +56,7 @@ def run() -> None: print( " https://discord.com/api/oauth2/authorize?client_id=" - + "{}&permissions=8&scope=bot%20applications.commands".format(jconfig.client_id) # noqa: W503 + "{}&permissions=8&scope=bot%20applications.commands".format(jconfig.client_id) ) jarvis.max_messages = jconfig.max_messages diff --git a/jarvis/cogs/admin/ban.py b/jarvis/cogs/admin/ban.py index b04e7c9..7b197f5 100644 --- a/jarvis/cogs/admin/ban.py +++ b/jarvis/cogs/admin/ban.py @@ -90,8 +90,12 @@ class BanCog(CacheCog): await ctx.send(embed=embed) @slash_command(name="ban", description="Ban a user") - @slash_option(name="user", description="User to ban", option_type=OptionTypes.USER, required=True) - @slash_option(name="reason", description="Ban reason", option_type=OptionTypes.STRING, required=True) + @slash_option( + name="user", description="User to ban", option_type=OptionTypes.USER, required=True + ) + @slash_option( + name="reason", description="Ban reason", option_type=OptionTypes.STRING, required=True + ) @slash_option( name="btype", description="Ban type", @@ -181,8 +185,12 @@ class BanCog(CacheCog): await self.discord_apply_ban(ctx, reason, user, duration, active, fields, mtype) @slash_command(name="unban", description="Unban a user") - @slash_option(name="user", description="User to unban", option_type=OptionTypes.STRING, required=True) - @slash_option(name="reason", description="Unban reason", option_type=OptionTypes.STRING, required=True) + @slash_option( + name="user", description="User to unban", option_type=OptionTypes.STRING, required=True + ) + @slash_option( + name="reason", description="Unban reason", option_type=OptionTypes.STRING, required=True + ) @admin_or_permissions(Permissions.BAN_MEMBERS) async def _unban( self, @@ -219,9 +227,14 @@ class BanCog(CacheCog): if len(results) > 1: active_bans = [] for ban in bans: - active_bans.append("{0} ({1}): {2}".format(ban.user.username, ban.user.id, ban.reason)) + active_bans.append( + "{0} ({1}): {2}".format(ban.user.username, ban.user.id, ban.reason) + ) ab_message = "\n".join(active_bans) - message = f"More than one result. Please use one of the following IDs:\n```{ab_message}\n```" + message = ( + "More than one result. " + f"Please use one of the following IDs:\n```{ab_message}\n```" + ) await ctx.send(message) return else: @@ -263,9 +276,13 @@ class BanCog(CacheCog): admin=ctx.author.id, reason=reason, ).save() - await ctx.send("Unable to find user in Discord, " + "but removed entry from database.") + await ctx.send( + "Unable to find user in Discord, " + "but removed entry from database." + ) - @slash_command(name="bans", description="User bans", sub_cmd_name="list", sub_cmd_description="List bans") + @slash_command( + name="bans", description="User bans", sub_cmd_name="list", sub_cmd_description="List bans" + ) @slash_option( name="btype", description="Ban type", @@ -356,7 +373,7 @@ class BanCog(CacheCog): pages.append(embed) else: for i in range(0, len(bans), 5): - embed = build_embed(title=title, description="", fields=fields[i : i + 5]) # noqa: E203 + embed = build_embed(title=title, description="", fields=fields[i : i + 5]) embed.set_thumbnail(url=ctx.guild.icon_url) pages.append(embed) diff --git a/jarvis/cogs/admin/kick.py b/jarvis/cogs/admin/kick.py index 34f5ed2..b551225 100644 --- a/jarvis/cogs/admin/kick.py +++ b/jarvis/cogs/admin/kick.py @@ -17,8 +17,12 @@ class KickCog(Scale): """J.A.R.V.I.S. KickCog.""" @slash_command(name="kick", description="Kick a user") - @slash_option(name="user", description="User to kick", option_type=OptionTypes.USER, required=True) - @slash_option(name="reason", description="Kick reason", option_type=OptionTypes.STRING, required=True) + @slash_option( + name="user", description="User to kick", option_type=OptionTypes.USER, required=True + ) + @slash_option( + name="reason", description="Kick reason", option_type=OptionTypes.STRING, required=True + ) @admin_or_permissions(Permissions.BAN_MEMBERS) async def _kick(self, ctx: InteractionContext, user: User, reason: str) -> None: if not user or user == ctx.author: diff --git a/jarvis/cogs/admin/mute.py b/jarvis/cogs/admin/mute.py index 9261b18..ae1e0f8 100644 --- a/jarvis/cogs/admin/mute.py +++ b/jarvis/cogs/admin/mute.py @@ -22,7 +22,9 @@ class MuteCog(Scale): self.bot = bot @slash_command(name="mute", description="Mute a user") - @slash_option(name="user", description="User to mute", option_type=OptionTypes.USER, required=True) + @slash_option( + name="user", description="User to mute", option_type=OptionTypes.USER, required=True + ) @slash_option( name="reason", description="Reason for mute", @@ -47,7 +49,9 @@ class MuteCog(Scale): SlashCommandChoice(name="Week(s)", value=604800), ], ) - @admin_or_permissions(Permissions.MUTE_MEMBERS, Permissions.BAN_MEMBERS, Permissions.KICK_MEMBERS) + @admin_or_permissions( + Permissions.MUTE_MEMBERS, Permissions.BAN_MEMBERS, Permissions.KICK_MEMBERS + ) async def _timeout( self, ctx: InteractionContext, user: Member, reason: str, time: int = 1, scale: int = 60 ) -> None: @@ -83,10 +87,17 @@ class MuteCog(Scale): await ctx.send(embed=embed) @slash_command(name="unmute", description="Unmute a user") - @slash_option(name="user", description="User to unmute", option_type=OptionTypes.USER, required=True) - @admin_or_permissions(Permissions.MUTE_MEMBERS, Permissions.BAN_MEMBERS, Permissions.KICK_MEMBERS) + @slash_option( + name="user", description="User to unmute", option_type=OptionTypes.USER, required=True + ) + @admin_or_permissions( + Permissions.MUTE_MEMBERS, Permissions.BAN_MEMBERS, Permissions.KICK_MEMBERS + ) async def _unmute(self, ctx: InteractionContext, user: Member) -> None: - if not user.communication_disabled_until or user.communication_disabled_until < datetime.now(): + if ( + not user.communication_disabled_until + or user.communication_disabled_until < datetime.now() # noqa: W503 + ): await ctx.send("User is not muted", hidden=True) return diff --git a/jarvis/cogs/admin/purge.py b/jarvis/cogs/admin/purge.py index adae1ac..6e95950 100644 --- a/jarvis/cogs/admin/purge.py +++ b/jarvis/cogs/admin/purge.py @@ -64,7 +64,9 @@ class PurgeCog(commands.Cog): ], ) @admin_or_permissions(manage_messages=True) - async def _autopurge_add(self, ctx: SlashContext, channel: TextChannel, delay: int = 30) -> None: + async def _autopurge_add( + self, ctx: SlashContext, channel: TextChannel, delay: int = 30 + ) -> None: if not isinstance(channel, TextChannel): await ctx.send("Channel must be a TextChannel", hidden=True) return diff --git a/jarvis/cogs/admin/roleping.py b/jarvis/cogs/admin/roleping.py index 46ee2c5..fe81488 100644 --- a/jarvis/cogs/admin/roleping.py +++ b/jarvis/cogs/admin/roleping.py @@ -97,7 +97,10 @@ class RolepingCog(CacheCog): role = ctx.guild.get_role(roleping.role) bypass_roles = list(filter(lambda x: x.id in roleping.bypass["roles"], ctx.guild.roles)) bypass_roles = [r.mention or "||`[redacted]`||" for r in bypass_roles] - bypass_users = [ctx.guild.get_member(u).mention or "||`[redacted]`||" for u in roleping.bypass["users"]] + bypass_users = [ + ctx.guild.get_member(u).mention or "||`[redacted]`||" + for u in roleping.bypass["users"] + ] bypass_roles = bypass_roles or ["None"] bypass_users = bypass_users or ["None"] embed = build_embed( @@ -242,7 +245,8 @@ class RolepingCog(CacheCog): if len(roleping.bypass["roles"]) == 10: await ctx.send( - "Already have 10 roles in bypass. Please consider consolidating roles for roleping bypass", + "Already have 10 roles in bypass. " + "Please consider consolidating roles for roleping bypass", hidden=True, ) return @@ -323,7 +327,8 @@ class RolepingCog(CacheCog): if len(roleping.bypass["roles"]) == 10: await ctx.send( - "Already have 10 roles in bypass. Please consider consolidating roles for roleping bypass", + "Already have 10 roles in bypass. " + "Please consider consolidating roles for roleping bypass", hidden=True, ) return diff --git a/jarvis/cogs/admin/warning.py b/jarvis/cogs/admin/warning.py index ec18e9a..81ed296 100644 --- a/jarvis/cogs/admin/warning.py +++ b/jarvis/cogs/admin/warning.py @@ -116,7 +116,9 @@ class WarningCog(CacheCog): user=user.id, guild=ctx.guild.id, ).order_by("-created_at") - active_warns = Warning.objects(user=user.id, guild=ctx.guild.id, active=True).order_by("-created_at") + active_warns = Warning.objects(user=user.id, guild=ctx.guild.id, active=True).order_by( + "-created_at" + ) pages = [] if active: @@ -146,8 +148,10 @@ class WarningCog(CacheCog): for i in range(0, len(fields), 5): embed = build_embed( title="Warnings", - description=f"{warnings.count()} total | {active_warns.count()} currently active", - fields=fields[i : i + 5], # noqa: E203 + description=( + f"{warnings.count()} total | {active_warns.count()} currently active" + ), + fields=fields[i : i + 5], ) embed.set_author( name=user.name + "#" + user.discriminator, @@ -171,8 +175,10 @@ class WarningCog(CacheCog): for i in range(0, len(fields), 5): embed = build_embed( title="Warnings", - description=f"{warnings.count()} total | {active_warns.count()} currently active", - fields=fields[i : i + 5], # noqa: E203 + description=( + f"{warnings.count()} total | {active_warns.count()} currently active" + ), + fields=fields[i : i + 5], ) embed.set_author( name=user.name + "#" + user.discriminator, diff --git a/jarvis/cogs/autoreact.py b/jarvis/cogs/autoreact.py index 378f705..6d1263f 100644 --- a/jarvis/cogs/autoreact.py +++ b/jarvis/cogs/autoreact.py @@ -108,7 +108,9 @@ class AutoReactCog(commands.Cog): return exists = Autoreact.objects(guild=ctx.guild.id, channel=channel.id).first() if not exists: - await ctx.send(f"Please create autoreact first with /autoreact create {channel.mention}") + await ctx.send( + f"Please create autoreact first with /autoreact create {channel.mention}" + ) return if emote in exists.reactions: await ctx.send( @@ -188,7 +190,9 @@ class AutoReactCog(commands.Cog): return message = "" if len(exists.reactions) > 0: - message = f"Current active autoreacts on {channel.mention}:\n" + "\n".join(exists.reactions) + message = f"Current active autoreacts on {channel.mention}:\n" + "\n".join( + exists.reactions + ) else: message = f"No reactions set on {channel.mention}" await ctx.send(message) diff --git a/jarvis/cogs/ctc2.py b/jarvis/cogs/ctc2.py index b236e69..381686e 100644 --- a/jarvis/cogs/ctc2.py +++ b/jarvis/cogs/ctc2.py @@ -18,7 +18,7 @@ guild_ids = [578757004059738142, 520021794380447745, 862402786116763668] valid = re.compile(r"[\w\s\-\\/.!@#$%^*()+=<>,\u0080-\U000E0FFF]*") invites = re.compile( - r"(?:https?://)?(?:www.)?(?:discord.(?:gg|io|me|li)|discord(?:app)?.com/invite)/([^\s/]+?)(?=\b)", + r"(?:https?://)?(?:www.)?(?:discord.(?:gg|io|me|li)|discord(?:app)?.com/invite)/([^\s/]+?)(?=\b)", # noqa: E501 flags=re.IGNORECASE, ) @@ -54,13 +54,19 @@ class CTCCog(CacheCog): async def _pw(self, ctx: SlashContext, guess: str) -> None: if len(guess) > 800: await ctx.send( - "Listen here, dipshit. Don't be like <@256110768724901889>. Make your guesses < 800 characters.", + ( + "Listen here, dipshit. Don't be like <@256110768724901889>. " + "Make your guesses < 800 characters." + ), hidden=True, ) return elif not valid.fullmatch(guess): await ctx.send( - "Listen here, dipshit. Don't be like <@256110768724901889>. Make your guesses *readable*.", + ( + "Listen here, dipshit. Don't be like <@256110768724901889>. " + "Make your guesses *readable*." + ), hidden=True, ) return @@ -124,7 +130,7 @@ class CTCCog(CacheCog): embed = build_embed( title="completethecodetwo.cards guesses", description=f"{len(fields)} guesses so far", - fields=fields[i : i + 5], # noqa: E203 + fields=fields[i : i + 5], url="https://completethecodetwo.cards", ) embed.set_thumbnail(url="https://dev.zevaryx.com/db_logo.png") diff --git a/jarvis/cogs/dbrand.py b/jarvis/cogs/dbrand.py index 79e4904..884de2b 100644 --- a/jarvis/cogs/dbrand.py +++ b/jarvis/cogs/dbrand.py @@ -230,7 +230,8 @@ class DbrandCog(commands.Cog): embed = build_embed( title="Check Shipping Times", description=( - "Country not found.\nYou can [view all shipping " "destinations here](https://dbrand.com/shipping)" + "Country not found.\nYou can [view all shipping " + "destinations here](https://dbrand.com/shipping)" ), fields=[], url="https://dbrand.com/shipping", diff --git a/jarvis/cogs/dev.py b/jarvis/cogs/dev.py index 4345c0c..7df8699 100644 --- a/jarvis/cogs/dev.py +++ b/jarvis/cogs/dev.py @@ -18,9 +18,11 @@ from jarvis.utils.field import Field supported_hashes = {x for x in hashlib.algorithms_guaranteed if "shake" not in x} OID_VERIFY = re.compile(r"^([1-9][0-9]{0,3}|0)(\.([1-9][0-9]{0,3}|0)){5,13}$") -URL_VERIFY = re.compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+") +URL_VERIFY = re.compile( + r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+" +) DN_VERIFY = re.compile( - r"^(?:(?PCN=(?P[^,]*)),)?(?:(?P(?:(?:CN|OU)=[^,]+,?)+),)?(?P(?:DC=[^,]+,?)+)$" + r"^(?:(?PCN=(?P[^,]*)),)?(?:(?P(?:(?:CN|OU)=[^,]+,?)+),)?(?P(?:DC=[^,]+,?)+)$" # noqa: E501 ) ULID_VERIFY = re.compile(r"^[0-9a-z]{26}$", re.IGNORECASE) UUID_VERIFY = re.compile( @@ -29,7 +31,7 @@ UUID_VERIFY = re.compile( ) invites = re.compile( - r"(?:https?://)?(?:www.)?(?:discord.(?:gg|io|me|li)|discord(?:app)?.com/invite)/([^\s/]+?)(?=\b)", + r"(?:https?://)?(?:www.)?(?:discord.(?:gg|io|me|li)|discord(?:app)?.com/invite)/([^\s/]+?)(?=\b)", # noqa: E501 flags=re.IGNORECASE, ) @@ -47,7 +49,7 @@ def hash_obj(hash: Any, data: Union[str, bytes], text: bool = True) -> str: BSIZE = 65536 block_idx = 0 while block_idx * BSIZE < len(data): - block = data[BSIZE * block_idx : BSIZE * (block_idx + 1)] # noqa: E203 + block = data[BSIZE * block_idx : BSIZE * (block_idx + 1)] hash.update(block) block_idx += 1 return hash.hexdigest() @@ -253,7 +255,9 @@ class DevCog(commands.Cog): ) @commands.cooldown(1, 30, commands.BucketType.channel) async def _cloc(self, ctx: SlashContext) -> None: - output = subprocess.check_output(["tokei", "-C", "--sort", "code"]).decode("UTF-8") # noqa: S603, S607 + output = subprocess.check_output( # noqa: S603, S607 + ["tokei", "-C", "--sort", "code"] + ).decode("UTF-8") await ctx.send(f"```\n{output}\n```") diff --git a/jarvis/cogs/error.py b/jarvis/cogs/error.py index 82f93a9..3715d03 100644 --- a/jarvis/cogs/error.py +++ b/jarvis/cogs/error.py @@ -20,7 +20,8 @@ class ErrorHandlerCog(commands.Cog): return elif isinstance(error, commands.errors.CommandOnCooldown): await ctx.send( - "Command on cooldown. " + f"Please wait {error.retry_after:0.2f}s before trying again", + "Command on cooldown. " + f"Please wait {error.retry_after:0.2f}s before trying again", ) else: await ctx.send(f"Error processing command:\n```{error}```") @@ -29,13 +30,16 @@ class ErrorHandlerCog(commands.Cog): @commands.Cog.listener() async def on_slash_command_error(self, ctx: SlashContext, error: Exception) -> None: """discord_slash on_slash_command_error override.""" - if isinstance(error, commands.errors.MissingPermissions) or isinstance(error, commands.errors.CheckFailure): + if isinstance(error, commands.errors.MissingPermissions) or isinstance( + error, commands.errors.CheckFailure + ): await ctx.send("I'm afraid I can't let you do that.", hidden=True) elif isinstance(error, commands.errors.CommandNotFound): return elif isinstance(error, commands.errors.CommandOnCooldown): await ctx.send( - "Command on cooldown. " + f"Please wait {error.retry_after:0.2f}s before trying again", + "Command on cooldown. " + f"Please wait {error.retry_after:0.2f}s before trying again", hidden=True, ) else: diff --git a/jarvis/cogs/gitlab.py b/jarvis/cogs/gitlab.py index a3f2a95..75f0e0f 100644 --- a/jarvis/cogs/gitlab.py +++ b/jarvis/cogs/gitlab.py @@ -46,7 +46,9 @@ class GitlabCog(CacheCog): else: assignee = "None" - created_at = datetime.strptime(issue.created_at, "%Y-%m-%dT%H:%M:%S.%fZ").strftime("%Y-%m-%d %H:%M:%S UTC") + created_at = datetime.strptime(issue.created_at, "%Y-%m-%dT%H:%M:%S.%fZ").strftime( + "%Y-%m-%d %H:%M:%S UTC" + ) labels = issue.labels if labels: @@ -62,7 +64,9 @@ class GitlabCog(CacheCog): color = self.project.labels.get(issue.labels[0]).color fields.append(Field(name="Created At", value=created_at)) if issue.state == "closed": - closed_at = datetime.strptime(issue.closed_at, "%Y-%m-%dT%H:%M:%S.%fZ").strftime("%Y-%m-%d %H:%M:%S UTC") + closed_at = datetime.strptime(issue.closed_at, "%Y-%m-%dT%H:%M:%S.%fZ").strftime( + "%Y-%m-%d %H:%M:%S UTC" + ) fields.append(Field(name="Closed At", value=closed_at)) if issue.milestone: fields.append( @@ -86,7 +90,9 @@ class GitlabCog(CacheCog): icon_url=issue.author["avatar_url"], url=issue.author["web_url"], ) - embed.set_thumbnail(url="https://about.gitlab.com/images/press/logo/png/gitlab-icon-rgb.png") + embed.set_thumbnail( + url="https://about.gitlab.com/images/press/logo/png/gitlab-icon-rgb.png" + ) await ctx.send(embed=embed) @cog_ext.cog_subcommand( @@ -110,7 +116,9 @@ class GitlabCog(CacheCog): await ctx.send("Milestone does not exist.", hidden=True) return - created_at = datetime.strptime(milestone.created_at, "%Y-%m-%dT%H:%M:%S.%fZ").strftime("%Y-%m-%d %H:%M:%S UTC") + created_at = datetime.strptime(milestone.created_at, "%Y-%m-%dT%H:%M:%S.%fZ").strftime( + "%Y-%m-%d %H:%M:%S UTC" + ) fields = [ Field( @@ -143,7 +151,9 @@ class GitlabCog(CacheCog): url="https://git.zevaryx.com/jarvis", icon_url="https://git.zevaryx.com/uploads/-/system/user/avatar/11/avatar.png", ) - embed.set_thumbnail(url="https://about.gitlab.com/images/press/logo/png/gitlab-icon-rgb.png") + embed.set_thumbnail( + url="https://about.gitlab.com/images/press/logo/png/gitlab-icon-rgb.png" + ) await ctx.send(embed=embed) @cog_ext.cog_subcommand( @@ -172,7 +182,9 @@ class GitlabCog(CacheCog): else: assignee = "None" - created_at = datetime.strptime(mr.created_at, "%Y-%m-%dT%H:%M:%S.%fZ").strftime("%Y-%m-%d %H:%M:%S UTC") + created_at = datetime.strptime(mr.created_at, "%Y-%m-%dT%H:%M:%S.%fZ").strftime( + "%Y-%m-%d %H:%M:%S UTC" + ) labels = mr.labels if labels: @@ -191,10 +203,14 @@ class GitlabCog(CacheCog): color = "#00FFEE" fields.append(Field(name="Created At", value=created_at)) if mr.state == "merged": - merged_at = datetime.strptime(mr.merged_at, "%Y-%m-%dT%H:%M:%S.%fZ").strftime("%Y-%m-%d %H:%M:%S UTC") + merged_at = datetime.strptime(mr.merged_at, "%Y-%m-%dT%H:%M:%S.%fZ").strftime( + "%Y-%m-%d %H:%M:%S UTC" + ) fields.append(Field(name="Merged At", value=merged_at)) elif mr.state == "closed": - closed_at = datetime.strptime(mr.closed_at, "%Y-%m-%dT%H:%M:%S.%fZ").strftime("%Y-%m-%d %H:%M:%S UTC") + closed_at = datetime.strptime(mr.closed_at, "%Y-%m-%dT%H:%M:%S.%fZ").strftime( + "%Y-%m-%d %H:%M:%S UTC" + ) fields.append(Field(name="Closed At", value=closed_at)) if mr.milestone: fields.append( @@ -218,7 +234,9 @@ class GitlabCog(CacheCog): icon_url=mr.author["avatar_url"], url=mr.author["web_url"], ) - embed.set_thumbnail(url="https://about.gitlab.com/images/press/logo/png/gitlab-icon-rgb.png") + embed.set_thumbnail( + url="https://about.gitlab.com/images/press/logo/png/gitlab-icon-rgb.png" + ) await ctx.send(embed=embed) def build_embed_page(self, api_list: list, t_state: str, name: str) -> Embed: @@ -248,7 +266,9 @@ class GitlabCog(CacheCog): url="https://git.zevaryx.com/jarvis", icon_url="https://git.zevaryx.com/uploads/-/system/user/avatar/11/avatar.png", ) - embed.set_thumbnail(url="https://about.gitlab.com/images/press/logo/png/gitlab-icon-rgb.png") + embed.set_thumbnail( + url="https://about.gitlab.com/images/press/logo/png/gitlab-icon-rgb.png" + ) return embed @cog_ext.cog_subcommand( @@ -311,7 +331,7 @@ class GitlabCog(CacheCog): pages = [] t_state = t_state[0].upper() + t_state[1:] for i in range(0, len(issues), 5): - pages.append(self.build_embed_page(issues[i : i + 5], t_state=t_state, name="issue")) # noqa: E203 + pages.append(self.build_embed_page(issues[i : i + 5], t_state=t_state, name="issue")) paginator = Paginator( bot=self.bot, @@ -398,7 +418,9 @@ class GitlabCog(CacheCog): pages = [] t_state = t_state[0].upper() + t_state[1:] for i in range(0, len(merges), 5): - pages.append(self.build_embed_page(merges[i : i + 5], t_state=t_state, name="merge request")) # noqa: E203 + pages.append( + self.build_embed_page(merges[i : i + 5], t_state=t_state, name="merge request") + ) paginator = Paginator( bot=self.bot, @@ -463,7 +485,9 @@ class GitlabCog(CacheCog): pages = [] for i in range(0, len(milestones), 5): - pages.append(self.build_embed_page(milestones[i : i + 5], t_state=None, name="milestone")) # noqa: E203 + pages.append( + self.build_embed_page(milestones[i : i + 5], t_state=None, name="milestone") + ) paginator = Paginator( bot=self.bot, diff --git a/jarvis/cogs/modlog/command.py b/jarvis/cogs/modlog/command.py index e5ccd4b..b03666d 100644 --- a/jarvis/cogs/modlog/command.py +++ b/jarvis/cogs/modlog/command.py @@ -45,5 +45,7 @@ class ModlogCommandCog(commands.Cog): name=ctx.author.name, icon_url=ctx.author.avatar_url, ) - embed.set_footer(text=f"{ctx.author.name}#{ctx.author.discriminator} | {ctx.author.id}") + embed.set_footer( + text=f"{ctx.author.name}#{ctx.author.discriminator} | {ctx.author.id}" + ) await channel.send(embed=embed) diff --git a/jarvis/cogs/modlog/member.py b/jarvis/cogs/modlog/member.py index bd6cf20..d6423cc 100644 --- a/jarvis/cogs/modlog/member.py +++ b/jarvis/cogs/modlog/member.py @@ -223,7 +223,9 @@ class ModlogMemberCog(commands.Cog): desc=f"{before.mention} was verified", ) - async def process_rolechange(self, before: discord.Member, after: discord.Member) -> discord.Embed: + async def process_rolechange( + self, before: discord.Member, after: discord.Member + ) -> discord.Embed: """Process rolechange event.""" await asyncio.sleep(0.5) # Need to wait for audit log auditlog = await before.guild.audit_logs( diff --git a/jarvis/cogs/modlog/message.py b/jarvis/cogs/modlog/message.py index 8c779a6..1834877 100644 --- a/jarvis/cogs/modlog/message.py +++ b/jarvis/cogs/modlog/message.py @@ -47,7 +47,9 @@ class ModlogMessageCog(commands.Cog): icon_url=before.author.avatar_url, url=after.jump_url, ) - embed.set_footer(text=f"{before.author.name}#{before.author.discriminator} | {before.author.id}") + embed.set_footer( + text=f"{before.author.name}#{before.author.discriminator} | {before.author.id}" + ) await channel.send(embed=embed) @commands.Cog.listener() @@ -100,5 +102,7 @@ class ModlogMessageCog(commands.Cog): icon_url=message.author.avatar_url, url=message.jump_url, ) - embed.set_footer(text=f"{message.author.name}#{message.author.discriminator} | {message.author.id}") + embed.set_footer( + text=f"{message.author.name}#{message.author.discriminator} | {message.author.id}" + ) await channel.send(embed=embed) diff --git a/jarvis/cogs/starboard.py b/jarvis/cogs/starboard.py index df5d1d6..d2eb830 100644 --- a/jarvis/cogs/starboard.py +++ b/jarvis/cogs/starboard.py @@ -129,7 +129,9 @@ class StarboardCog(commands.Cog): ), create_option( name="channel", - description="Channel that has the message, required if different than command message", + description=( + "Channel that has the message, " "required if different than command message" + ), option_type=7, required=False, ), @@ -154,7 +156,9 @@ class StarboardCog(commands.Cog): for starboard in starboards: channel_list.append(find(lambda x: x.id == starboard.channel, ctx.guild.channels)) - select_channels = [create_select_option(label=x.name, value=str(idx)) for idx, x in enumerate(channel_list)] + select_channels = [ + create_select_option(label=x.name, value=str(idx)) for idx, x in enumerate(channel_list) + ] select = create_select( options=select_channels, @@ -303,3 +307,4 @@ class StarboardCog(commands.Cog): def setup(bot: commands.Bot) -> None: """Add StarboardCog to J.A.R.V.I.S.""" bot.add_cog(StarboardCog(bot)) + bot.add_cog(StarboardCog(bot)) diff --git a/jarvis/cogs/twitter.py b/jarvis/cogs/twitter.py index c007585..65fe265 100644 --- a/jarvis/cogs/twitter.py +++ b/jarvis/cogs/twitter.py @@ -31,7 +31,9 @@ class TwitterCog(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot config = get_config() - auth = tweepy.AppAuthHandler(config.twitter["consumer_key"], config.twitter["consumer_secret"]) + auth = tweepy.AppAuthHandler( + config.twitter["consumer_key"], config.twitter["consumer_secret"] + ) self.api = tweepy.API(auth) self._tweets.start() self._guild_cache = {} @@ -49,7 +51,9 @@ class TwitterCog(commands.Cog): logger.error(f"Error with fetching: {e}") for twitter in twitters: try: - tweets = list(filter(lambda x: x.id > twitter.last_tweet, twitter_data[twitter.handle])) + tweets = list( + filter(lambda x: x.id > twitter.last_tweet, twitter_data[twitter.handle]) + ) if tweets: tweets = sorted(tweets, key=lambda x: x.id) if twitter.guild not in self._guild_cache: @@ -57,7 +61,9 @@ class TwitterCog(commands.Cog): guild = self._guild_cache[twitter.guild] if twitter.channel not in self._channel_cache: channels = await guild.fetch_channels() - self._channel_cache[twitter.channel] = find(lambda x: x.id == twitter.channel, channels) + self._channel_cache[twitter.channel] = find( + lambda x: x.id == twitter.channel, channels + ) channel = self._channel_cache[twitter.channel] for tweet in tweets: retweet = "retweeted_status" in tweet.__dict__ @@ -66,7 +72,9 @@ class TwitterCog(commands.Cog): timestamp = int(tweet.created_at.timestamp()) url = f"https://twitter.com/{twitter.handle}/status/{tweet.id}" verb = "re" if retweet else "" - await channel.send(f"`@{twitter.handle}` {verb}tweeted this at : {url}") + await channel.send( + f"`@{twitter.handle}` {verb}tweeted this at : {url}" + ) newest = max(tweets, key=lambda x: x.id) twitter.last_tweet = newest.id twitter.save() @@ -79,7 +87,12 @@ class TwitterCog(commands.Cog): name="follow", description="Follow a Twitter account", options=[ - create_option(name="handle", description="Twitter account", option_type=COptionType.STRING, required=True), + create_option( + name="handle", + description="Twitter account", + option_type=COptionType.STRING, + required=True, + ), create_option( name="channel", description="Channel to post tweets into", @@ -91,7 +104,10 @@ class TwitterCog(commands.Cog): description="Mirror re-tweets?", option_type=COptionType.STRING, required=False, - choices=[create_choice(name="Yes", value="Yes"), create_choice(name="No", value="No")], + choices=[ + create_choice(name="Yes", value="Yes"), + create_choice(name="No", value="No"), + ], ), ], ) @@ -111,7 +127,9 @@ class TwitterCog(commands.Cog): try: latest_tweet = self.api.user_timeline(screen_name=handle, count=1)[0] except Exception: - await ctx.send("Unable to get user timeline. Are you sure the handle is correct?", hidden=True) + await ctx.send( + "Unable to get user timeline. Are you sure the handle is correct?", hidden=True + ) return count = Twitter.objects(guild=ctx.guild.id).count() @@ -155,7 +173,9 @@ class TwitterCog(commands.Cog): option = create_select_option(label=twitter.handle, value=str(twitter.id)) options.append(option) - select = create_select(options=options, custom_id="to_delete", min_values=1, max_values=len(twitters)) + select = create_select( + options=options, custom_id="to_delete", min_values=1, max_values=len(twitters) + ) components = [create_actionrow(select)] block = "\n".join(x.handle for x in twitters) @@ -167,7 +187,10 @@ class TwitterCog(commands.Cog): try: context = await wait_for_component( - self.bot, check=lambda x: ctx.author.id == x.author.id, messages=message, timeout=60 * 5 + self.bot, + check=lambda x: ctx.author.id == x.author.id, + messages=message, + timeout=60 * 5, ) for to_delete in context.selected_options: _ = Twitter.objects(guild=ctx.guild.id, id=ObjectId(to_delete)).delete() @@ -175,7 +198,9 @@ class TwitterCog(commands.Cog): for component in row["components"]: component["disabled"] = True block = "\n".join(handlemap[x] for x in context.selected_options) - await context.edit_origin(content=f"Unfollowed the following:\n```\n{block}\n```", components=components) + await context.edit_origin( + content=f"Unfollowed the following:\n```\n{block}\n```", components=components + ) except asyncio.TimeoutError: for row in components: for component in row["components"]: @@ -192,7 +217,10 @@ class TwitterCog(commands.Cog): description="Mirror re-tweets?", option_type=COptionType.STRING, required=True, - choices=[create_choice(name="Yes", value="Yes"), create_choice(name="No", value="No")], + choices=[ + create_choice(name="Yes", value="Yes"), + create_choice(name="No", value="No"), + ], ), ], ) @@ -209,7 +237,9 @@ class TwitterCog(commands.Cog): option = create_select_option(label=twitter.handle, value=str(twitter.id)) options.append(option) - select = create_select(options=options, custom_id="to_update", min_values=1, max_values=len(twitters)) + select = create_select( + options=options, custom_id="to_update", min_values=1, max_values=len(twitters) + ) components = [create_actionrow(select)] block = "\n".join(x.handle for x in twitters) @@ -221,7 +251,10 @@ class TwitterCog(commands.Cog): try: context = await wait_for_component( - self.bot, check=lambda x: ctx.author.id == x.author.id, messages=message, timeout=60 * 5 + self.bot, + check=lambda x: ctx.author.id == x.author.id, + messages=message, + timeout=60 * 5, ) handlemap = {str(x.id): x.handle for x in twitters} for to_update in context.selected_options: @@ -233,8 +266,11 @@ class TwitterCog(commands.Cog): component["disabled"] = True block = "\n".join(handlemap[x] for x in context.selected_options) await context.edit_origin( - content=f"{'Unfollowed' if not retweets else 'Followed'} retweets from the following:" - f"\n```\n{block}\n```", + content=( + f"{'Unfollowed' if not retweets else 'Followed'} " + "retweets from the following:" + f"\n```\n{block}\n```" + ), components=components, ) except asyncio.TimeoutError: diff --git a/jarvis/cogs/util.py b/jarvis/cogs/util.py index 900c8b9..a1fec76 100644 --- a/jarvis/cogs/util.py +++ b/jarvis/cogs/util.py @@ -228,7 +228,9 @@ class UtilCog(commands.Cog): async def _server_info(self, ctx: SlashContext) -> None: guild: Guild = ctx.guild - owner = f"{guild.owner.name}#{guild.owner.discriminator}" if guild.owner else "||`[redacted]`||" + owner = ( + f"{guild.owner.name}#{guild.owner.discriminator}" if guild.owner else "||`[redacted]`||" + ) region = guild.region categories = len(guild.categories) @@ -308,7 +310,9 @@ class UtilCog(commands.Cog): @cog_ext.cog_slash( name="pigpen", description="Encode a string into pigpen", - options=[create_option(name="text", description="Text to encode", option_type=3, required=True)], + options=[ + create_option(name="text", description="Text to encode", option_type=3, required=True) + ], ) async def _pigpen(self, ctx: SlashContext, text: str) -> None: outp = "`" diff --git a/jarvis/events/message.py b/jarvis/events/message.py index 52a1211..a449019 100644 --- a/jarvis/events/message.py +++ b/jarvis/events/message.py @@ -11,7 +11,7 @@ from jarvis.utils import build_embed, find from jarvis.utils.field import Field invites = re.compile( - r"(?:https?://)?(?:www.)?(?:discord.(?:gg|io|me|li)|discord(?:app)?.com/invite)/([^\s/]+?)(?=\b)", + r"(?:https?://)?(?:www.)?(?:discord.(?:gg|io|me|li)|discord(?:app)?.com/invite)/([^\s/]+?)(?=\b)", # noqa: E501 flags=re.IGNORECASE, ) @@ -46,7 +46,7 @@ class MessageEventHandler(object): channel = find(lambda x: x.id == 599068193339736096, message.channel_mentions) if channel and message.author.id == 293795462752894976: await channel.send( - content="https://cdn.discordapp.com/attachments/664621130044407838/805218508866453554/tech.gif" + content="https://cdn.discordapp.com/attachments/664621130044407838/805218508866453554/tech.gif" # noqa: E501 ) content = re.sub(r"\s+", "", message.content) match = invites.search(content) @@ -87,7 +87,9 @@ class MessageEventHandler(object): name=message.author.nick if message.author.nick else message.author.name, icon_url=message.author.avatar_url, ) - embed.set_footer(text=f"{message.author.name}#{message.author.discriminator} | {message.author.id}") + embed.set_footer( + text=f"{message.author.name}#{message.author.discriminator} | {message.author.id}" # noqa: E501 + ) await message.channel.send(embed=embed) async def massmention(self, message: Message) -> None: @@ -99,7 +101,8 @@ class MessageEventHandler(object): if ( massmention and massmention.value > 0 # noqa: W503 - and len(message.mentions) - (1 if message.author in message.mentions else 0) # noqa: W503 + and len(message.mentions) # noqa: W503 + - (1 if message.author in message.mentions else 0) # noqa: W503 > massmention.value # noqa: W503 ): _ = Warning( @@ -120,7 +123,9 @@ class MessageEventHandler(object): name=message.author.nick if message.author.nick else message.author.name, icon_url=message.author.avatar_url, ) - embed.set_footer(text=f"{message.author.name}#{message.author.discriminator} | {message.author.id}") + embed.set_footer( + text=f"{message.author.name}#{message.author.discriminator} | {message.author.id}" + ) await message.channel.send(embed=embed) async def roleping(self, message: Message) -> None: @@ -188,7 +193,9 @@ class MessageEventHandler(object): name=message.author.nick if message.author.nick else message.author.name, icon_url=message.author.avatar_url, ) - embed.set_footer(text=f"{message.author.name}#{message.author.discriminator} | {message.author.id}") + embed.set_footer( + text=f"{message.author.name}#{message.author.discriminator} | {message.author.id}" + ) await message.channel.send(embed=embed) async def on_message(self, message: Message) -> None: diff --git a/jarvis/tasks/unban.py b/jarvis/tasks/unban.py index 45c0a67..620225f 100644 --- a/jarvis/tasks/unban.py +++ b/jarvis/tasks/unban.py @@ -16,7 +16,9 @@ async def unban() -> None: bans = Ban.objects(type="temp", active=True) unbans = [] for ban in bans: - if ban.created_at + timedelta(hours=ban.duration) < datetime.utcnow() + timedelta(minutes=10): + if ban.created_at + timedelta(hours=ban.duration) < datetime.utcnow() + timedelta( + minutes=10 + ): guild = await jarvis.jarvis.fetch_guild(ban.guild) user = await jarvis.jarvis.fetch_user(ban.user) if user: diff --git a/jarvis/utils/__init__.py b/jarvis/utils/__init__.py index 1bd4fbe..8306e5a 100644 --- a/jarvis/utils/__init__.py +++ b/jarvis/utils/__init__.py @@ -80,7 +80,7 @@ def get_extensions(path: str = jarvis.cogs.__path__) -> list: def parse_color_hex(hex: str) -> Color: """Convert a hex color to a d.py Color.""" hex = hex.lstrip("#") - rgb = tuple(int(hex[i : i + 2], 16) for i in (0, 2, 4)) # noqa: E203 + rgb = tuple(int(hex[i : i + 2], 16) for i in (0, 2, 4)) return Color.from_rgb(*rgb)