def stats(infos): t = time.time() if infos.user.uid != Manager.get_owner_id(): return text = "In questo momento sto mantenendo online %s bot.\n" % Core.count_bots() text += "Il tempo di elaborazione di questo messaggio è di %s ms, " % LowLevel.get_time(t) text += "quindi il carico di lavoro è leggero.\n\nFoos version: %s" % ver Dialoger.send(infos, None, special_text=text)
def start(infos): global max_bots if DBs.add_user(infos): txt = "Avviato da %s per la prima volta." % infos.user.username Dialoger.send(infos, "", special_text=txt, to_id=Manager.get_owner_id()) text = "Benvenuto *%s*, se vuoi utilizzarmi esegui il comando /newbot" % infos.user.name infos.reply(text, markdown=True, disable_web_page_preview=True)
def botstats(infos): try: text = "Ecco le <b>statistiche</b>:\n\n" text += "<b>Gruppi</b>: <c>%s</c>\n" % DBs.get_groups_number(infos.bid) text += "<b>Private</b>: <c>%s</c>\n\n" % DBs.get_groups_number(infos.bid, user=True) Dialoger.send(infos, None, special_text=text) except Exception as err: Log.e(err)
def startb(infos): if DBs.add_user(infos): txt = "Avviato da %s per la prima volta!" % infos.user.username Dialoger.send(infos, None, special_text=txt, to_id=infos.prop_id) text = "\n\n_______________________" text += "\n<b>Bot creato con</b> <link>t.me/ChatbotMakerBot:>Syntaxer</link>!" text += "\n<link>t.me/Kaikyu:>Kaikyu Lotus Channel</link>" Dialoger.send(infos, "start", add=text)
def startb(infos): if DBs.add_user(infos): txt = "Avviato da %s per la prima volta!" % infos.user.username Dialoger.send(infos, None, special_text=txt, to_id=infos.prop_id) text = "\n\n_______________________" text += "\n<b>Bot creato con</b> @yukimakerbot_bot" text += "\n <b>Made by</b> <link>t.me/KFrahh:>KFrahh</link>" Dialoger.send(infos, "start", add=text)
def report(infos): try: if not infos.user.is_master: return if infos.text == "": return Dialoger.send(infos, None, to_id=infos.prop_id, special_text="Questo bot è stato reportato da kfrahh per:\n%s" % infos.text) Dialoger.send(infos, None, to_id=Manager.get_owner_id(), special_text="Report inviato, master.", special_token=Manager.get_main_bot_token()) except Exception as err: print(err)
def extractor(infos): if not infos.chat_private: return uid = infos.user.uid if infos.user.uid != Manager.get_owner_id(): if Manager.get_prop_id(infos.token) != uid: return stkid = infos.user.message.item_id thing = infos.user.message.what if thing == "document": try: f_name = HTTPLL.getFileName(infos.token, stkid) if f_name.endswith(".kb"): content = HTTPLL.getFile(infos.token, None, file_path="documents/" + f_name).read().decode("utf-8") success, message = Commands.restore(content, infos.bid, infos.user.lang_n) if success: repl = "Restore riuscito!" else: repl = "Restore fallito: %s" % message return infos.reply(repl) except Exception as err: Log.e("Errore: %s" % err) return msg = "Vuoi aggiungere [%s], master? ~\nInviami il trigger a cui aggiungerlo!\n...*aspetta*" % thing wait_list = json.loads(open("Files/jsons/wait_for.json").read()) if str(uid) in wait_list: x = wait_list[str(uid)] obj = x["thing"] obj_id = x["id"] msg = "Sto ancora aspettando il trigger per:\n%s con ID: %s~" % (obj, obj_id) else: wait_list[str(uid)] = {} wait_list[str(uid)]["thing"] = thing wait_list[str(uid)]["id"] = stkid if infos.user.message.text != "": wait_list[str(uid)]["text"] = infos.user.message.text else: wait_list[str(uid)]["text"] = None with open("Files/jsons/wait_for.json", "w") as fl: fl.write(json.dumps(wait_list)) Dialoger.send(infos, None, special_text=msg)
def status(bot, update): try: g_name = update["message"]["chat"]["title"] gid = update["message"]["chat"]["id"] if "username" in update["message"]["from"]: by = update["message"]["from"]["username"] else: by = "[no username]" byid = update["message"]["from"]["id"] # gid = update["message"]["chat"]["id"] propid = Manager.get_prop_id(bot["token"]) if update["message"]["new_chat_members"]: join_user_name = update["message"]["new_chat_members"][0]['first_name'] # join_user_username = update["message"]["new_chat_members"][0]['username'] join_user_id = update["message"]["new_chat_members"][0]['id'] if join_user_id == bot["id"]: text = "Aggiunta a: %s\nUtente: @%s" % (g_name, by) bpht = HTTPLL.getChatPhoto(bot["token"], gid) if bpht: HTTPLL.sendPhoto(bot["token"], propid, bpht, caption=text) else: HTTPLL.sendMessage(bot["token"], propid, text) Log.a("[Bot: %s | @%s] Aggiunto a %s da %s" % (bot["username"], bot["id"], g_name, byid)) Dialoger.send(Infos(bot, update), "newgroup", special_token=bot["token"]) else: state = DBs.read_obj(gid, bot["id"], "groups")["ext"] if not state or state == "0": Dialoger.send(Infos(bot, update), "welcome", special_name=join_user_name, special_token=bot["token"]) elif update["message"]["left_chat_member"]: left_user_id = update["message"]["left_chat_member"]['id'] if left_user_id == bot["id"]: Log.i("bot quitt") Unreloaded.gbots[str(update["message"]["chat"]["id"])].remove(bot["id"]) HTTPLL.sendMessage(bot["token"], propid, "Rimossa da: %s\nUtente @%s" % (g_name, by)) Log.a("[%s] Rimosso da un gruppo da %s" % (bot["first_name"], by)) except Exception as err: Log.e(err)
def pers_commands(infos): command = infos.user.message.command cont = LowLevel.jfile("t", infos.bid, infos.user.lang_n) # controllo commands if "bot_commands" not in cont: Log.w("BOT ID %s non ha bot_commands!" % infos.entity) return for trigger in cont["bot_commands"]: if "|" in trigger: for part in trigger.split("|"): if re.search("^%s$" % escape(part), command): return Dialoger.send(infos, trigger, antispam=False) else: if re.search("^%s$" % escape(trigger), command): if Unreloaded.antispam(infos): return return Dialoger.send(infos, trigger, antispam=False) if infos.chat_private: return Dialoger.send(infos, "comando sconosciuto", antispam=False)
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 spegni(infos): if not Manager.has_a_bot(infos.user.uid): return if not Core.is_online(infos.token): return if not infos.user.is_owner: return if not infos.text: Dialoger.send(infos, None, special_text="Se mi spegni non potrai più avviarmi fino al riavvio di" " Kitsu!\nScrivi /spegni ok se ne sei sicuro") return if infos.text.lower() != "ok": return Dialoger.send(infos, None, special_text="Scrivi /spegni ok se ne sei sicuro!") try: Dialoger.send(infos, None, special_text="Spegnimento...") Core.detach_bot(infos.token) except Exception as err: Dialoger.send(infos, None, special_text="Si è verificato un errore...\n(%s)" % err)
def reader(i): try: kl = i.text.lower() inter = False if i.chat_private: if i.user.message.what != "text": return BotsFoos.extractor(i) wait_list = json.loads(open("Files/jsons/wait_for.json").read()) if str(i.user.uid) in wait_list: try: if i.text.lower() == "annulla": del wait_list[str(i.user.uid)] with open("Files/jsons/wait_for.json", "w") as fl: fl.write(json.dumps(wait_list)) Dialoger.send(i, None, special_text="Annullato!") return x = wait_list[str(i.user.uid)] obj = x["thing"] cosa = "???" prefix = None if obj == "photo": cosa = "la foto" prefix = "+pht+" if obj == "sticker": cosa = "lo sticker" prefix = "+stk+" if obj == "document": cosa = "il documento" prefix = "+doc+" if obj == "voice": cosa = "la registrazione" prefix = "+voi+" if obj == "audio": cosa = "l'audio" prefix = "+aud+" if obj == "video": cosa = "il video" prefix = "+vid+" if not prefix: return obj_id = x["id"] trigger = i.text.lower() Dialoger.send(i, None, special_text="Aggiungo %s alla sezione %s" % (cosa, trigger)) reply = "%s()%s" % (prefix, obj_id) if x["text"]: reply += "()%s" % x["text"] if LowLevel.add_risposta(i.bid, reply, trigger, i.user.lang_n): risp = "Aggiunto!" del wait_list[str(i.user.uid)] with open("Files/jsons/wait_for.json", "w") as fl: fl.write(json.dumps(wait_list)) else: risp = "C'è qualche problema..." Dialoger.send(i, None, special_text=risp) return except Exception as err: Log.e(err) else: pass DBs.add_group(i) DBs.add_user(i) if re.search("^" + i.regex + "\W*$", kl): return Dialoger.send(i, "chiamata") if (re.search(i.regex + "$", kl) or re.search("^" + i.regex, kl)) or i.chat_private: sezione = interaction(i) inter = True if sezione: return Dialoger.send(i, sezione) if i.is_reply: if i.to_user.uid != i.bid: sezione = risposta(i) if sezione: return Dialoger.send(i, sezione) else: sezione = interaction(i) inter = True if sezione: return Dialoger.send(i, sezione) sezione = checking(i) if sezione: return Dialoger.send(i, sezione) if inter: Dialoger.send(i, "gen_answ") t = "a" if not os.path.isfile("Files/bot_files/%s/gen_answ.txt" % i.bid): t = "w" with open("Files/bot_files/%s/gen_answ.txt" % i.bid, t) as fl: fl.write("@%s: %s \n\n" % (i.user.username, i.text)) if random.randint(0, 750) == 500: return Dialoger.send(i, ("autom_" + timemoment()[0]).lower()) except Exception as err: Log.e(err)
def unkown_command(infos): if not infos.chat_private: return Dialoger.send(infos, None, special_text="Comando sconosciuto, kitsu!") Log.a("Comando sconosciuto")
def triggers(infos): try: # bid = BotListManager.get_botid_from_prop_id(infos.user.uid) dic = LowLevel.get_triggers(infos.bid, "triggers.json" if infos.user.lang_n == 0 else "triggers_eng.json") if not dic: return Dialoger.send(infos, None, special_text="A quanto pare non hai un bot, kitsu...") msg = "Lista dei miei trigger:" msg += "\nContenuti [1]\n" tot = len(dic["contents"]) + len(dic["interactions"]) \ + len(dic["equals"]) + len(dic["admin_actions"]) \ + len(dic["eteractions"]) + len(dic["bot_commands"]) if len(dic["contents"]) != 0: for trig in dic["contents"]: msg += trig + "\n" else: msg += "Vuoto\n" msg += "\nInterazioni [2]\n" if len(dic["interactions"]) != 0: for trig in dic["interactions"]: msg += trig + "\n" else: msg += "Vuoto\n" msg += "\nEguali [3]\n" if len(dic["equals"]) != 0: for trig in dic["equals"]: msg += trig + "\n" else: msg += "Vuoto\n" msg += "\nEterazioni [4]\n" if len(dic["eteractions"]) != 0: for trig in dic["eteractions"]: msg += trig + "\n" else: msg += "Vuoto\n" msg += "\nInterazioni (master) [5]\n" if len(dic["admin_actions"]) != 0: for trig in dic["admin_actions"]: msg += trig + "\n" else: msg += "Vuoto\n" msg += "\nComandi (%s) [6]\n" % Utils.get_com_symbol(infos.entity) if len(dic["bot_commands"]) != 0: for trig in dic["bot_commands"]: msg += trig + "\n" else: msg += "Vuoto\n" if not infos.chat_private: to_id = infos.user.message.id else: to_id = None msg += "\n\nTotale di %s triggers!" % tot HTTPLL.sendMessage(infos.token, infos.cid, text=msg, reply_to_message_id=to_id) except Exception as err: infos.reply("K-kitsu errore!\nErr. n°21: @Kaikyu non sa programmare.\n\n(%s)" % err) Log.e(err)
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)