示例#1
0
def get_empty_bot(infos):
    try:
        infos.reply("Ok, master.")
        d = 0
        w = 0
        wb = 0
        u_bots = "Zero-Trigger bots:"
        bids = Manager.get_bots_id()
        for bid in bids:
            tot = Manager.trigger_count(bid)
            toke = Manager.get_token_from_bot_id(bid)
            if tot < 5:
                if toke not in BotCache.bots:
                    BotCache.bots[toke] = HTTPLL.getMe(toke)

                bot = BotCache.bots[toke]
                u_bots += "\n%s - %s" % (bid, bot["username"])
                Manager.delete_bot(bid)
                d += 1
            elif tot < 20:
                try:
                    HTTPLL.sendMessage(toke, Manager.get_prop_id(toke), "Master, t-ti sei dimenticato di me...?")
                except Exception:
                    wb += 1
                    Manager.delete_bot(bid)
                w += 1
        u_bots += "\n\n%s unactive bots detached.\n%s warns sent to the bot masters but %s of them had blocked their bot." % (d, w, wb)
        infos.reply(u_bots)
    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("M-master... Controlla il log... k-kitsu! ><")
示例#2
0
def mcast(infos):
    unsend = 0
    send = 0
    bids = Manager.get_bots_id()
    tot = len(bids)
    msg = infos.text
    for bid in bids:
        btoken = Manager.get_token_from_bot_id(bid)
        pid = Manager.get_prop_id(btoken)
        try:
            HTTPLL.sendMessage(btoken, pid, msg)
            send += 1
        except Exception:
            Manager.delete_bot(bid)
            unsend += 1

    infos.reply("Inviato a %s su %s (%s avevano bloccato il proprio bot e sono stati eliminati)" % (send, tot, unsend))
示例#3
0
def warn_token(key):
    ids = Manager.get_bot_from_token(key)
    pid = ids["user_id"]
    bid = ids["bot_id"]

    try:
        HTTPLL.sendMessage(
            Manager.get_main_bot_token(), pid,
            "Il tuo bot è stato scollegato per token revokata o invalida,"
            " registra la sua nuova token per tornare ad utilizzarlo!")
    except Exception:
        pass

    if Manager.delete_bot(bid):
        Log.a("Master, ho scollegato il bot di %s per token revocata." % pid)
示例#4
0
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)
示例#5
0
def get_ordered_bots():
    ids = Manager.get_bots_id()
    bot_scores = {}
    bot_usages = {}

    for bid in ids:
        bstats = LowLevel.get_stats_file(bid)
        triggers = LowLevel.jfile("t", bid, 0)
        if not triggers:
            Manager.delete_bot(bid)
            continue

        bot_scores[str(bid)] = 0
        bot_usages[str(bid)] = 0

        for trigger in triggers["equals"]:
            if trigger in bstats:
                bot_scores[str(bid)] += 0.5 * bstats[trigger]
                bot_usages[str(bid)] += 1 * bstats[trigger]

        for trigger in triggers["contents"]:
            if trigger in bstats:
                bot_scores[str(bid)] += 0.2 * bstats[trigger]
                bot_usages[str(bid)] += 1 * bstats[trigger]

        for trigger in triggers["interactions"]:
            if trigger in bstats:
                bot_scores[str(bid)] += 1 * bstats[trigger]
                bot_usages[str(bid)] += 1 * bstats[trigger]

        for trigger in triggers["eteractions"]:
            if trigger in bstats:
                bot_scores[str(bid)] += 1.5 * bstats[trigger]
                bot_usages[str(bid)] += 1 * bstats[trigger]

        for trigger in triggers["admin_actions"]:
            if trigger in bstats:
                bot_scores[str(bid)] -= 2 * bstats[trigger]
                bot_usages[str(bid)] += 1 * bstats[trigger]

        for trigger in triggers["bot_commands"]:
            if trigger in bstats:
                bot_scores[str(bid)] += 0.7 * bstats[trigger]
                bot_usages[str(bid)] += 1 * bstats[trigger]

        for section in [
                "insulti", "complimenti", "bene", "amare", "saluti", "scuse",
                "ringraziamenti"
        ]:
            if section in bstats:
                bot_scores[str(bid)] += 0.7 * bstats[section]
                bot_usages[str(bid)] += 1 * bstats[section]

        for section in [
                "autom_mattina", "autom_pomeriggio", "autom_sera",
                "autom_notte"
        ]:
            if section in bstats:
                bot_scores[str(bid)] += 0.3 * bstats[section]
                bot_usages[str(bid)] += 1 * bstats[section]

        if "gen_answ" in bstats:
            bot_scores[str(bid)] += 0.1 * bstats["gen_answ"]
            bot_usages[str(bid)] += 1 * bstats["gen_answ"]

        if "chiamata" in bstats:
            bot_scores[str(bid)] += 0.7 * bstats["chiamata"]
            bot_usages[str(bid)] += 1 * bstats["chiamata"]

    bot_scores = OrderedDict(
        sorted(bot_scores.items(), key=operator.itemgetter(1), reverse=True))
    return bot_scores, bot_scores, bot_usages