-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.py
157 lines (138 loc) · 5.89 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import telebot
import user
import config
import proxys
from telebot import types
from urllib import parse
global proxylist, tgproxylist
bot = telebot.TeleBot(config.token)
proxys.init()
@bot.message_handler(commands=["start", "help"])
def send_welcome(message):
bot.send_message(message.chat.id, "命令列表:\n/help - 帮助\n/proxy - 获取v2ray代理(带clash订阅转换)\n/tgproxy - 获取telegram直连(mtproxy)代理\n/sign - 签到\n/info - 获取当前积分\n/list - 获取当前代理池数量\n/add - 向代理池添加代理[admin]\n/rm - 删除代理池的某个代理[admin]\n/getlist - 获取代理池全部内容[admin]\n/add_integral - 增加某个用户的积分[admin]\n/deduct_integral - 扣除某个用户的积分[admin]")
@bot.message_handler(commands=["sign"])
def send_welcome(message):
global signmsg_id
markup = types.InlineKeyboardMarkup()
sign = types.InlineKeyboardButton("点我签到", callback_data='sign')
markup.add(sign)
signmsg_id = bot.send_message(message.chat.id, "点击按钮完成签到", reply_markup=markup).message_id
@bot.message_handler(commands=["info"])
def send_welcome(message):
bot.send_message(message.chat.id, user.get_deduct(message.chat.id))
@bot.message_handler(commands=["list"])
def send_welcome(message):
bot.send_message(message.chat.id, proxys.get_proxylist())
@bot.message_handler(commands=["proxy"])
def send_welcome(message):
deduct = user.deduct_points(message.chat.id)
if deduct:
proxy = proxys.get_proxy()
URL = proxys.subconvert(proxy)
markup = types.InlineKeyboardMarkup()
subconverts = types.InlineKeyboardButton("订阅转换", url=URL)
markup.add(subconverts)
bot.send_message(message.chat.id, proxy, reply_markup=markup)
else:
bot.send_message(message.chat.id, "积分不足!")
@bot.message_handler(commands=["tgproxy"])
def send_welcome(message):
deduct = user.deduct_points(message.chat.id)
if deduct:
proxy = proxys.get_tgproxy()
bot.send_message(message.chat.id, proxy)
else:
bot.send_message(message.chat.id, "积分不足!")
@bot.message_handler(commands=["add_integral"])
def send_welcome(message):
for uid in config.adminlist:
if message.chat.id == uid:
isadmin = True
if isadmin:
bot.send_message(message.chat.id, user.add_integral(message.text.split(" ")[1], message.text.split(" ")[2]))
else:
bot.send_message(message.chat.id, "你不是管理员\n无法使用该命令!")
@bot.message_handler(commands=["deduct_integral"])
def send_welcome(message):
for uid in config.adminlist:
if message.chat.id == uid:
isadmin = True
if isadmin:
bot.send_message(message.chat.id, user.deduct_integral(message.text.split(" ")[1], message.text.split(" ")[2]))
else:
bot.send_message(message.chat.id, "你不是管理员\n无法使用该命令!")
@bot.message_handler(commands=["add"])
def send_welcome(message):
for uid in config.adminlist:
if message.chat.id == uid:
isadmin = True
if isadmin:
module = message.text.split(" ")[1]
text = message.text.split(" ")[2]
msg_id = bot.send_message(message.chat.id, "添加中..").message_id
if module == "mtproxy":
files = config.TGPROXY_FILE
elif module == "v2ray":
files = config.PROXY_FILE
else:
bot.edit_message_text("代理类型不存在", message.chat.id, msg_id)
return
with open(files, "a") as file:
file.write(text)
proxys.init()
bot.edit_message_text("以下代理已添加:\n" + text, message.chat.id, msg_id)
else:
bot.send_message(message.chat.id, "你不是管理员\n无法使用该命令!")
@bot.message_handler(commands=["rm"])
def send_welcome(message):
for uid in config.adminlist:
if message.chat.id == uid:
isadmin = True
if isadmin:
module = message.text.split(" ")[1]
text = message.text.split(" ")[2]
msg_id = bot.send_message(message.chat.id, "删除中..").message_id
if module == "mtproxy":
files = config.TGPROXY_FILE
elif module == "v2ray":
files = config.PROXY_FILE
else:
bot.edit_message_text("代理类型不存在", message.chat.id, msg_id)
return
with open(files, "r") as file:
new_contents = []
for line in file:
if text not in line:
new_contents.append(line)
with open(files, "w") as file:
for line in new_contents:
file.write(line)
proxys.init()
bot.edit_message_text("以下代理已删除:\n" + text, message.chat.id, msg_id)
else:
bot.send_message(message.chat.id, "你不是管理员\n无法使用该命令!")
@bot.message_handler(commands=["getlist"])
def send_welcome(message):
for uid in config.adminlist:
if message.chat.id == uid:
isadmin = True
if isadmin:
module = message.text.split(" ")[1]
if module == "mtproxy":
files = config.TGPROXY_FILE
elif module == "v2ray":
files = config.PROXY_FILE
else:
bot.edit_message_text("代理类型不存在", message.chat.id, msg_id)
return
file = open(files, "rb")
bot.send_document(message.chat.id, file)
bot.send_document(message.chat.id, "FILEID")
else:
bot.send_message(message.chat.id, "你不是管理员\n无法使用该命令!")
@bot.callback_query_handler(func=lambda call: True)
def callback_handle(call):
if call.data == "sign":
bot.delete_message(call.message.chat.id, signmsg_id)
bot.send_message(call.message.chat.id, "@" + call.message.chat.username + " " + user.sign_in(call.message.chat.id) + "\n" + user.get_deduct(call.message.chat.id))
bot.infinity_polling()