From 76d1625346d8a58faed14e00eba58951cf1a1e5b Mon Sep 17 00:00:00 2001 From: bacon Date: Mon, 18 Mar 2024 02:08:16 +0300 Subject: [PATCH] fixed start after move --- bot/cogs/audio.py | 14 ++++++++++++-- bot/integral_lib/CogsPrep.py | 27 +++++++++++++++++++++++++++ bot/integral_lib/Comands.py | 15 ++++++++++++++- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/bot/cogs/audio.py b/bot/cogs/audio.py index 2fd64d6..9a98d73 100644 --- a/bot/cogs/audio.py +++ b/bot/cogs/audio.py @@ -1,7 +1,7 @@ import random import disnake -from disnake import OptionChoice, Option, OptionType, Member, VoiceState +from disnake import OptionChoice, Option, OptionType, Member, VoiceState, ApplicationCommandInteraction from disnake.ext import commands from integral_lib.ListGenerator import ListGenerator @@ -59,7 +59,17 @@ class Audio(commands.Cog, name='Audio'): await inter.response.send_message('You`re not in voice', ephemeral=True) @playaudio.autocomplete('audio') - async def list_to_play(self, inter: disnake.ApplicationCommandInteraction, current: str): + async def list_to_play(self, inter: ApplicationCommandInteraction, current: str): + """ + Asynchronously generates a list of OptionChoices for the given audio files based on the user input. + Parameters: + - inter: disnake.ApplicationCommandInteraction - The interaction context for the command. + - current: str - The current user input to filter the audio file choices. + Returns: + - list[OptionChoice] - A list of OptionChoice objects representing the available audio file choices. + :param current: + :param inter: ApplicationCommandInteraction + """ current = current.lower() _dict: dict = {} for f in ListGenerator('audio'): diff --git a/bot/integral_lib/CogsPrep.py b/bot/integral_lib/CogsPrep.py index a30d6f9..c9dceef 100644 --- a/bot/integral_lib/CogsPrep.py +++ b/bot/integral_lib/CogsPrep.py @@ -15,6 +15,15 @@ from .Logger import logger def cog_list(fold: str = './cogs') -> List[str]: + """ + A function that generates a list of cog names based on the files present in a specified folder. + + Parameters: + - fold (str): The directory path where the cog files are located. Defaults to './cogs'. + + Returns: + - List[str]: A list of cog names without the '.py' extension. + """ cogs_list = [] for _filename in listdir(fold): if _filename.endswith('.py'): @@ -25,6 +34,22 @@ def cog_list(fold: str = './cogs') -> List[str]: def work_with_cogs(what_do: str, bot: InteractionBotBase, cog: str | list): + """ + Perform the specified action on the given cog or list of cogs. + Args: + what_do (str): The action to perform (load, unload, reload, disable, enable). + bot (InteractionBotBase): The bot instance to work with. + cog (str | list): The name of the cog or a list of cogs to work with. + Raises: + ValueError: If the action is not recognized. + Returns: + None + -------- + :param cog: str | list + :param bot: InteractionBotBase + :param what_do: str = ['load', 'unload', 'reload', 'disable', 'enable'] + """ + if isinstance(cog, str): cog = cog.split() for _filename in cog: @@ -49,3 +74,5 @@ def work_with_cogs(what_do: str, f'cogs/{_filename}.py') bot.load_extension(f'cogs.{_filename}') logger.info(f'Cog {_filename} started and enabled') + else: + raise ValueError(f"Unrecognized action: {what_do}") diff --git a/bot/integral_lib/Comands.py b/bot/integral_lib/Comands.py index 517693d..7c2f1d2 100644 --- a/bot/integral_lib/Comands.py +++ b/bot/integral_lib/Comands.py @@ -37,6 +37,18 @@ async def read_json(guild: int, _param: str): async def write_json(guild: int, param_name: str, param: str or int): + """ + A function to write JSON data to a file after updating or adding a parameter value. + + Parameters: + + - guild: an integer representing the guild ID + - param_name: a string representing the parameter name + - param: a string or integer representing the parameter value + + Returns: + This function does not return anything. + """ with open(getenv('CONF_FILE'), encoding='utf-8') as f: try: _json = load(f) @@ -54,7 +66,8 @@ async def write_json(guild: int, param_name: str, param: str or int): def determine_prefix(bot: commands.Bot, msg): """ - Determite per-server bot prefix + Determine the per-server bot prefix based on the given message object. + :param bot: Disnake Bot object :param msg: Disnake msg object :return: prefix for server, default is $