forked from yihong0618/tg_bot_collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtg.py
46 lines (33 loc) · 1.07 KB
/
tg.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
import argparse
from telebot import TeleBot
from handlers import list_available_commands, load_handlers
from os import environ
from dotenv import load_dotenv
load_dotenv()
TG_TOKEN = environ.get("TG_TOKEN")
def main():
# Init args
parser = argparse.ArgumentParser()
parser.add_argument("tg_token", help="tg token", default=TG_TOKEN)
# 'disable-command' option
# The action 'append' will allow multiple entries to be saved into a list
# The variable name is changed to 'disable_commands'
parser.add_argument(
"--disable-command",
action="append",
dest="disable_commands",
help="Specify a command to disable. Can be used multiple times.",
default=[],
choices=list_available_commands(),
)
options = parser.parse_args()
print("Arg parse done.")
# Init bot
bot = TeleBot(options.tg_token)
load_handlers(bot, options.disable_commands)
print("Bot init done.")
# Start bot
print("Starting tg collections bot.")
bot.infinity_polling()
if __name__ == "__main__":
main()