-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbot.py
68 lines (56 loc) · 2.11 KB
/
bot.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
67
68
#!/usr/bin/env python3
from telegram.ext import Updater
import os
import getopt
import sys
import config
def help():
return "'bot.py -c <configpath>'"
if __name__ == '__main__':
PATH = os.path.dirname(os.path.expanduser("~/.config/codepractice/"))
try:
opts, args = getopt.getopt(sys.argv[1:],"hc:",["config="])
except getopt.GetoptError:
print(help())
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print(help())
sys.exit()
elif opt in ("-c","--config"):
PATH = arg
config.config_file = os.path.join(PATH,"config.json")
try:
CONFIG = config.load_config()
except FileNotFoundError:
print(f"config.json not found.Generate a new configuration file in {config.config_file}" )
config.set_default()
sys.exit(2)
updater = Updater(CONFIG['Token'], use_context=True)
dispatcher = updater.dispatcher
me = updater.bot.get_me()
CONFIG['ID'] = me.id
CONFIG['Username'] = '@' + me.username
config.set_default()
print(f"Starting... ID: {str(CONFIG['ID'])} , Username: {CONFIG['Username']}")
# 在这里加入功能
from cmdproc import startcmd,rewardscmd,admincmd,weathercmd,infocmd,penaltiescmd,guesscmd,capitals,botadmincmd
from cmdproc import youtubemusic,game24,storymakergame
commands = startcmd.add_dispatcher(dispatcher)
commands = admincmd.add_dispatcher(dispatcher)
commands = rewardscmd.add_dispatcher(dispatcher)
commands += weathercmd.add_dispatcher(dispatcher)
commands += penaltiescmd.add_dispatcher(dispatcher)
commands += guesscmd.add_dispatcher(dispatcher)
commands += infocmd.add_dispatcher(dispatcher)
commands += capitals.add_handler(dispatcher)
commands += botadmincmd.add_dispatcher(dispatcher)
commands += youtubemusic.add_dispatcher(dispatcher)
commands += game24.add_handler(dispatcher)
commands += storymakergame.add_handler(dispatcher)
updater.bot.set_my_commands(commands)
updater.start_polling()
print('Started...')
updater.idle()
print('Stopping...')
print('Stopped.')