-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathRRR.py
198 lines (182 loc) · 8.03 KB
/
RRR.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import plugins
from utils import *
from plugins import *
updater = Updater(token=config['bot'])
dispatcher = updater.dispatcher
for plugin in plugins.__all__:
active = eval(plugin).info['active']
if "auto" not in plugin and "inline" not in plugin:
if active:
handler = CommandHandler(eval(plugin).info['triggers'], eval(plugin).action, pass_args=True)
dispatcher.add_handler(handler)
else:
pass
elif "inline" in plugin:
if active:
handler = CommandHandler(eval(plugin).info['triggers'], eval(plugin).action, pass_args=True)
dispatcher.add_handler(handler)
handler = CallbackQueryHandler(eval(plugin).button)
dispatcher.add_handler(handler)
else:
pass
else:
if active:
print (eval(plugin).info['triggers'])
handler = RegexHandler(eval(plugin).info['triggers'], eval(plugin).action)
dispatcher.add_handler(handler)
else:
pass
handler = MessageHandler(Filters.text, plugins.autoMessages.action)
dispatcher.add_handler(handler)
class RegexFilter(BaseFilter):
def filter(self, message):
return '/s/' == message.text[0:3]
def regex(bot, update):
# try:
cid = getCID(update)
rid = update.message.reply_to_message
if rid and cid != degeneratesgroup:
content = update.message.text
if content.split('/')[1] == 's':
lookfor = r"" + content.split('/')[2]
replacewith = r"" + content.split('/')[3]
final_text = re.sub(lookfor, replacewith, rid.text)
update.message.reply_text("`" + final_text + "`", parse_mode="Markdown", reply_to_message_id=update.message.message_id)
else:
pass
# except:
# pass
regex_filter = RegexFilter()
dispatcher.add_handler(MessageHandler(Filters.command & regex_filter, regex))
def help(bot, update, args):
"""
Returns the help for any given command, if more than one, will make a single message with them
if no command, will return all the active commands
"""
UID = getUID(update)
CID = getCID(update)
# If theres only one command
if len(args) == 1:
# Check if exists
try:
try:
command = eval(args[0].lower())
success = True
except:
success = False
for plugin in plugins.__all__:
if "auto" not in plugin:
command = eval(plugin)
if command.info['active']:
if type(command.info['triggers']) == tuple:
for trigger in command.info['triggers']:
if args[0].lower() == trigger:
success = True
break
else:
if args[0].lower() == command.info['triggers']:
success = True
if success:
break
# Check if its active
if command.info['active'] and success:
if type(command.info['triggers']) == tuple:
triggers = "\n\n Alternative Triggers:"
for trigger in command.info['triggers']:
triggers += "\n " + trigger
else:
triggers = ""
# Check if its admin command and if user is admin
if command.info['admin'] and UID == adminid:
# Has example?
if command.info['example']:
bot.send_message(CID,"`> " + command.info['name'] + " [admin]`\n\n /" + args[0] + " `" + command.info['arguments'] + "\n\n " + command.info['help'].replace('\n', '\n ') + "\n\n Example:\n " + command.info['example'].replace('\n', '\n ') + triggers + "`", parse_mode="Markdown")
else:
bot.send_message(CID,"`> " + command.info['name'] + " [admin]`\n\n /" + args[0] + " `" + command.info['arguments'] + "\n\n " + command.info['help'].replace('\n', '\n ') + triggers + "`", parse_mode="Markdown")
elif not command.info['admin']:
# Has example?
if command.info['example']:
bot.send_message(CID,"`> " + command.info['name'] + "`\n\n /" + args[0] + " `" + command.info['arguments'] + "\n\n " + command.info['help'].replace('\n', '\n ') + "\n\n Example:\n " + command.info['example'].replace('\n', '\n ') + triggers + "`", parse_mode="Markdown")
else:
bot.send_message(CID,"`> " + command.info['name'] + "`\n\n /" + args[0] + " `" + command.info['arguments'] + "\n\n " + command.info['help'].replace('\n', '\n ') + triggers + "`", parse_mode="Markdown")
else:
pass
else:
bot.send_message(CID, "`Theres no " + args[0] +" command.`", parse_mode="Markdown" )
except:
bot.send_message(CID, "`Theres no " + args[0] +" command.`", parse_mode="Markdown" )
# If theres more than one command
elif len(args) > 1:
message = ""
for arg in args:
try:
# Check if exists
command = eval(arg.lower())
#Check if its still active
if command.info['active']:
if type(command.info['triggers']) == tuple:
triggers = "\n\n Alternative Triggers:"
for trigger in command.info['triggers']:
triggers += "\n " + trigger
else:
triggers = ""
# Check if its admin command and if user is admin
if command.info['admin'] and UID == adminid:
# Has example?
if command.info['example']:
message += "`> " + command.info['name'] + " [admin]`\n\n /" + arg + " `" + command.info['arguments'] + "\n\n " + command.info['help'].replace('\n', '\n ') + "\n\n Example:\n " + command.info['example'].replace('\n', '\n ') + triggers + "`\n\n"
else:
message += "`> " + command.info['name'] + " [admin]`\n\n /" + arg + " `" + command.info['arguments'] + "\n\n " + command.info['help'].replace('\n', '\n ') + triggers + "`\n\n"
elif not command.info['admin']:
# Has example?
if command.info['example']:
message += "`> " + command.info['name'] + "`\n\n /" + arg + " `" + command.info['arguments'] + "\n\n " + command.info['help'].replace('\n', '\n ') + "\n\n Example:\n " + command.info['example'].replace('\n', '\n ') + triggers + "`\n\n"
else:
message += "`> " + command.info['name'] + "`\n\n /" + arg + " `" + command.info['arguments'] + "\n\n " + command.info['help'].replace('\n', '\n ') + triggers + "`\n\n"
else:
pass
except:
message += "`> " + arg + "\n\n Not found.`\n\n"
bot.send_message(CID, message, parse_mode="Markdown")
else:
message = "`Heres a list of the currently active plugins:\n\n`"
commands = []
for plugin in plugins.__all__:
if "auto" not in plugin:
# If the plugin is active
command = eval(plugin)
if command.info['active']:
# Check if its admin command and if user is admin
if command.info['admin'] and UID == adminid:
if type(command.info['triggers']) == tuple:
commands.append("`> `/" + command.info['triggers'][0] + "` " + command.info['arguments'] + " [admin]`\n")
else:
commands.append("`> `/" + command.info['triggers'] + "` " + command.info['arguments'] + " [admin]`\n")
elif not command.info['admin']:
if type(command.info['triggers']) == tuple:
commands.append("`> `/" + command.info['triggers'][0] + "` " + command.info['arguments'] + "`\n")
else:
commands.append("`> `/" + command.info['triggers'] + "` " + command.info['arguments'] + "`\n")
else:
pass
else:
pass
commands.sort()
bot.send_message(CID, message + " ".join(commands) + "\n\n`Some of them will work right away, others need extra arguments, to know more about any command, send /help <command>`", parse_mode="Markdown")
def stop_and_restart():
"""Gracefully stop the Updater and replace the current process with a new one"""
updater.stop()
os.execl(sys.executable, sys.executable, *sys.argv)
def restart(bot, update):
cid = getCID(update)
if cid == adminid:
update.message.reply_text('`Bot is restarting...`', parse_mode="Markdown")
Thread(target=stop_and_restart).start()
dispatcher.add_handler(CommandHandler('restart', restart))
help_handler = CommandHandler('help', help, pass_args=True)
dispatcher.add_handler(help_handler)
dispatcher.add_error_handler(error)
updater.start_polling(clean=True)
print ("Running")
bot.send_message(adminid, "*Bot loaded and ready for action!*", parse_mode="Markdown")
updater.idle()