def status(bot, update): try: g_name = update["message"]["chat"]["title"] by = update["message"]["from"]["username"] byid = update["message"]["from"]["id"] gid = update["message"]["chat"]["id"] if update["message"]["new_chat_members"]: join_user_name = update["message"]["new_chat_members"][0]['first_name'] if "username" in update["message"]["new_chat_members"][0]: join_user_username = update["message"]["new_chat_members"][0]['username'] else: join_user_username = join_user_name 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 = None # ToDo Get Propic Method if bpht: HTTPLL.sendPhoto(Manager.get_main_bot_token(), Manager.get_owner_id(), bpht, caption=text) else: HTTPLL.sendMessage(Manager.get_main_bot_token(), Manager.get_owner_id(), text) elif update["message"]["left_chat_member"]: left_user_name = update["message"]["left_chat_member"]['first_name'] left_user_id = update["message"]["left_chat_member"]['id'] if left_user_id == bot["id"]: HTTPLL.sendMessage(Manager.get_main_bot_token(), Manager.get_owner_id(), text="Rimossa da: %s\nUtente @%s" % (g_name, by)) Log.a("[%s] Rimossa da un gruppo da %s" % (bot["first_name"], by)) except Exception as err: Log.e(err) pprint.pprint(update)
def help(infos): try: if infos.user.uid not in auth: return string = "%s [@%s] (%s) ha detto:\n%s" % (infos.user.name, infos.user.username, infos.user.uid, infos.text) HTTPLL.sendMessage(infos.token, Manager.get_owner_id(), string) except Exception as err: HTTPLL.sendMessage(infos.token, Manager.get_owner_id(), str(err))
def send_message(infos): try: args = infos.text.split(" ") HTTPLL.sendMessage(infos.token, args[0], infos.text.replace(args[0], "")) except Exception as err: HTTPLL.sendMessage(infos.token, Manager.get_owner_id(), str(err))
def notice(infos): if infos.text == "": return infos.reply("Cosa dovrei dire...?") infos.text = infos.text.replace("[_]", "\n") HTTPLL.sendMessage(infos.token, Manager.get_owner_id(), infos.text) bids = Manager.get_bots_id() for bid in bids: token = Manager.get_token_from_bot_id(bid) uid = Manager.get_prop_id(token) try: HTTPLL.sendMessage(infos.token, uid, infos.text) except Exception: Log.w("%s notice unauth" % uid) HTTPLL.sendMessage(infos.token, Manager.get_owner_id(), "Avviso importante inviato.")
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 __init__(self, bot, x, message): self.message = Message(message, bot) self.name = x["first_name"] self.username = "" self.sname = "" self.lang = "it" self.uid = int(x["id"]) self.is_to_bot = False self.is_admin = False self.is_owner = True if Manager.get_prop_id( bot["token"]) == self.uid else False if self.uid == Manager.get_owner_id(): self.is_owner = True self.is_master = True if self.uid == Manager.get_owner_id() else False self.sesso = None self.lang_n = 0 if "username" in x: self.username = x["username"] if "last_name" in x: self.sname = x["last_name"] if "language_code" in x: self.lang = str(x["language_code"]).lower() if message["chat"]["type"] == 'private': to_read = "users" else: to_read = "groups" lang = DBs.read_obj(message["chat"]["id"], bot["id"], to_read)["ext2"] if lang: self.lang_n = int(lang) self.perms = Permissions(bot["token"], message["chat"]["id"], self.uid) if message["chat"]["type"] != 'private': self.is_admin = self.perms.is_admin if self.is_master: self.is_admin = True if not self.lang_n: self.lang_n = 0
def run(): httpd = ThreadedHTTPServer(('', port), S) httpd.socket = ssl.wrap_socket(httpd.socket, certfile=certfile, keyfile=ckey, server_side=True) Log.i("Starting server, use <Ctrl-C> to stop") HTTPLL.sendMessage(Manager.get_main_bot_token(), Manager.get_owner_id(), "Avvio concluso.") try: httpd.serve_forever() except Exception as err: print(err) Log.e("Server has stopped, warning.")
def getter(token): if token not in offsets: offsets[token] = 0 while token in BotCache.bots: for update in HTTPLL.getUpdates(token, offsets[token], timeout=120): offsets[token] = update["update_id"] + 1 update_handler(BotCache.bots[token], update) HTTPLL.sendMessage(token, Manager.get_owner_id(), "Bot {} stopped.".format(token))
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)
# coding=utf-8 # Copyright (c) 2018 Kaikyu # 888 d8P d8b 888 .d8888b. 888 # 888 d8P Y8P 888 d88P Y88b 888 # 888 d8P 888 888 888 888 # 888d88K 888 888888 .d8888b 888 888 88888b. .d88b. 888 .d88b. .d88888 .d88b. # 8888888b 888 888 88K 888 888 888 "88b d8P Y8b 888 d88""88b d88" 888 d8P Y8b # 888 Y88b 888 888 "Y8888b. 888 888 888 888 88888888 8888 888 888 888 888 888 888 88888888 # 888 Y88b 888 Y88b. X88 Y88 888 888 888 Y8b. Y88b d88P Y88..88P Y88b 888 Y8b. # 888 Y88b 888 "Y888 88888P' "Y88888 888 888 "Y8888 "Y8888P" "Y88P" "Y88888 "Y8888 from Utils import Logger as Log from Core import ThreadedCore as Core from Core import Manager from Core import HTTPLL if __name__ == "__main__": Log.i("Starting Kitsu, version 3.0.") Core.attach_bot(Manager.get_token_list()) HTTPLL.sendMessage(Manager.get_main_bot_token(), Manager.get_owner_id(), "Booted.") Core.idle()
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)