Skip to content

Commit

Permalink
ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
zunda-arrow committed Nov 22, 2024
1 parent 16bec04 commit bd564aa
Show file tree
Hide file tree
Showing 13 changed files with 1,649 additions and 1,649 deletions.
2 changes: 1 addition & 1 deletion bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""HC-TCG online bot."""
"""HC-TCG online bot."""
100 changes: 50 additions & 50 deletions bot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
"""Run the bot."""

from importlib import import_module
from os import listdir, path
from time import time

from apscheduler.schedulers.asyncio import AsyncIOScheduler
from interactions import Client, listen

from bot.config import CONFIG
from bot.util import ServerManager

start = time()


class Bot(Client):
"""Slightly modified discord client."""

@listen()
async def on_ready(self: "Bot") -> None:
"""Handle bot starting."""
await server_manager.reload_all_generators()

await bot.change_presence()
scheduler.start()

print(f"Bot started in {round(time()-start, 2)}s")

@listen()
async def on_disconnect(self: "Bot") -> None:
"""Handle bot disconnection."""
await server_manager.close_all_sessions()
scheduler.shutdown()


bot = Bot()

scheduler = AsyncIOScheduler()

servers = []
for file in listdir("servers"):
if not path.isfile(f"servers/{file}"):
continue
servers.append(import_module(f"servers.{file.removesuffix(".py")}").server)

server_manager = ServerManager(bot, servers)

bot.load_extensions("bot\\exts", manager=server_manager, scheduler=scheduler)

bot.start(CONFIG.SECRET)
"""Run the bot."""

from importlib import import_module
from os import listdir, path
from time import time

from apscheduler.schedulers.asyncio import AsyncIOScheduler
from interactions import Client, listen

from bot.config import CONFIG
from bot.util import ServerManager

start = time()


class Bot(Client):
"""Slightly modified discord client."""

@listen()
async def on_ready(self: "Bot") -> None:
"""Handle bot starting."""
await server_manager.reload_all_generators()

await bot.change_presence()
scheduler.start()

print(f"Bot started in {round(time()-start, 2)}s")

@listen()
async def on_disconnect(self: "Bot") -> None:
"""Handle bot disconnection."""
await server_manager.close_all_sessions()
scheduler.shutdown()


bot = Bot()

scheduler = AsyncIOScheduler()

servers = []
for file in listdir("servers"):
if not path.isfile(f"servers/{file}"):
continue
servers.append(import_module(f"servers.{file.removesuffix(".py")}").server)

server_manager = ServerManager(bot, servers)

bot.load_extensions("bot\\exts", manager=server_manager, scheduler=scheduler)

bot.start(CONFIG.SECRET)
44 changes: 22 additions & 22 deletions bot/config.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
"""Load environment config."""

from __future__ import annotations

import os

import dotenv


class Config:
"""Load environement variables as class."""

def __init__(self: Config) -> None:
"""Load environement variables as class."""
dotenv.load_dotenv()

env = os.environ

self.SECRET: str = env.get("DISCORD_SECRET") or ""


CONFIG = Config()
"""Load environment config."""

from __future__ import annotations

import os

import dotenv


class Config:
"""Load environement variables as class."""

def __init__(self: Config) -> None:
"""Load environement variables as class."""
dotenv.load_dotenv()

env = os.environ

self.SECRET: str = env.get("DISCORD_SECRET") or ""


CONFIG = Config()
Loading

0 comments on commit bd564aa

Please sign in to comment.