From dd122a1edc85ae48bd5a6d38b6d88c52f894912d Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Tue, 16 Apr 2024 22:48:07 -0400 Subject: [PATCH 1/4] Fix all flake8 DOC105 issues --- techsupport_bot/bot.py | 5 +++-- techsupport_bot/commands/animal.py | 2 +- techsupport_bot/commands/burn.py | 2 +- techsupport_bot/commands/commandcontrol.py | 2 +- techsupport_bot/commands/conch.py | 2 +- techsupport_bot/commands/correct.py | 2 +- techsupport_bot/commands/echo.py | 2 +- techsupport_bot/commands/embed.py | 3 ++- techsupport_bot/commands/emoji.py | 6 +++--- techsupport_bot/commands/extension.py | 2 +- techsupport_bot/commands/factoids.py | 8 ++++---- techsupport_bot/commands/hello.py | 2 +- techsupport_bot/commands/htd.py | 4 ++-- techsupport_bot/commands/relay.py | 5 +++-- techsupport_bot/commands/role.py | 4 ++-- techsupport_bot/commands/roll.py | 2 +- techsupport_bot/commands/set.py | 2 +- techsupport_bot/commands/sync.py | 2 +- techsupport_bot/core/auxiliary.py | 6 +++--- techsupport_bot/tests/helpers/channel.py | 2 +- techsupport_bot/tests/helpers/message.py | 2 +- techsupport_bot/ui/pagination.py | 2 +- 22 files changed, 36 insertions(+), 33 deletions(-) diff --git a/techsupport_bot/bot.py b/techsupport_bot/bot.py index 450506afb..fa8d697d7 100644 --- a/techsupport_bot/bot.py +++ b/techsupport_bot/bot.py @@ -9,6 +9,7 @@ import json import os import threading +import io import botlogging import discord @@ -383,7 +384,7 @@ async def get_log_channel_from_guild( Args: guild (discord.Guild): the guild object to reference - key (string): the key to use when looking up the channel + key (str): the key to use when looking up the channel """ if not guild: return None @@ -675,7 +676,7 @@ def get_command_extension_name(self, command: commands.Command) -> str: extension_name = command.module.split(".")[1] return extension_name - async def register_file_extension(self, extension_name: str, fp) -> None: + async def register_file_extension(self, extension_name: str, fp: io.BufferedIOBase) -> None: """Offers an interface for loading an extension from an external source. This saves the external file data to the OS, without any validation. diff --git a/techsupport_bot/commands/animal.py b/techsupport_bot/commands/animal.py index 82f4d396d..333477f8b 100644 --- a/techsupport_bot/commands/animal.py +++ b/techsupport_bot/commands/animal.py @@ -20,7 +20,7 @@ class Animals(cogs.BaseCog): @auxiliary.with_typing @commands.command(name="cat", brief="Gets a cat", description="Gets a cat") - async def cat(self, ctx: commands.context) -> None: + async def cat(self, ctx: commands.Context) -> None: """Prints a cat to discord Args: diff --git a/techsupport_bot/commands/burn.py b/techsupport_bot/commands/burn.py index 271520062..2916b1b34 100644 --- a/techsupport_bot/commands/burn.py +++ b/techsupport_bot/commands/burn.py @@ -29,7 +29,7 @@ class Burn(cogs.BaseCog): ] async def handle_burn( - self, ctx, user: discord.Member, message: discord.Message + self, ctx: commands.Context, user: discord.Member, message: discord.Message ) -> None: """The core logic to handle the burn command diff --git a/techsupport_bot/commands/commandcontrol.py b/techsupport_bot/commands/commandcontrol.py index 277367c67..22b5918e3 100644 --- a/techsupport_bot/commands/commandcontrol.py +++ b/techsupport_bot/commands/commandcontrol.py @@ -28,7 +28,7 @@ class CommandControl(cogs.BaseCog): brief="Executes a commands bot command", description="Executes a commands bot command", ) - async def command_group(self, ctx): + async def command_group(self, ctx: commands.Context): """The bare .command command. This does nothing but generate the help message Args: diff --git a/techsupport_bot/commands/conch.py b/techsupport_bot/commands/conch.py index 644a55ee7..51887c2eb 100644 --- a/techsupport_bot/commands/conch.py +++ b/techsupport_bot/commands/conch.py @@ -58,7 +58,7 @@ def format_question(self, question: str) -> str: question += "?" return question - async def conch_command(self, ctx, question: str = "") -> None: + async def conch_command(self, ctx: commands.Context, question: str = "") -> None: """Method for the core logic of the conch command Args: diff --git a/techsupport_bot/commands/correct.py b/techsupport_bot/commands/correct.py index fc0df7e77..417f3930e 100644 --- a/techsupport_bot/commands/correct.py +++ b/techsupport_bot/commands/correct.py @@ -17,7 +17,7 @@ async def setup(bot): class Corrector(cogs.BaseCog): """Class for the correct command for the discord bot.""" - async def correct_command(self, ctx, to_replace: str, replacement: str) -> None: + async def correct_command(self, ctx: commands.Context, to_replace: str, replacement: str) -> None: """This is the main processing for the correct command Args: diff --git a/techsupport_bot/commands/echo.py b/techsupport_bot/commands/echo.py index d743baafd..f92c45696 100644 --- a/techsupport_bot/commands/echo.py +++ b/techsupport_bot/commands/echo.py @@ -26,7 +26,7 @@ class MessageEcho(cogs.BaseCog): @commands.group( brief="Executes an echo bot command", description="Executes an echo bot command" ) - async def echo(self, ctx): + async def echo(self, ctx: commands.Context): """The bare .echo command. This does nothing but generate the help message Args: diff --git a/techsupport_bot/commands/embed.py b/techsupport_bot/commands/embed.py index 633190ff9..e805feb30 100644 --- a/techsupport_bot/commands/embed.py +++ b/techsupport_bot/commands/embed.py @@ -10,6 +10,7 @@ Defines: has_embed_role """ +import munch import discord from core import auxiliary, cogs, extensionconfig from discord.ext import commands @@ -152,7 +153,7 @@ async def embed(self, ctx: commands.Context, *, keep_option: str = None): "I couldn't generate all of your embeds, so I gave you a blank slate", ) - async def process_request(self, request_body) -> list[discord.Embed]: + async def process_request(self, request_body: munch.Munch) -> list[discord.Embed]: """Returns a list of discord.Embed objects from a request_body Args: diff --git a/techsupport_bot/commands/emoji.py b/techsupport_bot/commands/emoji.py index 0d44f6fb7..16b38efab 100644 --- a/techsupport_bot/commands/emoji.py +++ b/techsupport_bot/commands/emoji.py @@ -24,7 +24,7 @@ class Emojis(cogs.BaseCog): KEY_MAP = {"?": "question", "!": "exclamation"} @classmethod - def emoji_from_char(cls, char): + def emoji_from_char(cls, char: str): """Gets an unicode emoji from a character Args: @@ -55,7 +55,7 @@ def check_if_all_unique(self, string: str): return len(set(string.lower())) == len(string.lower()) @classmethod - def generate_emoji_string(cls, string, only_emoji=False): + def generate_emoji_string(cls, string: str, only_emoji: bool = False): """This takes a string and returns a string or list of emojis Args: @@ -81,7 +81,7 @@ def generate_emoji_string(cls, string, only_emoji=False): return emoji_list async def emoji_commands( - self, ctx, message: str, add_reactions: bool, react_user: discord.Member = None + self, ctx: commands.Context, message: str, add_reactions: bool, react_user: discord.Member = None ): """A method to handle the core of both emoji message and reaction diff --git a/techsupport_bot/commands/extension.py b/techsupport_bot/commands/extension.py index f47f127dd..da741d659 100644 --- a/techsupport_bot/commands/extension.py +++ b/techsupport_bot/commands/extension.py @@ -32,7 +32,7 @@ class ExtensionControl(cogs.BaseCog): brief="Executes an extension bot command", description="Executes an extension bot command", ) - async def extension_group(self, ctx): + async def extension_group(self, ctx: commands.Context): """The bare .extension command. This does nothing but generate the help message Args: diff --git a/techsupport_bot/commands/factoids.py b/techsupport_bot/commands/factoids.py index f9fc838df..ff9d16763 100644 --- a/techsupport_bot/commands/factoids.py +++ b/techsupport_bot/commands/factoids.py @@ -189,11 +189,11 @@ async def preconfig(self): await self.kickoff_jobs() # -- DB calls -- - async def delete_factoid_call(self, factoid, guild: str): + async def delete_factoid_call(self, factoid: bot.models.Factoid, guild: str): """Calls the db to delete a factoid Args: - factoid (Factoid): The factoid to delete + factoid (bot.models.Factoid): The factoid to delete guild (str): The guild ID for cache handling """ # Removes the `factoid all` cache since it has become outdated @@ -843,11 +843,11 @@ async def kickoff_jobs(self): task = asyncio.create_task(self.cronjob(job)) task = self.running_jobs[job_id]["task"] = task - async def cronjob(self, job, ctx: commands.Context = None): + async def cronjob(self, job: bot.models.FactoidJob, ctx: commands.Context = None): """Run a cron job for a factoid Args: - job (FactoidJob): The job to start + job (bot.models.FactoidJob): The job to start ctx (commands.Context): The context, used for logging """ job_id = job.job_id diff --git a/techsupport_bot/commands/hello.py b/techsupport_bot/commands/hello.py index 0db5a1ada..6f1e2e51f 100644 --- a/techsupport_bot/commands/hello.py +++ b/techsupport_bot/commands/hello.py @@ -16,7 +16,7 @@ async def setup(bot): class Greeter(cogs.BaseCog): """Class for the greeter command.""" - async def hello_command(self, ctx) -> None: + async def hello_command(self, ctx: commands.Context) -> None: """A simple function to add HEY reactions to the command invocation Args: diff --git a/techsupport_bot/commands/htd.py b/techsupport_bot/commands/htd.py index 3b84b63ba..67c5750d7 100644 --- a/techsupport_bot/commands/htd.py +++ b/techsupport_bot/commands/htd.py @@ -131,7 +131,7 @@ def perform_op_on_list(self, equation_list: list) -> int: " (hex)\n0b (binary) \nNo prefix (assumed decimal)" ), ) - async def htd(self, ctx, *, val_to_convert): + async def htd(self, ctx: commands.Context, *, val_to_convert: str): """This discord command for .htd Args: @@ -290,7 +290,7 @@ async def htd_command(self, ctx: commands.Context, val_to_convert: str) -> None: """The main logic for the htd command Args: - ctx (command.Context): The context in which the command was run it + ctx (commands.Context): The context in which the command was run it val_to_convert (str): The raw user input """ val_to_convert = self.clean_input(val_to_convert) diff --git a/techsupport_bot/commands/relay.py b/techsupport_bot/commands/relay.py index 34bee3d54..902d86943 100644 --- a/techsupport_bot/commands/relay.py +++ b/techsupport_bot/commands/relay.py @@ -8,6 +8,7 @@ from bidict import bidict from core import auxiliary, cogs from discord.ext import commands +import irc.client async def setup(bot: commands.Bot) -> None: @@ -126,7 +127,7 @@ async def handle_factoid( brief="Executes an irc command", description="Executes an irc command", ) - async def irc(self, ctx: commands.Context) -> None: + async def irc_base(self, ctx: commands.Context) -> None: """The base set of IRC commands Args: @@ -495,7 +496,7 @@ async def on_reaction_add( reaction=reaction, user=user, channel=self.mapping[str(channel.id)] ) - async def handle_dm_from_irc(self, message: str, event) -> None: + async def handle_dm_from_irc(self, message: str, event: irc.client.Event) -> None: """Sends a DM to the owner of the bot based on a message from IRC Args: diff --git a/techsupport_bot/commands/role.py b/techsupport_bot/commands/role.py index 59b5f9e61..3e654c8a6 100644 --- a/techsupport_bot/commands/role.py +++ b/techsupport_bot/commands/role.py @@ -18,7 +18,7 @@ async def setup(bot: bot.TechSupportBot): """Adding config and the cog to the bot Args: - bot (commands.Bot): The bot object + bot (bot.TechSupportBot): The bot object """ config = extensionconfig.ExtensionConfig() config.add( @@ -215,7 +215,7 @@ def check_permissions( Args: user (discord.User): The user executing the command guild (discord.Guild): The guild the command was run in - roles (list): A list of the roles allowed to execute + roles (list[str]): A list of the roles allowed to execute Returns: bool: True if can execute, false if cannot diff --git a/techsupport_bot/commands/roll.py b/techsupport_bot/commands/roll.py index 88126729a..6cd181fd7 100644 --- a/techsupport_bot/commands/roll.py +++ b/techsupport_bot/commands/roll.py @@ -24,7 +24,7 @@ class Roller(cogs.BaseCog): description="Rolls a random number in a given range", usage="[minimum] [maximum] (defaults to 1-100)", ) - async def roll(self, ctx, min: int = 1, max: int = 100): + async def roll(self, ctx: commands.Context, min: int = 1, max: int = 100): """The function that is called when .roll is run on discord Args: diff --git a/techsupport_bot/commands/set.py b/techsupport_bot/commands/set.py index 6631ea11d..491560b2b 100644 --- a/techsupport_bot/commands/set.py +++ b/techsupport_bot/commands/set.py @@ -29,7 +29,7 @@ class Setter(cogs.BaseCog): brief="Executes a `set X` bot command", description="Executes a `set X` bot command", ) - async def set_group(self, ctx): + async def set_group(self, ctx: commands.Context): """The bare .set command. This does nothing but generate the help message Args: diff --git a/techsupport_bot/commands/sync.py b/techsupport_bot/commands/sync.py index baf6cf5e3..2f39e5a3b 100644 --- a/techsupport_bot/commands/sync.py +++ b/techsupport_bot/commands/sync.py @@ -28,7 +28,7 @@ class AppCommandSync(cogs.BaseCog): description="Syncs slash commands", usage="", ) - async def sync_slash_commands(self, ctx): + async def sync_slash_commands(self, ctx: commands.Context): """A simple command to manually sync slash commands Args: diff --git a/techsupport_bot/core/auxiliary.py b/techsupport_bot/core/auxiliary.py index cf2a11cb8..1eb23a655 100644 --- a/techsupport_bot/core/auxiliary.py +++ b/techsupport_bot/core/auxiliary.py @@ -51,7 +51,7 @@ async def search_channel_for_message( """Searches the last 50 messages in a channel based on given conditions Args: - channel (discord.TextChannel): The channel to search in. This is required + channel (discord.abc.Messageable): The channel to search in. This is required prefix (str, optional): A prefix you want to exclude from the search. Defaults to None. member_to_match (discord.Member, optional): The member that the message found must be from. Defaults to None. @@ -147,7 +147,7 @@ async def send_deny_embed( Args: message (str): The reason for deny channel (discord.abc.Messageable): The channel to send the deny embed to - author (discord.Member, optional): The author of the message. + author (discord.Member | None, optional): The author of the message. If this is provided, the author will be mentioned Returns: @@ -185,7 +185,7 @@ async def send_confirm_embed( Args: message (str): The reason for confirm channel (discord.abc.Messageable): The channel to send the confirm embed to - author (discord.Member, optional): The author of the message. + author (discord.Member | None, optional): The author of the message. If this is provided, the author will be mentioned Returns: diff --git a/techsupport_bot/tests/helpers/channel.py b/techsupport_bot/tests/helpers/channel.py index bac3a41c4..c6fd4ab5b 100644 --- a/techsupport_bot/tests/helpers/channel.py +++ b/techsupport_bot/tests/helpers/channel.py @@ -18,7 +18,7 @@ class MockChannel: def __init__(self, history=None): self.message_history = history - async def history(self, limit) -> AsyncGenerator[str, None]: + async def history(self, limit: int) -> AsyncGenerator[str, None]: """Replication of the async history method As history is not expected to be massive, this just yields every message diff --git a/techsupport_bot/tests/helpers/message.py b/techsupport_bot/tests/helpers/message.py index 49effc6cd..221e1d4c7 100644 --- a/techsupport_bot/tests/helpers/message.py +++ b/techsupport_bot/tests/helpers/message.py @@ -21,7 +21,7 @@ def __init__(self, content=None, author=None, attachments=None, reactions=None): self.attachments = attachments self.reactions = reactions - async def add_reaction(self, reaction): + async def add_reaction(self, reaction: list): """Replication of the adding a reaction Adding reactions to a previous message diff --git a/techsupport_bot/ui/pagination.py b/techsupport_bot/ui/pagination.py index 3ddf0c1b3..8f5912923 100644 --- a/techsupport_bot/ui/pagination.py +++ b/techsupport_bot/ui/pagination.py @@ -38,7 +38,7 @@ async def send( author (discord.Member): The author of the pages command data (list[Union[str, discord.Embed]]): A list of pages in order with [0] being the first page - interaction (discord.Interaction): The interaction this should followup with (Optional) + interaction (discord.Interaction | None): The interaction this should followup with (Optional) """ self.author = author self.data = data From 102a3b89e01536556b0d3fcd8fb7bdfe960174a4 Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Tue, 16 Apr 2024 22:59:13 -0400 Subject: [PATCH 2/4] Formatting --- techsupport_bot/bot.py | 6 ++++-- techsupport_bot/commands/correct.py | 4 +++- techsupport_bot/commands/embed.py | 2 +- techsupport_bot/commands/emoji.py | 6 +++++- techsupport_bot/commands/relay.py | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/techsupport_bot/bot.py b/techsupport_bot/bot.py index fa8d697d7..1cdce7604 100644 --- a/techsupport_bot/bot.py +++ b/techsupport_bot/bot.py @@ -6,10 +6,10 @@ import asyncio import datetime import glob +import io import json import os import threading -import io import botlogging import discord @@ -676,7 +676,9 @@ def get_command_extension_name(self, command: commands.Command) -> str: extension_name = command.module.split(".")[1] return extension_name - async def register_file_extension(self, extension_name: str, fp: io.BufferedIOBase) -> None: + async def register_file_extension( + self, extension_name: str, fp: io.BufferedIOBase + ) -> None: """Offers an interface for loading an extension from an external source. This saves the external file data to the OS, without any validation. diff --git a/techsupport_bot/commands/correct.py b/techsupport_bot/commands/correct.py index 417f3930e..34cbf1631 100644 --- a/techsupport_bot/commands/correct.py +++ b/techsupport_bot/commands/correct.py @@ -17,7 +17,9 @@ async def setup(bot): class Corrector(cogs.BaseCog): """Class for the correct command for the discord bot.""" - async def correct_command(self, ctx: commands.Context, to_replace: str, replacement: str) -> None: + async def correct_command( + self, ctx: commands.Context, to_replace: str, replacement: str + ) -> None: """This is the main processing for the correct command Args: diff --git a/techsupport_bot/commands/embed.py b/techsupport_bot/commands/embed.py index e805feb30..5fa4bc25a 100644 --- a/techsupport_bot/commands/embed.py +++ b/techsupport_bot/commands/embed.py @@ -10,8 +10,8 @@ Defines: has_embed_role """ -import munch import discord +import munch from core import auxiliary, cogs, extensionconfig from discord.ext import commands diff --git a/techsupport_bot/commands/emoji.py b/techsupport_bot/commands/emoji.py index 16b38efab..d713750a0 100644 --- a/techsupport_bot/commands/emoji.py +++ b/techsupport_bot/commands/emoji.py @@ -81,7 +81,11 @@ def generate_emoji_string(cls, string: str, only_emoji: bool = False): return emoji_list async def emoji_commands( - self, ctx: commands.Context, message: str, add_reactions: bool, react_user: discord.Member = None + self, + ctx: commands.Context, + message: str, + add_reactions: bool, + react_user: discord.Member = None, ): """A method to handle the core of both emoji message and reaction diff --git a/techsupport_bot/commands/relay.py b/techsupport_bot/commands/relay.py index 902d86943..bf9e702ae 100644 --- a/techsupport_bot/commands/relay.py +++ b/techsupport_bot/commands/relay.py @@ -3,12 +3,12 @@ from typing import Dict, List, Union import discord +import irc.client import munch import ui from bidict import bidict from core import auxiliary, cogs from discord.ext import commands -import irc.client async def setup(bot: commands.Bot) -> None: From de462bb256e724927abed3dde07a6e7a74db4361 Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Tue, 16 Apr 2024 23:00:57 -0400 Subject: [PATCH 3/4] Formatting the second --- techsupport_bot/ui/pagination.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/techsupport_bot/ui/pagination.py b/techsupport_bot/ui/pagination.py index 8f5912923..593393be8 100644 --- a/techsupport_bot/ui/pagination.py +++ b/techsupport_bot/ui/pagination.py @@ -38,7 +38,8 @@ async def send( author (discord.Member): The author of the pages command data (list[Union[str, discord.Embed]]): A list of pages in order with [0] being the first page - interaction (discord.Interaction | None): The interaction this should followup with (Optional) + interaction (discord.Interaction | None): The interaction this + should followup with (Optional) """ self.author = author self.data = data From ed5365c6bb57d3de38115ed3db606a84135be06a Mon Sep 17 00:00:00 2001 From: ajax146 <31014239+ajax146@users.noreply.github.com> Date: Tue, 16 Apr 2024 23:02:58 -0400 Subject: [PATCH 4/4] Formatting the third --- techsupport_bot/ui/pagination.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/techsupport_bot/ui/pagination.py b/techsupport_bot/ui/pagination.py index 593393be8..2e27a206a 100644 --- a/techsupport_bot/ui/pagination.py +++ b/techsupport_bot/ui/pagination.py @@ -38,7 +38,7 @@ async def send( author (discord.Member): The author of the pages command data (list[Union[str, discord.Embed]]): A list of pages in order with [0] being the first page - interaction (discord.Interaction | None): The interaction this + interaction (discord.Interaction | None): The interaction this should followup with (Optional) """ self.author = author