# Regex Telegram Bot # It replaces words and letters etc <3 # use s/pattern/replace_string # example: # Reply to a message: "Allah Hu Akbar" # with: s/./nigger # Created by KuchiKuu # 2022-05-15 # Modified: 2020-05-15 import re def get_fucking_regex_faggot(m): check_g = len(m)-2 whole_string = False pattern = "" if(m[check_g:] == "/g"):# //Sadly, this does not work as intended. //todo # whole_string = True # print("Will check whole string") m = m[:check_g] is_it_simple = re.findall("/",m) # print(str(len(is_it_simple))) if(len(is_it_simple) == 1): result = m.split("/") # print("> Pattern is simple") # print(result[0] + " - " + result[1]) pattern = result[0] # if(whole_string == False): //todo # pattern = pattern + "?" return (pattern,result[1]) else: # print("> Pattern is complex") replace = "" current = "pattern" i = len(m) j = 0 while j != i: # print("Checking "+m[j]) if(m[j] == "/"): if(m[j-1] == "\\"): if(current=="pattern"): pattern = pattern + m[j] else: replace = replace + m[j] else: current = "replace" else: if(current=="pattern"): pattern = pattern + m[j] else: replace = replace + m[j] j = j + 1 # print(">pattern: "+pattern) # print(">replace: "+replace) # if(whole_string == False): //todo # pattern = pattern + "?" return (pattern,replace) return (-1,-1) import telebot import json config = {} TOKEN="" OWNER_ID=-1 with open("/root/telegram/regex/gatitaenvidiosa_config") as f: config = json.load(f) TOKEN=config["TOKEN"] OWNER_ID=config["OWNER_ID"] def debug_message(text): print(text) #exit() bot = telebot.TeleBot(TOKEN,parse_mode=None) @bot.message_handler(func=lambda m:True) def say_something(message): #bot.reply_to(message,str(message)) if(message.reply_to_message): if(message.reply_to_message.text): if(message.text): # print("OK") # print("Got a message: "+message.text); # print("Replied to: "+str(message.reply_to_message.text)) # bot.reply_to(message.reply_to_message,"LOL") if(message.text[:2] == "s/"): # print("Regex") regex_properties = get_fucking_regex_faggot(message.text[2:]) try: bot.reply_to(message.reply_to_message,re.sub(regex_properties[0],regex_properties[1],message.reply_to_message.text)) except re.error: bot.reply_to(message,"Learn regex bro") @bot.my_chat_member_handler() def membership(ChatMemberUpdated): if(ChatMemberUpdated.new_chat_member.user.id == bot.get_me().id): if(ChatMemberUpdated.new_chat_member.status == "member"): debug_message("I have joined a chat") bot.send_message(ChatMemberUpdated.chat.id,"Glory to the Palestine! DEATH TO ISRAEL!!") elif(ChatMemberUpdated.new_chat_member.status == "left"): debug_message("I have been removed from a chat.") bot.infinity_polling()