2023-05-02 16:46:15 +03:00
|
|
|
import logging
|
2024-12-16 21:34:37 +02:00
|
|
|
import sys
|
|
|
|
from logging import Logger
|
2023-05-02 16:46:15 +03:00
|
|
|
|
|
|
|
from discord import Activity, ActivityType
|
2024-12-16 00:36:48 +02:00
|
|
|
from libbot import config_get
|
|
|
|
from libbot.sync import config_get as sync_config_get
|
2023-05-02 16:46:15 +03:00
|
|
|
|
2023-05-06 19:56:01 +03:00
|
|
|
from modules.client import client
|
2024-12-16 21:59:10 +02:00
|
|
|
from modules.scheduler import scheduler
|
2023-05-02 16:46:15 +03:00
|
|
|
|
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.INFO,
|
|
|
|
format="%(name)s.%(funcName)s | %(levelname)s | %(message)s",
|
|
|
|
datefmt="[%X]",
|
|
|
|
)
|
|
|
|
|
2024-12-16 21:34:37 +02:00
|
|
|
logger: Logger = logging.getLogger(__name__)
|
2023-05-02 16:46:15 +03:00
|
|
|
|
|
|
|
try:
|
2023-05-04 17:14:33 +03:00
|
|
|
import uvloop # type: ignore
|
2023-05-02 16:46:15 +03:00
|
|
|
|
|
|
|
uvloop.install()
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@client.event
|
2024-12-16 21:34:37 +02:00
|
|
|
async def on_ready() -> None:
|
2024-06-23 13:05:03 +03:00
|
|
|
logger.info("Logged in as %s", client.user)
|
2023-05-06 20:06:04 +03:00
|
|
|
|
2024-12-16 21:34:37 +02:00
|
|
|
activity_type: str = await config_get("type", "status")
|
|
|
|
activity_message: str = await config_get("message", "status")
|
2023-05-06 20:06:04 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-06-23 13:05:03 +03:00
|
|
|
logger.info(
|
|
|
|
"Set activity type to %s with message %s", activity_type, activity_message
|
|
|
|
)
|
2023-05-04 17:14:33 +03:00
|
|
|
|
2023-05-02 16:46:15 +03:00
|
|
|
|
2024-12-16 21:34:37 +02:00
|
|
|
def main() -> None:
|
2024-06-23 13:05:03 +03:00
|
|
|
client.load_extension("cogs")
|
2023-05-04 17:09:47 +03:00
|
|
|
|
2023-05-02 16:46:15 +03:00
|
|
|
try:
|
|
|
|
scheduler.start()
|
2024-12-16 00:36:48 +02:00
|
|
|
client.run(sync_config_get("bot_token", "bot"))
|
2023-05-02 16:46:15 +03:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
scheduler.shutdown()
|
2024-12-16 21:34:37 +02:00
|
|
|
sys.exit()
|
2023-05-02 16:46:15 +03:00
|
|
|
|
2023-05-04 17:14:33 +03:00
|
|
|
|
2023-05-02 16:46:15 +03:00
|
|
|
if __name__ == "__main__":
|
2023-05-04 17:14:33 +03:00
|
|
|
main()
|