sentient-jimmy/jimmy/main.py

53 lines
1.5 KiB
Python
Raw Permalink Normal View History

import os
import logging
import discord
import sys
from discord.ext import commands
from tortoise import Tortoise
from config import get_config
sys.path.extend([".", ".."])
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("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()