def rnd_elab(infos, text): try: x = 0 while "rnd[" in text: if x > 10: x = 0 / 0 minmax = text.split("rnd[")[1] minn = int(minmax.split(",")[0]) maxx = int(minmax.split(",")[1].split("]")[0]) if minn > maxx: x = 0 / 0 num = random.randint(minn, maxx) if "rnd[%s,%s]" % (minn, maxx) in text: text = text.replace("rnd[%s,%s]" % (minn, maxx), str(num), 1) elif "rnd[%s, %s]" % (minn, maxx) in text: text = text.replace("rnd[%s, %s]" % (minn, maxx), str(num), 1) x += 1 return text except Exception: warn = get_phrase("rnd[ err") HTTPLL.sendMessage(infos.token, chat_id=Manager.get_prop_id(infos.token), text=warn) Log.d("[Bot: @%s | %s] rnd error" % (infos.bid, infos.username)) return None
def restore(content, bid, lang_n): try: if lang_n != 0: dialogs = "dialogs_eng.json" triggers = "triggers_eng.json" else: dialogs = "dialogs.json" triggers = "triggers.json" new = decode("kitsu", content) x = json.loads(new) Log.d("Decode ok! JSON ok!") if "dialogs" not in x or "triggers" not in x: return False, "File di backup invalido!" with open("Files/bot_files/%s/%s" % (bid, dialogs), "w") as f: f.write(json.dumps(x["dialogs"])) with open("Files/bot_files/%s/%s" % (bid, triggers), "w") as f: f.write(json.dumps(x["triggers"])) return True, "Backup ripristinato con successo!" except Exception as err: Log.e(err) return False, str(err)
def reply_to_usermessage(self, msg, sendname, takename, chat_id, from_id, user_id): reply = None Log.d("Running RTU") if msg is not None: msg, branch = pars.ReadReply(msg) try: if branch == "admin_commands": reply = Manage.admin_commands(msg, chat_id, from_id, user_id, takename, branch) return reply if branch == "simple_interactions": if takename == "MayaChan": reply = pars.LoadDialog(msg, branch) pars.Usage(branch) return reply if branch == "user_interactions": reply = pars.LoadDialog(msg, branch) pars.Usage(branch) except: branch = None if reply is not None: if "{}" in reply: reply = reply.format(takename) return reply
def temp_mute(infos, minutes): try: time.sleep(minutes * 60) HTTPLL.restrictChatMember(infos.token, infos.cid, infos.to_user.uid) send(infos, "user_unmuted") except Exception as err: HTTPLL.sendMessage(infos.token, infos.cid, "Non ho potuto unmutare l'utente con ID %s..." % infos.to_user.uid) Log.d("Errore nel unmute: %s" % err)
def PTRun(): maxWeight = Core.setMaxWeight() items = parser.loadItems() VpSM = Core.addMatrixVpS(items) sortMatrix = Core.sortMatrix(VpSM) Core.algo(sortMatrix, maxWeight) Log.d(LL.uptime())
def Usage(branch): with open("Core/Data/json/trigger_usage.json") as use: data = json.load(use) count = data[branch]["count"] count = int(count) + 1 Log.d("Used " + branch + " " + str(count) + " times!") data[branch]["count"] = count with open("Core/Data/json/trigger_usage.json", "w") as use: json.dump(data, use)
def make_reply(self, msg, username, first_name): reply = None parse_mode = None if msg is not None: reply = None parse_mode = None msg, branch = pars.ReadTrigger(msg) reply, parse_mode = Manage.trigger(msg, branch, username) Log.d(str(reply) + " " + str(parse_mode)) return reply, parse_mode
def kick_chat_member(self, chat_id, user_id, until=None): if until: if until not in bans: Log.d("Invalid kick time") raise InvalidKickTime(until) until = time.time() + bans[until] url = self.base +"kickChatMember?chat_id={}&user_id={}&until_date={}".format(chat_id, user_id, until) value = requests.get(url) self.getError(value)
def delete_files(bid): if not bid: Log.w("Non posso eliminare i bot di None") return False bid = str(bid) try: shutil.rmtree("Files/bot_files/" + bid) Log.d("File rimossi") return True except: Log.w("I file del bot %s non esistono" % bid) return False
def kick_chat_member(toke, chat_id, user_id, until=None): if until: if until not in bans: Log.d("Invalid kick time") raise InvalidKickTime(until) until = time.time() + bans[until] return make_request("kickChatMember", toke, chat_id=chat_id, user_id=user_id, until_date=until)["result"]
def add_bot(user_id, bot_id, bot_token): try: new = {"user_id": user_id, "bot_id": bot_id} bots = json.loads(open("Files/jsons/bots.json").read()) if bot_token in bots: return False bots[bot_token] = new with open("Files/jsons/bots.json", "w") as fl: fl.write(json.dumps(bots)) Log.d("Nuovo bot (%s) aggiunto al file bots" % bot_id) return True except Exception as err: Log.e(err) return False
def update_handler(bot, update): try: infos = Infos.Infos(bot, update) if infos.error: return Log.d("Errore owo!") if infos.user.uid in json.loads(open("Files/jsons/blacklist.json").read()) or infos.skip: return if "message" in update: if "new_chat_members" not in update["message"]: return if update["message"]["new_chat_members"] or "left_chat_member" in update["message"]: if bot["id"] == Manager.get_main_bot_id(): return Foos.status(bot, update) return BotsFoos.status(bot, update) if infos.user.message.what != "command": return Elaborator.reader(infos) if infos.user.message.command == "report": return Foos.report(infos) ok = Elaborator.command_reader(infos) if ok != "procedi": return if infos.user.message.pers_command: return Elaborator.pers_commands(infos) except Exception as err: Log.e("Ho trovato un errore: riga %s %s %s" % (sys.exc_info()[-1].tb_lineno, type(err).__name__, err))
def get_main_bot_token(): global _main_bot_token if _main_bot_token != "": return _main_bot_token _main_bot_token = json.loads(open("Files/jsons/config.json").read())["maker_token"] if _main_bot_token == "TOKEN": Log.critical("imposta la token del bot principale in Files/jsons/config.json") exit() bots = get_bots_id() if get_main_bot_id() not in bots: add_bot(get_owner_id(), get_main_bot_id(), _main_bot_token) Log.d("First boot needed to configure, please restart the script.") exit() return _main_bot_token
def getAdmins(chat_id, user_id, from_id): command = False reply = None adminAr = bot.get_chat_administrators(chat_id) adminAr = adminAr["result"] Log.d("Get Group Admins") if adminAr: i = 0 admin = False from_admin = False while admin != True: try: admin_id = str(adminAr[i]["user"]["id"]) if int(user_id) != int(admin_id): i = i + 1 else: admin = True except: admin_id = None break pass while from_admin != True: try: admin_id = str(adminAr[i]["user"]["id"]) if int(from_id) != int(admin_id): i = i + 1 else: from_admin = True except: from_id = None break pass if admin == True: reply = "Sorry... I can't do this to an admin" if from_admin == False: reply = "Only admins can do that!" if admin != True and from_admin != False: command = True else: command = False return reply, command
def command_reader(infos): try: command = infos.user.message.command if infos.is_kitsu: Log.d("I'm Kitsu.") for com in kitsu_commands: if command == com: return kitsu_commands[com](infos) if infos.user.is_master: Log.d("You're master.") for com in master_commands: if command == com: return master_commands[com](infos) if command == "start": return BotsFoos.startb(infos) if infos.user.is_owner: for com in bot_master_comm: if command == com: return bot_master_comm[com](infos) infos.admins.append(Manager.get_owner_id()) if infos.user.uid in infos.admins: for com in bot_commands: if command == com: return bot_commands[com](infos) for com in general_commands: if command == com: return general_commands[com](infos) return "procedi" except Exception as err: Log.e("Ho trovato un errore: riga %s %s %s (%s)" % (sys.exc_info()[-1].tb_lineno, type(err).__name__, err, infos.text)) infos.reply( "C-c'è stato un errore...\nInoltra a @Kaikyu il tuo ultimo messaggio!" )
def attach_bot(token, bid=None, clean=True): if bid: token = Manager.get_token_from_bot_id(bid) if not token: return Log.w("Empty token.") if isinstance(token, list): Log.d("Passed a list, iterating...") for toke in token: attach_bot(toke, clean=clean) Log.d("Finished iterating tokens!") else: if token in BotCache.bots: if BotCache.bots[token]: return Log.w("This bot is already online...") threading.Thread(target=bot_init, args=(token, clean)).start() return True
def delete_bot(bid): bots = json.loads(open("Files/jsons/bots.json").read()) token = get_token_from_bot_id(bid) if not token: Log.d("Token (%s) non trovata!" % token) return False try: del bots[token] except: Log.w("Token non trovata?") return False with open("Files/jsons/bots.json", "w") as fl: fl.write(json.dumps(bots)) Log.d("File bots scritto") return True
def bcast(infos, who): if not infos.user.is_owner: return dialogs = LowLevel.jfile("d", infos.bid, infos.user.lang_n) if "broadcast" not in dialogs: infos.reply("Crea la sezione con \"/add_sezione broadcast\" prima...") return if not dialogs["broadcast"]: infos.reply("Aggiungi le risposte alla sezione \"broadcast\" con \"/add_risposte broadcast | Risposta\" prima!") return Log.d("Broadcast utenti avviato da %s ID %s" % (infos.user.username, infos.user.uid)) try: itms = DBs.get_data(infos.entity, who) n_itms = len(itms) msg_id = infos.reply("Invio 0/%s..." % n_itms)["message_id"] uns = 0 s = 0 for itm in itms: res = Dialoger.send(infos, "broadcast", special_user_name=itm[2], to_id=itm[0], antispam=False, no_log=True) if res == "ERR": uns += 1 else: s += 1 time.sleep(0.05) if (s + uns) % 10 == 0: HTTPLL.editMessageText(infos.token, chat_id=infos.cid, message_id=msg_id, text="Invio %s/%s..." % (s + uns, n_itms)) Dialoger.send(infos, None, special_text="Fatto!\nInviato a %s su %s!" % (s, n_itms)) except Exception as err: Log.w(str(err)) Dialoger.send(infos, "general_error", antispam=False)
def get_chat_photo(toke, chat_id): x = io.BytesIO() res = make_request("getChat", toke, chat_id=chat_id)["result"] try: if "photo" not in res: Log.d("Chat %s probably has no photo" % chat_id) return None file_id = res["photo"]["big_file_id"] if not file_id: Log.d("Non è stato possibile recuperare la propic") return None x = getFile(toke, file_id, out=x) x.seek(0) return x except Exception as err: Log.e( "Non è stato possibile recuperare l'immagine di profilo di %s: %s" % (chat_id, err)) file_id = None return file_id
def elimina_bot(infos): try: if not infos.user.is_owner: return if not Core.is_online(infos.token): Dialoger.send(infos, None, special_text="M-ma io non sono online...") uid = str(infos.user.uid) bid = infos.bid if not infos.text: code = str(random.randint(1000, 9999)) Dialoger.send(infos, None, special_text="Se mi elimini perderai tutti i dati!\n" "Scrivi \"/elimina_bot %s\" se ne sei sicuro..." % code) Unreloaded.set_delete_code(uid, code) return if Unreloaded.get_delete_code(uid) == "": code = str(random.randint(1000, 9999)) Dialoger.send(infos, None, special_text="Non avevo ancora generato il codice, eccolo: %s." % code) Unreloaded.set_delete_code(uid, code) return if infos.text != Unreloaded.get_delete_code(uid): Dialoger.send(infos, None, special_text="Codice sbagliato, era: %s" % Unreloaded.get_delete_code(uid)) return Dialoger.send(infos, None, special_text="Procedo...") Log.d("Elimino il bot %s di %s" % (bid, uid)) Core.detach_bot(infos.token) Manager.delete_bot(bid) Dialoger.send(infos, None, special_text="Addio...") except Exception as err: Log.e(err)
def MayaRun(): update_id = None Log.d("Run Maya") while True: updates = bot.get_updates(offset=update_id) updates = updates["result"] print(updates) print(update_id) if updates: for item in updates: update_id = item["update_id"] try: message = str(item["message"]["text"]) except: message = None from_ = item["message"]["from"]["id"] chat_ = item["message"]["chat"]["id"] first_name_ = item["message"]["from"]["first_name"] try: username_ = item["message"]["from"]["username"] except: username_ = None try: chat_name_ = item["message"]["chat"]["title"] except: chat_name_ = None try: new_chat_member_ = item["message"]["new_chat_participant"] except: new_chat_member_ = None try: gone_chat_member_ = item["message"]["left_chat_member"] except: gone_chat_member_ = None Log.i(from_) Log.i(chat_) if new_chat_member_ is not None: new_chat_member_name_ = item["message"][ "new_chat_participant"]["first_name"] Log.a("welcome") reply = "Welcome " + new_chat_member_name_ + " to " + chat_name_ + " ^^" bot.send_message(reply, chat_) stk = pars.ReadSticker("manomp", "welcome") bot.send_sticker(chat_, stk) if gone_chat_member_ is not None: gone_chat_member_name_ = item["message"][ "left_chat_member"]["first_name"] Log.a("Left") reply = "Goodbye " + gone_chat_member_name_ if from_ == "MayaChan": bot.send_message(reply, chat_) try: reply_to_message_ = item["message"]["reply_to_message"] except: reply_to_message_ = None if reply_to_message_ is not None: reply_to_message_name_ = item["message"][ "reply_to_message"]["from"]["first_name"] reply_id_ = item["message"]["reply_to_message"]["from"][ "id"] reply = repum.reply_to_usermessage(message, first_name_, reply_to_message_name_, chat_, from_, reply_id_) bot.send_message(reply, chat_) if reply_to_message_ is None: if from_ == chat_: reply, parse_mode = trigger.make_reply( message, username_, first_name_) bot.send_message(reply, from_, parse_mode) if from_ != chat_: reply, parse_mode = trigger.make_reply( message, username_, first_name_) bot.send_message(reply, chat_, parse_mode)
from Utils import Logger as Log from LowLevel import LowLevel as LL from Core import Core from Utils import parser import operator import re import time import random import sys import psutil import json startTime = time.time() Log.d("Set start time: " + str(time.strftime("%H:%M:%S", time.gmtime(startTime)))) def PTRun(): maxWeight = Core.setMaxWeight() items = parser.loadItems() VpSM = Core.addMatrixVpS(items) sortMatrix = Core.sortMatrix(VpSM) Core.algo(sortMatrix, maxWeight) Log.d(LL.uptime()) def idle(): while True:
def idle(): while True: Log.d("Run Idle") time.sleep(10)
def newbot(infos): user = infos.user.username uid = infos.user.uid say = infos.reply if uid not in auth: say("Per potermi utilizzare devi effettuare una donazione a PayPal.me/KaikyuDev di 5 euro," "includendo come messaggio il tuo ID, se non sai il tuo ID esegui il comando /myid.\n\n" "I server, così come il tempo, hanno un valore.") return if uid in limits: limit = limits[uid] else: limit = 1 if infos.text == "token": say("Non devi scrivere \"token\", devi darmi la **token** del tuo **bot**.", markdown=True) HTTPLL.sendMessage( infos.token, Manager.get_owner_id(), "@%s ha usato /newbot \"token\" lol" % infos.user.username) return if Manager.get_bot_count() >= max_bots and "!!" not in infos.text: say("Tutti i posti sono stati occupati.\nSegui @KitsuneCode per sapere quando ce ne saranno altri ~" ) return msg = "Nuovo bot da %s (ID: %s)" % (user, uid) if infos.text == "": say("La sintassi del comando è semplice:\n/newbot token\nRiprova...") return Log.a("[Bot: @%s | %s] user: %s ID: %s 'newbot senza chiave'" % (infos.username, infos.bid, user, uid)) key = infos.text.replace("!!", "") if Manager.is_token_used(key): Log.a("[Bot: @%s | %s] user: %s ID: %s 'newbot chiave usata'" % (infos.username, infos.bid, user, uid)) return say("Questa chiave è già usata...") if Manager.count_bots(uid) >= limit: Log.a("[Bot: @%s | %s] user: %s ID: %s 'newbot utente ha già un bot'" % (infos.username, infos.bid, user, uid)) return say( "A quanto pare non puoi fare altri bot ne hai già %s su %s..." % (Manager.count_bots(uid), limit)) if ":" not in key or len(key) != 45: say("%s non credo che questa sia una chiave valida." % user) return Log.a("[Bot: @%s | %s] user: %s ID: %s 'newbot chiave errata'" % (infos.username, infos.bid, user, uid)) try: tbot = HTTPLL.getMe(key) txt = "Eccomi master.\nQuesta è una [guida](%s) sul miofunzionamento.\nUnisciti al [gruppo ufficiale](%s) per avere " \ "le novità in tempo reale." % ("telegra.ph/Come-creare-un-KitsuBot-08-20", "t.me/KitsuBotsGroup") HTTPLL.sendMessage(key, uid, text=txt, parse_mode="markdown") msg += "\nHa usato la token %s\n" % key except Exception as err: Log.d( "L'utente non ha avviato il proprio bot, o c'è qualche problema (%s)" % err) return say("Sicuro di aver avviato il tuo bot in privato?") if Manager.add_bot(uid, tbot["id"], tbot["token"]): say("Registrato con successo!\nTutti i prossimi comandi dovrai eseguirli dal tuo bot: @%s\n" "Il tuo bot è il %sesimo su %s!" % (tbot["username"], Manager.get_bot_count(), max_bots)) else: Log.d("Qualcosa è andato storto...") return say("Qualcosa è andato storto!") msg += "Nome %s\nUsername @%s\nID: %s" % (tbot["first_name"], tbot["username"], tbot["id"]) HTTPLL.sendMessage(infos.token, Manager.get_owner_id(), msg) Core.attach_bot(key)
def replacer(infos, text): try: if "[fm]" in text: if DBs.get_groups_number( infos.bid) < 100 and Manager.trigger_count( infos.bid) < 120: HTTPLL.sendMessage( infos.token, Manager.get_prop_id(infos.token), "Master, non posso ancora usare la funzionalità last.fm..." ) return text = text.replace("[fm]", "") username = infos.user.uid if infos.args: username = infos.args try: fm = LastFM(username) except UnregistredUser: return Dialogs.base_send(infos, "fmnick_missing") except UnvalidUsername: return Dialogs.base_send(infos, "fmnick_invalid") except EmptyTracks: return Dialogs.base_send(infos, "fm_no_result") text = text.replace("+fmnick+", fm.nickname) text = text.replace("+title+", fm.title()) text = text.replace("+artist+", fm.artist()) text = text.replace("+album+", fm.album()) text = text.replace("[img]", "<link>+img_link+:>+zwnj+</link>") text = text.replace("+img_link+", fm.image()) text = text.replace("+action+", fm.np()) lett = "a" if infos.user.sesso == "1" else "o" if infos.name: text = text.replace("+gnome+", infos.name) text = text.replace( "+sesso+", "una ragazza" if infos.user.sesso == "1" else "un ragazzo") if "+anni+" in text or "+giorni+" in text or "+anni_reali+" in text: date_strig = LowLevel.jfile("d", infos.bid, infos.user.lang_n)["data_nascita"] try: d, m, y = map(int, date_strig.split("/")) Log.d("Quindi %s/%s/%s" % (d, m, y)) days = str(timedelta(days=(date.today() - date(y, m, d)).days)).split(" ")[0] years = str(int(int(days) / 365)) age = str(int(int(days) / 30)) text = text.replace("+anni+", age) text = text.replace("+giorni+", days) text = text.replace("+anni_reali+", years) except Exception: HTTPLL.sendMessage( infos.token, infos.prop_id, "master, reimposta la mia data di nascita con /set_nascita GG/MM/AAA..." ) Log.w("%s non è una data di nascita valida..." % date_strig) return None text = text.replace("+zwnj+", zwnj) text = text.replace("+snome+", infos.user.sname) text = text.replace("+username+", infos.user.username) text = text.replace("{?}", lett) text = text.replace("[_]", "\n") text = text.replace("+bcount+", str(infos.bot_count)) text = text.replace("+tcount+", str(Manager.trigger_count(infos.bid))) text = text.replace("+ore+", time.strftime("%H")) text = text.replace("+minuti+", time.strftime("%M")) text = text.replace("+secondi+", time.strftime("%S")) text = text.replace("+nome+", infos.user.name) text = text.replace("+moment+", timemoment()[infos.langn]) text = text.replace("+bnome+", infos.bot_name) text = text.replace("+busername+", infos.username) text = text.replace("+uid+", str(infos.user.uid)) text = text.replace("+gid+", str(infos.cid)) text = text.replace("+bid+", str(infos.bid)) text = text.replace("+kcu+", str(Unreloaded.get_cpu()) + "%") text = text.replace("+kmb+", str(Unreloaded.get_memory())) text = text.replace("+csymb+", infos.symbol) text = text.replace("+is_admin+", "sì" if infos.user.perms.is_admin else "no") text = text.replace("+kbcount+", str(Manager.get_bot_count())) text = text.replace("+trigger_count+", str(Manager.trigger_count(infos.bid))) if "+glink+" in text: if infos.chat_private: text = text.replace("+glink+", "t.me/%s" % infos.user.username) else: try: text = text.replace("+glink+", HTTPLL.getInviteLink(infos)) except Exception: text = text.replace("+glink+", "<non autorizzata>") if infos.user.perms.is_admin: text = text.replace( "+can_mute+", "sì" if infos.user.perms.can_restrict_members else "no") else: text = text.replace("+can_mute+", "no") if "+is_muted+" in text: usr = HTTPLL.getChatMember(infos.token, infos.cid, infos.user.uid)["result"] muted = "no" if "can_send_messages" in usr: if not usr["can_send_messages"]: muted = "si" text = text.replace("+is_muted+", muted) if "+benvenuto+" in text: state = DBs.read_obj(infos.cid, infos.entity, "groups")["ext"] if not state or state == "0": state = "sì" else: state = "no" text = text.replace("+benvenuto+", state) if "cpu%" in text: text = text.replace("cpu", str(psutil.cpu_percent())) if "ram%" in text: text = text.replace("ram", str(psutil.virtual_memory()[2])) if "disk%" in text: text = text.replace("disk", str(psutil.disk_usage('/')[3])) if "+upt+" in text: t = datetime.fromtimestamp( Unreloaded.get_time()).strftime("%d alle %H:%M:%S") text = text.replace("+upt+", t) if infos.to_user and infos.to_user.uid != infos.bid: text = text.replace("+is_admin2+", "sì" if infos.to_user.perms.is_admin else "no") if infos.to_user.perms.is_admin: text = text.replace( "+can_mute2+", "sì" if infos.to_user.perms.can_restrict_members else "no") else: text = text.replace("+can_mute2+", "no") if "+is_muted2+" in text: usr = HTTPLL.getChatMember(infos.token, infos.cid, infos.to_user.uid)["result"] muted = "no" if "can_send_messages" in usr: if not usr["can_send_messages"]: muted = "si" text = text.replace("+is_muted2+", muted) text = text.replace("+snome2+", infos.to_user.sname) text = text.replace("+username2+", infos.to_user.username) text = text.replace("+nome2+", infos.to_user.name) text = text.replace("+uid2+", str(infos.to_user.uid)) lett2 = "a" if infos.to_user.sesso == "1" else "o" text = text.replace("{??}", lett2) if "+nwarns+" in text: try: warns = json.loads( open("Files/bot_files/%s/warns.json" % infos.bid).read())[str(infos.cid)][str( infos.to_user.uid)] except Exception: warns = 0 text = text.replace("+nwarns+", str(warns)) else: if "+nwarns+" in text: try: warns = json.loads( open("Files/bot_files/%s/warns.json" % infos.bid).read())[str(infos.cid)][str( infos.user.uid)] except Exception: warns = 0 text = text.replace("+nwarns+", str(warns)) text = text.replace("+pingt+", LowLevel.get_time(infos.time)) text = text.replace("pingt", LowLevel.get_time(infos.time)) if infos.is_reply: try: if "|" in infos.trigger: for trigger in infos.trigger.split("|"): text = text.replace( "+msg2+", infos.to_user.message.text.replace( str(trigger), "")) elif "&" in infos.trigger: for trigger in infos.trigger.split("&"): text = text.replace( "+msg2+", infos.to_user.message.text.replace( str(trigger), "")) else: msg = re.sub(re.escape(infos.trigger), "", infos.to_user.message.text, flags=re.IGNORECASE) text = text.replace("+msg2+", msg) except: pass try: msg = re.sub(infos.regex, "", infos.text, flags=re.IGNORECASE) if "|" in infos.trigger: for trigger in infos.trigger.split("|"): msg = re.sub(trigger, "", msg, flags=re.IGNORECASE) elif "&" in infos.trigger: for trigger in infos.trigger.split("&"): msg = re.sub(trigger, "", msg, flags=re.IGNORECASE) else: msg = re.sub(re.escape(infos.trigger), "", msg, flags=re.IGNORECASE) msg = msg.strip() text = text.replace("+msg+", msg) text = re.sub(" +", " ", text) text = text.strip() except Exception as err: Log.e("Errore: %s" % err) text = rnd_elab(infos, text) return text except Exception as err: msg = "riga {} {} {}".format(sys.exc_info()[-1].tb_lineno, type(err).__name__, err) Log.e(msg) Dialogs.base_send(infos, "general_error") return None