-
Notifications
You must be signed in to change notification settings - Fork 4
/
adminbot.py
66 lines (52 loc) · 1.59 KB
/
adminbot.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
from cmdproc import zycmd
from telegram.ext import Updater
import mysystemd
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/maotaibot/"))
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_path = PATH
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']}")
commands = []
# 在这里加入功能
from cmdproc import admincmd, zycmd
commands += admincmd.add_dispatcher(dispatcher)
commands += zycmd.add_dispatcher(dispatcher)
updater.bot.set_my_commands(commands)
updater.start_polling()
print('Started...')
mysystemd.ready()
updater.idle()
print('Stopping...')
print('Stopped.')