80 lines
2.1 KiB
Python
80 lines
2.1 KiB
Python
import logging
|
|
import sys
|
|
from logging import Logger
|
|
|
|
from discord import Activity, ActivityType
|
|
from libbot import config_get
|
|
from libbot.sync import config_get as sync_config_get
|
|
|
|
from modules.client import client
|
|
from modules.scheduled import scheduler
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(name)s.%(funcName)s | %(levelname)s | %(message)s",
|
|
datefmt="[%X]",
|
|
)
|
|
|
|
logger: Logger = logging.getLogger(__name__)
|
|
|
|
try:
|
|
import uvloop # type: ignore
|
|
|
|
uvloop.install()
|
|
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:
|
|
client.load_extension("cogs")
|
|
|
|
try:
|
|
scheduler.start()
|
|
client.run(sync_config_get("bot_token", "bot"))
|
|
except KeyboardInterrupt:
|
|
scheduler.shutdown()
|
|
sys.exit()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|