Changed the Client structure
This commit is contained in:
60
main.py
60
main.py
@@ -1,12 +1,12 @@
|
||||
import logging
|
||||
import sys
|
||||
from logging import Logger
|
||||
from pathlib import Path
|
||||
|
||||
from discord import Activity, ActivityType
|
||||
from libbot import config_get
|
||||
from discord import LoginFailure, Intents
|
||||
from libbot.sync import config_get as sync_config_get
|
||||
|
||||
from modules.client import client
|
||||
from classes.holo_bot import HoloBot
|
||||
from modules.scheduler import scheduler
|
||||
|
||||
logging.basicConfig(
|
||||
@@ -25,53 +25,25 @@ except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
@client.event
|
||||
async def on_ready() -> None:
|
||||
logger.info("Logged in as %s", client.user)
|
||||
|
||||
activity_type: str = await config_get("type", "status")
|
||||
activity_message: str = await config_get("message", "status")
|
||||
|
||||
if activity_type == "playing":
|
||||
await client.change_presence(
|
||||
activity=Activity(type=ActivityType.playing, name=activity_message)
|
||||
)
|
||||
elif activity_type == "watching":
|
||||
await client.change_presence(
|
||||
activity=Activity(type=ActivityType.watching, name=activity_message)
|
||||
)
|
||||
elif activity_type == "listening":
|
||||
await client.change_presence(
|
||||
activity=Activity(type=ActivityType.listening, name=activity_message)
|
||||
)
|
||||
elif activity_type == "streaming":
|
||||
await client.change_presence(
|
||||
activity=Activity(type=ActivityType.streaming, name=activity_message)
|
||||
)
|
||||
elif activity_type == "competing":
|
||||
await client.change_presence(
|
||||
activity=Activity(type=ActivityType.competing, name=activity_message)
|
||||
)
|
||||
elif activity_type == "custom":
|
||||
await client.change_presence(
|
||||
activity=Activity(type=ActivityType.custom, name=activity_message)
|
||||
)
|
||||
else:
|
||||
return
|
||||
|
||||
logger.info(
|
||||
"Set activity type to %s with message %s", activity_type, activity_message
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if not Path("config.json").exists():
|
||||
logger.error(
|
||||
"Config file is missing: Make sure the configuration file 'config.json' is in place."
|
||||
)
|
||||
sys.exit()
|
||||
|
||||
intents: Intents = Intents().all()
|
||||
client: HoloBot = HoloBot(intents=intents, scheduler=scheduler)
|
||||
|
||||
client.load_extension("cogs")
|
||||
|
||||
try:
|
||||
scheduler.start()
|
||||
client.run(sync_config_get("bot_token", "bot"))
|
||||
except LoginFailure as exc:
|
||||
logger.error("Provided bot token is invalid: %s", exc)
|
||||
except KeyboardInterrupt:
|
||||
scheduler.shutdown()
|
||||
logger.info("KeyboardInterrupt received: Shutting down gracefully.")
|
||||
finally:
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user