diff --git a/tuxbot/core/checks.py b/tuxbot/core/checks.py index 8838d10..865f15f 100644 --- a/tuxbot/core/checks.py +++ b/tuxbot/core/checks.py @@ -22,6 +22,9 @@ __all__ = [ def is_mod(): + """Is the user a moderator ? + + """ async def pred(ctx): if await ctx.bot.is_owner(ctx.author): return True @@ -32,6 +35,9 @@ def is_mod(): def is_admin(): + """Is the user admin ? + + """ async def pred(ctx): if await ctx.bot.is_owner(ctx.author): return True @@ -42,6 +48,15 @@ def is_admin(): async def check_permissions(ctx: "ContextPlus", **perms: Dict[str, bool]): + """Does a user have any perms ? + + Parameters + ---------- + ctx:ContextPlus + Command context. + **perms:dict + Perms to verify. + """ if await ctx.bot.is_owner(ctx.author): return True @@ -55,6 +70,13 @@ async def check_permissions(ctx: "ContextPlus", **perms: Dict[str, bool]): def guild_owner_or_permissions(**perms: Dict[str, bool]): + """Is a user the guild's owner or does this user have any perms ? + + Parameters + ---------- + **perms:dict + Perms to verify. + """ async def pred(ctx): if ctx.author is ctx.guild.owner: return True diff --git a/tuxbot/core/config.py b/tuxbot/core/config.py index 8d9a621..b9ec0ed 100644 --- a/tuxbot/core/config.py +++ b/tuxbot/core/config.py @@ -1,15 +1,14 @@ import json import logging - -__all__ = ["Config"] - -from typing import List, Dict, Union +from typing import List, Dict, Union, Any import discord from tuxbot.core.data_manager import data_path -log = logging.getLogger("tuxbot.config") +__all__ = ["Config"] + +log = logging.getLogger("tuxbot.core.config") class Config: @@ -40,14 +39,40 @@ class Config: return self.__getitem__(item) def owners_id(self) -> List[int]: + """Simply return the owners id saved in config file. + + Returns + ------- + str + Owners id. + """ return self.__getitem__('core').get('owners_id') def token(self) -> str: + """Simply return the bot token saved in config file. + + Returns + ------- + str + Bot token. + """ return self.__getitem__('core').get('token') def get_prefixes(self, guild: discord.Guild) -> List[str]: + """Get custom prefixes for one guild. + + Parameters + ---------- + guild:discord.Guild + The required guild prefixes. + + Returns + ------- + List[str] + List of all prefixes. + """ core = self.__getitem__('core') - prefixes = core\ + prefixes = core \ .get('guild', {}) \ .get(guild.id, {}) \ .get('prefixes', []) @@ -55,6 +80,18 @@ class Config: return prefixes def get_blacklist(self, key: str) -> List[Union[str, int]]: + """Return list off all blacklisted values + + Parameters + ---------- + key:str + Which type of blacklist to choice (guilds ? channels ?,...). + + Returns + ------- + List[Union[str, int]] + List containing blacklisted values. + """ core = self.__getitem__('core') blacklist = core \ .get('blacklist', {}) \ @@ -62,7 +99,24 @@ class Config: return blacklist - def update(self, cog_name, item, value) -> dict: + def update(self, cog_name: str, item: str, value: Any) -> dict: + """Update values in config file. + + Parameters + ---------- + cog_name:str + Name of cog who's corresponding to the config file. + item:str + Key to update. + value:Any + New values to apply. + + Returns + ------- + dict: + Updated values. + + """ datas = self.__getitem__(cog_name) path = data_path(self._cog_instance) diff --git a/tuxbot/core/data_manager.py b/tuxbot/core/data_manager.py index 1bd4d9a..789641c 100644 --- a/tuxbot/core/data_manager.py +++ b/tuxbot/core/data_manager.py @@ -3,7 +3,7 @@ from pathlib import Path import appdirs -log = logging.getLogger("tuxbot.data_manager") +log = logging.getLogger("tuxbot.core.data_manager") app_dir = appdirs.AppDirs("Tuxbot-bot") config_dir = Path(app_dir.user_config_dir) diff --git a/tuxbot/core/i18n.py b/tuxbot/core/i18n.py index 09f3977..00b579e 100644 --- a/tuxbot/core/i18n.py +++ b/tuxbot/core/i18n.py @@ -1,3 +1,4 @@ +import logging import os from pathlib import Path from typing import Callable, Union, Dict @@ -9,6 +10,8 @@ __all__ = [ "Translator", ] +log = logging.getLogger("tuxbot.core.i18n") + _translators = [] _current_locale = "en-US"