54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
|
import os
|
||
|
import sys
|
||
|
import logging
|
||
|
import discord
|
||
|
from discord.ext import commands
|
||
|
from tortoise import Tortoise
|
||
|
sys.path.extend("..") # noqa: E402
|
||
|
from .config import get_config
|
||
|
|
||
|
|
||
|
log = logging.getLogger(__name__)
|
||
|
logging.basicConfig(level=logging.INFO)
|
||
|
|
||
|
|
||
|
class SentientJimmy(commands.Bot):
|
||
|
def __init__(self):
|
||
|
intents = discord.Intents.default()
|
||
|
# noinspection PyUnresolvedReferences
|
||
|
intents.message_content = True
|
||
|
super().__init__(
|
||
|
commands.when_mentioned_or("."),
|
||
|
intents=intents,
|
||
|
case_insensitive=True,
|
||
|
strip_after_prefix=True,
|
||
|
debug_guilds=get_config()["bot"].get("debug_guilds"),
|
||
|
)
|
||
|
self.load_extension("jimmy.cogs.chat")
|
||
|
self.load_extension("jishaku")
|
||
|
|
||
|
async def start(self, token: str, *, reconnect: bool = True) -> None:
|
||
|
is_docker = os.path.exists("/.dockerenv")
|
||
|
default_db = "sqlite://:memory:" if is_docker else "sqlite://default.db"
|
||
|
await Tortoise.init(
|
||
|
db_url=get_config()["bot"].get("db_url", default_db),
|
||
|
modules={"models": ["jimmy.db"]}
|
||
|
)
|
||
|
await Tortoise.generate_schemas()
|
||
|
await super().start(token, reconnect=reconnect)
|
||
|
|
||
|
async def close(self) -> None:
|
||
|
await Tortoise.close_connections()
|
||
|
await super().close()
|
||
|
|
||
|
def run(self) -> None:
|
||
|
token = get_config()["bot"]["token"]
|
||
|
super().run(token)
|
||
|
|
||
|
|
||
|
bot = SentientJimmy()
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
bot.run()
|