-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·66 lines (54 loc) · 1.66 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
"""
Tick Tock Tick Tack
"""
import asyncio
import logging
import os
import sys
import discord
from discord.ext import commands
from clockbot import ClockBot
logging.addLevelName(logging.WARNING, "WARN")
logging.addLevelName(logging.CRITICAL, "FATAL")
logging.basicConfig(
# FEAT: set log level from command line arguments
level=logging.INFO,
format="{asctime} {levelname:<5} [{name}] {message}",
datefmt="%Y-%m-%d %H:%M:%S",
style="{",
# FEAT: write to `log/YYYY-MM-DD.log` using `TimedRotatingFileHandler`
stream=sys.stdout,
)
try:
# FIX: secret in environment variable does not feel so secure
TOKEN = os.environ["TOKEN"]
PREFIX = os.environ["PREFIX"]
except KeyError as e:
env: str = e.args[0]
logging.critical("Environment variable %s is missing", env)
sys.exit(1)
async def main() -> None:
bot = ClockBot(
command_prefix=commands.when_mentioned_or(PREFIX),
intents=discord.Intents.all(),
status=discord.Status.do_not_disturb,
activity=discord.Game("코드 갈아엎기"),
help_command=commands.DefaultHelpCommand(),
)
async with bot:
await bot.load_extension("jishaku")
try:
await bot.start(TOKEN)
except discord.LoginFailure:
logging.critical("Invalid bot token; Client login failed")
sys.exit(1)
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
logging.info("Received SIGINT")
except Exception: # noqa: BLE001
logging.critical("Unhandled Exception has occured", exc_info=True)
finally:
logging.info("Client terminated")