WIP: Overhaul for 4.0.0
This commit is contained in:
0
src/libbot/pycord/__init__.py
Normal file
0
src/libbot/pycord/__init__.py
Normal file
@@ -1,35 +1,35 @@
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Union
|
||||
from typing import Any, Dict, Union
|
||||
|
||||
from typing_extensions import override
|
||||
|
||||
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
|
||||
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 _
|
||||
from ...i18n.classes import BotLocale
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PycordBot(Bot):
|
||||
@override
|
||||
def __init__(
|
||||
self,
|
||||
*args,
|
||||
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,
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
if config is None:
|
||||
@@ -39,9 +39,7 @@ class PycordBot(Bot):
|
||||
self.config = config
|
||||
|
||||
super().__init__(
|
||||
debug_guilds=(
|
||||
self.config["bot"]["debug_guilds"] if self.config["debug"] else None
|
||||
),
|
||||
debug_guilds=(self.config["bot"]["debug_guilds"] if self.config["debug"] else None),
|
||||
owner_ids=self.config["bot"]["owners"],
|
||||
*args,
|
||||
**kwargs,
|
||||
@@ -60,12 +58,14 @@ class PycordBot(Bot):
|
||||
|
||||
self.scheduler: Union[AsyncIOScheduler, BackgroundScheduler, None] = scheduler
|
||||
|
||||
@override
|
||||
async def start(self, token: str, reconnect: bool = True, scheduler_start: bool = True) -> None:
|
||||
if self.scheduler is not None and scheduler_start:
|
||||
self.scheduler.start()
|
||||
|
||||
await super().start(token, reconnect=reconnect)
|
||||
|
||||
@override
|
||||
async def close(self, scheduler_shutdown: bool = True, scheduler_wait: bool = True) -> None:
|
||||
if self.scheduler is not None and scheduler_shutdown:
|
||||
self.scheduler.shutdown(scheduler_wait)
|
||||
|
Reference in New Issue
Block a user