feat(doc): add docstrings

This commit is contained in:
Romain J 2020-06-06 02:00:16 +02:00
parent bf6d961658
commit cdb891d435
4 changed files with 87 additions and 8 deletions

View file

@ -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

View file

@ -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,12 +39,38 @@ 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 \
.get('guild', {}) \
@ -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)

View file

@ -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)

View file

@ -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"