Merge pull request 'Pycord support initial release' (#48) from dev into main
Reviewed-on: #48
This commit is contained in:
commit
f0ffdf096d
@ -1,11 +1,11 @@
|
||||
black==23.11.0
|
||||
black==23.12.1
|
||||
build==1.0.3
|
||||
isort==5.13.0
|
||||
mypy==1.7.1
|
||||
pylint==3.0.2
|
||||
isort==5.13.2
|
||||
mypy==1.8.0
|
||||
pylint==3.0.3
|
||||
pytest-asyncio==0.23.2
|
||||
pytest-cov==4.1.0
|
||||
pytest==7.4.3
|
||||
tox==4.11.4
|
||||
types-aiofiles==23.2.0.0
|
||||
types-ujson==5.8.0.1
|
||||
types-ujson==5.9.0.0
|
@ -1 +1,2 @@
|
||||
apscheduler~=3.10.4
|
||||
py-cord~=2.4.1
|
@ -1,2 +1,2 @@
|
||||
apscheduler~=3.10.1
|
||||
apscheduler~=3.10.4
|
||||
pyrogram~=2.0.106
|
@ -1 +1 @@
|
||||
ujson~=5.8.0
|
||||
ujson~=5.9.0
|
@ -1,6 +1,6 @@
|
||||
__version__ = "2.0.1"
|
||||
__version__ = "2.1.0"
|
||||
__license__ = "GPL3"
|
||||
__author__ = "Profitroll"
|
||||
|
||||
from . import i18n, pyrogram, sync
|
||||
from . import i18n, pycord, pyrogram, sync
|
||||
from .__main__ import *
|
||||
|
1
src/libbot/pycord/classes/__init__.py
Normal file
1
src/libbot/pycord/classes/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .bot import PycordBot
|
57
src/libbot/pycord/classes/bot.py
Normal file
57
src/libbot/pycord/classes/bot.py
Normal file
@ -0,0 +1,57 @@
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Union
|
||||
|
||||
try:
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from discord import Bot
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"You need to install libbot[pycord] in order to use this class."
|
||||
) from exc
|
||||
|
||||
try:
|
||||
from ujson import loads
|
||||
except ImportError:
|
||||
from json import loads
|
||||
|
||||
from libbot.i18n import BotLocale
|
||||
from libbot.i18n.sync import _
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PycordBot(Bot):
|
||||
def __init__(
|
||||
self,
|
||||
config: Union[Dict[str, Any], None] = None,
|
||||
config_path: Union[str, Path] = Path("config.json"),
|
||||
locales_root: Union[str, Path, None] = None,
|
||||
scheduler: Union[AsyncIOScheduler, BackgroundScheduler, None] = None,
|
||||
**kwargs,
|
||||
):
|
||||
if config is None:
|
||||
with open(config_path, "r", encoding="utf-8") as f:
|
||||
self.config: dict = loads(f.read())
|
||||
else:
|
||||
self.config = config
|
||||
|
||||
super().__init__(
|
||||
debug_guilds=self.config["bot"]["debug_guilds"],
|
||||
owner_ids=self.config["bot"]["owners"],
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
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._ = self.bot_locale._
|
||||
self.in_all_locales = self.bot_locale.in_all_locales
|
||||
self.in_every_locale = self.bot_locale.in_every_locale
|
||||
|
||||
self.scheduler: Union[AsyncIOScheduler, BackgroundScheduler, None] = scheduler
|
Loading…
Reference in New Issue
Block a user