async def my_event_handler(event): builder = event.builder try: plugins = utilities.plugins for plugin in plugins: if "inlineQuery" not in plugin: continue for pattern in plugin["inlineData"]: if re.search(pattern, str(event.text), re.IGNORECASE | re.MULTILINE): matches = re.findall( pattern, str(event.text), re.IGNORECASE | re.MULTILINE | re.DOTALL, ) if plugin["sudo"]: if utilities.check_sudo(event.sender_id): return_values = await plugin["inlineQuery"]( event, matches[0], event.chat_id, 0 if (event.sender_id not in utilities.user_steps) else utilities.user_steps[event.sender_id]["step"], crons=utilities.crons, ) for return_value in return_values: if return_value: try: await (return_value) except Exception as e: print("inline :" + str(e)) else: await event.answer([ builder.article("for sudors only", text="for sudors only") ]) else: return_values = await plugin["inlineQuery"]( event, matches[0], event.chat_id, 0 if (event.sender_id not in utilities.user_steps) else utilities.user_steps[event.sender_id]["step"], ) if return_values: for return_value in return_values: await (return_value) except Exception as e: print(str(e))
async def handler(event): try: plugins = utilities.plugins for plugin in plugins: if "callbackQuery" not in plugin: continue for pattern in plugin["callbackData"]: if re.search(pattern, str(event.data.decode()), re.IGNORECASE | re.MULTILINE): matches = re.findall( pattern, str(event.data.decode()), re.IGNORECASE | re.MULTILINE | re.DOTALL, ) if plugin["sudo"]: if utilities.check_sudo(event.sender_id): return_values = await plugin["callbackQuery"]( event, matches[0], event.chat_id, 0 if (event.sender_id not in utilities.user_steps) else utilities.user_steps[event.sender_id]["step"], crons=utilities.crons, ) for return_value in return_values: if return_value: try: await (return_value) except Exception as e: print("callback :" + str(e)) else: await event.answer("Sudors only!") else: return_values = await plugin["callbackQuery"]( event, matches[0], event.chat_id, 0 if (event.sender_id not in utilities.user_steps) else utilities.user_steps[event.sender_id]["step"], ) if return_values: for return_value in return_values: await (return_value) except Exception as e: print(str(e))
def getallUsage(id,name=None): response_text = "" plugin_files = [name] if name == None: plugin_files = [ files for files in os.listdir(join(utilities.WD, "plugins")) if re.search("^(.*)\.py$", files) ] plugin_files.sort() msgs = [] for plugin_file in plugin_files: plugin_file = plugin_file.replace(".py", "") if plugin_file == "__init__" : continue if plugin_file in utilities.config["plugins"]: plugin = utilities.load_plugin(plugin_file) if ( not utilities.check_sudo(id) and plugin["sudo"]): continue if "usage" in plugin: response_text += ( "ℹ️ " + plugin["name"] + "'s usage :\n" + "".join(((i + "\n")) for i in plugin["usage"]) + "\n" + ("" if name == None else "Description : " + plugin["desc"]) ) else: response_text += ( "ℹ️ " + plugin["name"] + "'s patterns :\n" + "".join((i + "\n") for i in plugin["patterns"]) + "\n" ) if len(response_text) > 3500: msgs.append(response_text) response_text = "" else: if name != None: msgs.append("no such a plugin") return msgs if len(response_text) > 0: msgs.append(response_text) return msgs
async def run(message, matches, chat_id, step, crons=None): response = [] if (utilities.check_sudo(message.sender_id)): if matches == "تفعيل الردود": isActive = getPropSetting(message.chat_id, propName) or None if isActive and isActive.active: response.append(message.reply("auto reply already activated.")) else: if togglePropSettings(message.chat_id, propName): response.append(message.reply("❏︙تم تفعيل الردود بنجاح")) else: response.append(message.reply("error while doing that.")) return response elif matches == "تعطيل الردود": isActive = getPropSetting(message.chat_id, propName) or None if not isActive or isActive.active: if togglePropSettings(message.chat_id, propName, False): response.append(message.reply("❏︙تم تعطيل الردود")) else: response.append(message.reply("error while doing that.")) else: response.append( message.reply("auto reply already deactivated.")) return response elif matches[0] == "اضف رد": bot = utilities.config["isbot"] if message.is_reply: msg = await message.get_reply_message() if msg.media: if bot: file = utils.pack_bot_file_id(msg.media) await utilities.client.send_file(msg.chat_id, file) else: downlodd_file = await msg.download_media( "tmp/autoReply") up_file = await utilities.client.upload_file( downlodd_file, use_cache=True) sent_file = await utilities.client.send_file( msg.chat_id, up_file) file = utils.pack_bot_file_id(sent_file.media) addAutoReply(matches[1], "media", msg.text, file) else: addAutoReply(matches[1], "text", msg.text) response.append(message.reply("❏︙تم اضافه رد بنجاح")) else: response.append(message.reply("please reply to a message.")) return response elif matches[0] == "حذف رد": if remAutoReplySetting(matches[1]): response.append(message.reply("❏︙تم حذف رد بنجاح")) else: response.append(message.reply("❏︙لا يوجد هاكذا رد ")) return response isActive = getPropSetting(message.chat_id, propName) or None if isActive and isActive.active: rep = getAutoReply(message.text) if rep: if rep.msg_type == "media": return [ message.reply(file=rep.file_id, message=rep.msg_content) ] else: return [message.reply(rep.msg_content)] else: return response return response
async def my_event_handler(event): try: message = event.message chat_id = event.chat_id from_id = event.sender_id plugins = utilities.plugins mutedUsers = getMutedUser(chat_id, from_id) if mutedUsers: remMuteUser(chat_id, from_id) if message.raw_text: matches = re.findall("^[#/!](cancel)$", event.raw_text, re.IGNORECASE) if len(matches) > 0 and matches[0] == "cancel": if from_id in utilities.user_steps: del utilities.user_steps[from_id] return await message.reply("Canceling successfully !") if from_id in utilities.user_steps: for plugin in plugins: if plugin["name"] == utilities.user_steps[from_id]["name"]: for pattern in plugin["patterns"]: if re.search(pattern, event.raw_text, re.IGNORECASE | re.MULTILINE): matches = re.findall(pattern, event.raw_text, re.IGNORECASE | re.DOTALL) break else: matches = ["xxxxxxxxxx"] if plugin["sudo"]: if utilities.check_sudo(from_id): return_values = await plugin["run"]( message, matches[0], chat_id, utilities.user_steps[from_id]["step"], ) for return_value in return_values: if return_value: try: await (return_value) except Exception as e: print("step :" + str(e)) else: return else: return_values = await plugin["run"]( message, matches[0], chat_id, utilities.user_steps[from_id]["step"], ) if return_values: for return_value in return_values: await (return_value) break return elif message.raw_text is not None and message.raw_text != "": if "flood" not in utilities.config: utilities.config["flood"] = True utilities.save_config() if utilities.config["flood"]: pv = utilities.red.get("flood-" + str(message.sender_id)) or 0 # print("flood-" + str(message.sender_id), pv) if pv == 0: utilities.flood[message.sender_id] = True utilities.red.set("flood-" + str(message.sender_id), (int(pv) + 1), ex=1) if (int(pv) + 1) == 5 and utilities.flood[message.sender_id]: await message.reply("please do not flood...") utilities.prRed( str(message.sender_id) + " : is causing flood please stop...") utilities.flood[message.sender_id] = False return elif (int(pv) + 1) >= 5: return for plugin in plugins: for pattern in plugin["patterns"]: if re.search(pattern, event.raw_text, re.IGNORECASE | re.MULTILINE): if ("bot" in plugin and utilities.config["isbot"] != plugin["bot"]): if plugin["bot"]: await event.reply("for bot-api only") else: await event.reply("for bot-cli only") return matches = re.findall( pattern, event.raw_text, re.IGNORECASE | re.MULTILINE | re.DOTALL, ) if plugin["sudo"]: if utilities.check_sudo(event.sender_id): return_values = await plugin["run"]( event, matches[0], chat_id, 0, crons=utilities.crons) for return_value in return_values: if return_value: try: await (return_value) except Exception as e: print("text main :" + str(e)) else: continue else: return_values = await plugin["run"]( event, matches[0], chat_id, 0, crons=utilities.crons) if return_values: for return_value in return_values: await (return_value) elif message.media is not None or message.file is not None: match = "" if message.photo: match = "__photo__" if message.gif: match = "__gif__" for plugin in plugins: for pattern in plugin["patterns"]: if re.search(pattern, match, re.IGNORECASE | re.MULTILINE): matches = re.findall(pattern, match, re.IGNORECASE) if plugin["sudo"]: if utilities.check_sudo(event.sender_id): return_values = await plugin["run"](event, matches[0], chat_id, 0) for return_value in return_values: try: await (return_value) except Exception as e: print("media :" + str(e)) else: return else: return_values = await plugin["run"](event, matches[0], chat_id, 0) if return_values: for return_value in return_values: await (return_value) except Exception as e: print(str(e)) await event.reply("Error : " + str(e))