-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__main__.py
More file actions
80 lines (62 loc) · 2.05 KB
/
__main__.py
File metadata and controls
80 lines (62 loc) · 2.05 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import re
from asyncio import run
from argparse import ArgumentParser
from os import listdir
from discord import Intents
from discord.ext.commands import Bot, when_mentioned
from consts import get_secret
bot = Bot(when_mentioned, intents=Intents.all())
@bot.event
async def on_ready():
await bot.tree.sync()
async def load_cogs(cog_re=r".*"):
filter_pattern = re.compile(cog_re)
for file in listdir("cogs"):
# cog name validation
if not file.endswith(".py") or file.startswith("_"):
continue
if filter_pattern.search(file[:-3]) is None:
continue
# load cog
cog_name = file[:-3]
print(f"Loading cog `{cog_name}` ...", end="\r")
await bot.load_extension(f"cogs.{cog_name}")
print(f"Cog loaded: {cog_name} ")
def parse_args():
from consts import override_const
parser = ArgumentParser()
parser._actions[0].help = "도움말 메시지를 보여주고 종료합니다"
parser.add_argument(
"-t",
"--test",
action="store_true",
help="봇을 `test_bot_token`으로 실행합니다. "
"설정되지 않은 경우, `bot_token`으로 실행합니다",
)
parser.add_argument(
"-c",
"--cog",
action="store",
default=r".*",
help="이 정규표현식을 만족하는 이름을 가진 코그만 실행합니다",
)
parser.add_argument(
"-o",
"--override",
action="append",
help="const를 override합니다. `key=value`의 형태로 입력합니다.",
)
args = parser.parse_args()
if args.test:
print("Run in test mode ...")
if args.override:
for override in args.override:
key, value = override.split("=")
override_const(key, eval(value))
print(f"Constant overlode: {key} = {value}")
return args
if __name__ == "__main__":
args = parse_args()
run(load_cogs(args.cog))
bot_token = get_secret("test_bot_token" if args.test else "bot_token")
bot.run(bot_token)