示例#1
0
def set_main_bot(token, owner__id):
    if Manager.add_bot(owner__id, int(token.split(":")[0]), token):
        attach_bot(token)
示例#2
0
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)