v3.1.0 #102
@ -1,6 +1,6 @@
|
||||
__version__ = "3.0.1"
|
||||
__version__ = "3.1.0"
|
||||
__license__ = "GPL3"
|
||||
__author__ = "Profitroll"
|
||||
|
||||
from . import i18n, pycord, pyrogram, sync
|
||||
from . import errors, i18n, pycord, pyrogram, sync
|
||||
from .__main__ import *
|
||||
|
1
src/libbot/errors/__init__.py
Normal file
1
src/libbot/errors/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .config import ConfigKeyError, ConfigValueError
|
37
src/libbot/errors/config.py
Normal file
37
src/libbot/errors/config.py
Normal file
@ -0,0 +1,37 @@
|
||||
from typing import Any, List, Optional, Union
|
||||
|
||||
|
||||
class ConfigKeyError(Exception):
|
||||
"""Raised when config key is not found.
|
||||
|
||||
### Attributes:
|
||||
* key (`Union[str, List[str]]`): Missing config key.
|
||||
"""
|
||||
|
||||
def __init__(self, key: Union[str, List[str]]) -> None:
|
||||
self.key: Union[str, List[str]] = key
|
||||
super().__init__(
|
||||
f"Config key {'.'.join(key) if isinstance(key, list) else key} is missing. Please set in your config file."
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"Config key {'.'.join(self.key) if isinstance(self.key, list) else self.key} is missing. Please set in your config file."
|
||||
|
||||
|
||||
class ConfigValueError(Exception):
|
||||
"""Raised when config key's value is invalid.
|
||||
|
||||
### Attributes:
|
||||
* key (`Union[str, List[str]]`): Invalid config key.
|
||||
* value (`Optional[Any]`): Key's correct value.
|
||||
"""
|
||||
|
||||
def __init__(self, key: Union[str, List[str]], value: Optional[Any] = None) -> None:
|
||||
self.key: Union[str, List[str]] = key
|
||||
self.value: Optional[Any] = value
|
||||
super().__init__(
|
||||
f"Config key {'.'.join(key) if isinstance(key, list) else key} has invalid value. {f'Must be {value}. ' if value else ''}Please set in your config file."
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"Config key {'.'.join(self.key) if isinstance(self.key, list) else self.key} has invalid value. {f'Must be {self.value}. ' if self.value else ''}Please set in your config file."
|
@ -1,6 +1,6 @@
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Union
|
||||
from typing import Any, Dict, List, Union
|
||||
|
||||
try:
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
@ -29,6 +29,7 @@ class PycordBot(Bot):
|
||||
config_path: Union[str, Path] = Path("config.json"),
|
||||
locales_root: Union[str, Path, None] = None,
|
||||
scheduler: Union[AsyncIOScheduler, BackgroundScheduler, None] = None,
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
if config is None:
|
||||
@ -38,17 +39,19 @@ class PycordBot(Bot):
|
||||
self.config = config
|
||||
|
||||
super().__init__(
|
||||
debug_guilds=self.config["bot"]["debug_guilds"],
|
||||
owner_ids=self.config["bot"]["owners"],
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
self.owner_ids: List[int] = self.config["bot"]["owners"]
|
||||
self.debug_guilds: List[int] = self.config["bot"]["debug_guilds"]
|
||||
|
||||
self.bot_locale: BotLocale = BotLocale(
|
||||
default_locale=self.config["locale"],
|
||||
locales_root=(Path("locale") if locales_root is None else locales_root),
|
||||
)
|
||||
self.default_locale: str = self.bot_locale.default
|
||||
self.locales: dict = self.bot_locale.locales
|
||||
self.locales: Dict[str, Any] = self.bot_locale.locales
|
||||
|
||||
self._ = self.bot_locale._
|
||||
self.in_all_locales = self.bot_locale.in_all_locales
|
||||
|
Loading…
Reference in New Issue
Block a user