Exemple #1
0
def helpall(update, context):
    try:
        idu = update.message.from_user.id
        nicku = update.message.from_user.username
        subject = (nicku or str(idu))
        tryinlinekey = [[
            InlineKeyboardButton(text="Prova la modalità inline!",
                                 switch_inline_query_current_chat="")
        ]]
        helpkeyboard = InlineKeyboardMarkup(tryinlinekey)
        update.message.reply_text(
            "<b>Comandi</b> "
            "\n/start - <i>Mi avvio</i> "
            "\n/help - <i>Invio questa lista</i> "
            "\n/info - <i>Invio varie informazioni sul bot</i> "
            "\n/userid - <i>Se utilizzato rispondendo al messaggio di un utente, mostro la sua nematrice</i> "
            "\n/groupid - <i>Se utilizzato in un gruppo, mostra la nematrice del gruppo</i> "
            "\n/envdht* - <i>Rilevo la temperatura e l'umidità della mia camera da letto</i> "
            "\n<s>/distance* - <i>Elaboro la distanza tra il sensore HC-SR04 e un oggetto qualsiasi</i></s> "
            "\n"
            "\n<b>Trigger</b> "
            "\n<code>I'm Piccione</code> - <i>Risponderò con un meme o con una canzone</i> "
            "\n<code>I f**k your padre</code> - <i>Continuero la citazione di @PadriFibra</i> "
            "\n<code>Kosovo</code> - <i>Risponderò con una canzone, una volta ogni tanto nei gruppi</i> "
            "\n<code>Senate</code> - <i>Se mi va, reclamerò la mia autorità</i> "
            "\n<code>Buonsalve</code> - <i>Ti ricambio il saluto o lo riporto ad altri</i> "
            "\n<code>Bot Pigeon, attivazione</code> - <i>Reagirò con un segnale di avvio</i> "
            "\n"
            "\nI comandi seguiti dall'asterisco sono disponibili solo ai Vassalli (utenti autorizzati da Lord Pigeon). ",
            parse_mode="HTML",
            reply_markup=helpkeyboard,
            quote=True)
        log.a("%s ha usato /help" % subject)
    except Exception as err:
        log.e(err)
Exemple #2
0
def groupid(update, context):
    try:
        idu = update.message.from_user.id
        nicku = update.message.from_user.username
        subject = (nicku or str(idu))
        chatid = update.message.chat.id
        typechat = update.message.chat.type
        if typechat == "group":
            titlechat = update.message.chat.title
            update.message.reply_text("La nematrice del gruppo è: \n`%s`" %
                                      str(chatid),
                                      parse_mode="markdown",
                                      quote=True)
            log.a("%s ha scoperto che la nematrice del gruppo \"%s\" è: %s" %
                  (subject, titlechat, str(chatid)))
        elif typechat == "supergroup":
            titlechat = update.message.chat.title
            update.message.reply_text(
                "La nematrice del supergruppo è: \n`%s`" % str(chatid),
                parse_mode="markdown",
                quote=True)
            log.a(
                "%s ha scoperto che la nematrice del supergruppo \"%s\" è: %s"
                % (subject, titlechat, str(chatid)))
        else:
            update.message.reply_text(
                "Devi essere in un gruppo per usare questo comando. ",
                parse_mode="markdown",
                quote=True)
            log.a(
                "%s ha scoperto che dev'essere in un gruppo per usare /groupid"
                % subject)
    except Exception as err:
        log.e(err)
Exemple #3
0
def helpcom(update, context):
    try:
        typechat = update.message.chat.type
        if typechat == "private":
            helpall(update, context)
        else:
            idu = update.message.from_user.id
            nicku = update.message.from_user.username
            subject = (nicku or str(idu))
            titlechat = update.message.chat.title
            clickhelpkey = [[
                InlineKeyboardButton(
                    text="Clicca qui!",
                    url=f"https://telegram.me/{context.bot.username}?start=help"
                )
            ]]
            helpgroupkeyboard = InlineKeyboardMarkup(clickhelpkey)
            update.message.reply_text(
                "Avviami in chat privata per leggere le istruzioni.",
                parse_mode="markdown",
                reply_markup=helpgroupkeyboard,
                quote=True)
            log.a("%s ha usato /help in %s" % (subject, titlechat))
    except Exception as err:
        log.e(err)
Exemple #4
0
def userid(update, context):
    try:
        idu = update.message.from_user.id
        nicku = update.message.from_user.username
        subject = (nicku or str(idu))
        if update.message.reply_to_message:
            ida = update.message.reply_to_message.from_user.id
            nicka = update.message.reply_to_message.from_user.username
            namea = update.message.reply_to_message.from_user.first_name
            addressee = (nicka or namea)
            msgida = update.message.reply_to_message.message_id
            chatid = update.message.chat.id
            context.bot.send_message(chat_id=chatid,
                                     reply_to_message_id=msgida,
                                     text="Nematrice di %s: \n`%s`" %
                                     (addressee, str(ida)),
                                     parse_mode="markdown")
            log.a("%s ha scoperto che la nm. di %s è %s" %
                  (subject, addressee, str(ida)))
        else:
            update.message.reply_text(
                "Devi rispondere a un messaggio per usare questo comando. ",
                parse_mode="markdown",
                quote=True)
            log.a(
                "%s ha scoperto che deve rispondere a un messaggio per usare /userid"
                % subject)
    except Exception as err:
        log.e(err)
Exemple #5
0
def datawrite(bank, data):
    try:
        with open(f'Databank/{bank}.yaml', "w") as bf:
            newdb = yaml.dump(data, bf)
            log.d(f"Il databank {bank} è stato modificato")
            return newdb
    except Exception as err:
        log.e(err)
Exemple #6
0
def dataread(bank):
    try:
        with open(f"Databank/{bank}.yaml") as bf:
            databank = yaml.safe_load(bf)
            log.d(f"Il databank {bank} è stato letto")
            return databank
    except Exception as err:
        log.e(err)
Exemple #7
0
def tripcode(arcanum, key):
    try:
        hashtripcode = hashlib.sha1(
            str(arcanum).encode("UTF-8")).hexdigest()  # Encrypts the arcanum
        hashtrip = hashtripcode[:int(
            key
        )]  # Takes only the first "key" characters of the encrypted arcanum
        tripcode = str("#" + str(hashtrip)
                       )  # Formats the character in a way similar to tripcodes
        return tripcode
    except Exception as err:
        log.e(err)
Exemple #8
0
def syncmedia(update, context):
    try:
        idu = update.message.from_user.id
        nicku = update.message.from_user.username
        subject = (nicku or str(idu))
        lords = dm.dataread("config")["lords"]
        if idu not in lords:
            update.message.reply_text("Non sei autorizzato.", quote=True)
        else:
            videorickastley = context.bot.send_video(
                chat_id=idu,
                video=open("Media/Inline/RickAstley/VideoRickAstley.mp4",
                           "rb")).video.file_id
            thumbrickastley = context.bot.send_video(
                chat_id=idu,
                video=open("Media/Inline/RickAstley/VideoRickAstley.mp4",
                           "rb")).video.thumb.file_id
            impiccione = context.bot.send_photo(
                chat_id=idu,
                photo=open("Media/Triggers/Impiccione/MemeImpiccione.jpg",
                           "rb")).photo[-1].file_id
            sonounpiccione = context.bot.send_audio(
                chat_id=idu,
                audio=open("Media/Triggers/Impiccione/Sono un piccione.mp3",
                           "rb")).audio.file_id
            kosovo = context.bot.send_voice(
                chat_id=idu,
                voice=open("Media/Triggers/Kosovo/PositivoKosovo.ogg",
                           "rb")).voice.file_id
            senate = context.bot.send_voice(
                chat_id=idu,
                voice=open("Media/Triggers/Senate/PositivoSenate.ogg",
                           "rb")).voice.file_id
            newmedia = {
                "Inline": {
                    "VideoRickAstley": videorickastley,
                    "ThumbRickAstley": thumbrickastley
                },
                "Triggers": {
                    "Impiccione": impiccione,
                    "Sonounpiccione": sonounpiccione,
                    "Kosovo": kosovo,
                    "Senate": senate
                }
            }
            dm.datawrite("media", newmedia)
            log.d(f"{subject} ha aggiornato i media")
    except Exception as err:
        log.e(err)
Exemple #9
0
def inlinelog(update, context):
    try:
        idu = update.chosen_inline_result.from_user.id
        nicku = update.chosen_inline_result.from_user.username
        subject = (nicku or str(idu))
        query = update.chosen_inline_result.query
        loot = update.chosen_inline_result.result_id
        if not query:
            quest = str("")
        else:
            quest = str(": " + str(query))
        journal = str(str(loot) + quest)
        log.a("%s ha scelto inline %s" % (subject, journal))
    except Exception as err:
        log.e(err)
Exemple #10
0
def debase(update, context):
    try:
        idu = update.message.from_user.id
        nicku = update.message.from_user.username
        subject = (nicku or str(idu))
        lords = (dm.dataread("config"))["lords"]
        if idu not in lords:
            update.message.reply_text("Non sei autorizzato.", quote=True)
        elif len(context.args) == 0:
            if update.message.reply_to_message:
                ida = update.message.reply_to_message.from_user.id
                nicka = update.message.reply_to_message.from_user.username
                namea = update.message.reply_to_message.from_user.first_name
                addressee = (nicka or namea)
                msgida = update.message.reply_to_message.message_id
                chatid = update.message.chat.id
                vassals = (dm.dataread("vassals"))["vassals"]
                vassals = list(dict.fromkeys(vassals))
                vassals.remove(ida)
                vassals = list(dict.fromkeys(vassals))
                newdb = {"vassals": vassals}
                dm.datawrite("vassals", newdb)
                context.bot.send_message(
                    chat_id=chatid,
                    reply_to_message_id=msgida,
                    text="%s adesso non è più un Vassallo." % addressee,
                    parse_mode="markdown")
                log.a("%s ha degradato %s, nm.: %s" %
                      (subject, addressee, str(ida)))
            else:
                update.message.reply_text("Devi rispondere a un messaggio.",
                                          quote=True)
        else:
            listids = [int(i) for i in context.args]
            vassals = (dm.dataread("vassals"))["vassals"]
            vassals = list(dict.fromkeys(vassals))
            for ids in listids:
                vassals.remove(ids)
            vassals = list(dict.fromkeys(vassals))
            newdb = {"vassals": vassals}
            dm.datawrite("vassals", newdb)
            update.message.reply_text(
                "L'utente nm. %s ora non fa più parte dei Vassalli." %
                str(context.args),
                quote=True)
            log.a("%s ha degradato %s" % (subject, str(context.args)))
    except Exception as err:
        log.e(err)
Exemple #11
0
def start(update, context):
    try:
        if len(context.args) == 0:
            idu = update.message.from_user.id
            nicku = update.message.from_user.username
            subject = (nicku or str(idu))
            nameu = update.message.from_user.first_name
            update.message.reply_text(
                "Ciao, %s, io sono il bot personale di @LordPigeon! \nDigita /help per una guida."
                % (nicku or nameu),
                parse_mode="markdown",
                quote=True)
            log.a("%s ha usato /start" % subject)
        elif "help" in context.args:
            helpall(update, context)
        elif "helpinline" in context.args:
            helpinline(update, context)
        elif "info" in context.args:
            info(update, context)
    except Exception as err:
        log.e(err)
Exemple #12
0
def caesarcode(arcanum, taxon):
    try:
        if taxon == "number":
            quadruarcanum = int(round(float(float(arcanum) / 4), 4) * 10**4)
            caesarcode = ""
            for i in range(len(str(quadruarcanum))):
                dig = int(str(quadruarcanum)[i])
                caesarcode += chr((dig - 97) % 26 + 97)
            return caesarcode
        elif taxon == "word":
            caesarcode = ""
            for i in range(len(arcanum)):
                char = arcanum[i]
                if (char.isupper()):
                    caesarcode += chr((ord(char) + len(arcanum) - 65) % 26 +
                                      65)
                else:
                    caesarcode += chr((ord(char) + len(arcanum) - 97) % 26 +
                                      97)
            return caesarcode
    except Exception as err:
        log.e(err)
Exemple #13
0
def welcome(update, context):
    try:
        titlechat = update.message.chat.title
        if update.message.new_chat_members[-1].id == context.bot.id:
            idu = update.message.from_user.id
            nicku = update.message.from_user.username
            subject = (nicku or str(idu))
            nameu = update.message.from_user.first_name
            update.message.reply_text("Grazie per avermi aggiunto, %s!" %
                                      (nicku or nameu),
                                      quote=True)
            log.i("%s mi ha aggiunto a %s" % (subject, titlechat))
        else:
            idc = update.message.new_chat_members[-1].id
            nickc = update.message.new_chat_members[-1].username
            client = (nickc or str(idc))
            namec = update.message.new_chat_members[-1].first_name
            update.message.reply_text("Buonsalve e benvenuto/a, %s!" %
                                      (nickc or namec),
                                      quote=True)
            log.i("Ho dato il benvenuto a %s in %s" % (client, titlechat))
    except Exception as err:
        log.e(err)
Exemple #14
0
def info(update, context):
    try:
        idu = update.message.from_user.id
        nicku = update.message.from_user.username
        subject = (nicku or str(idu))
        typechat = update.message.chat.type
        if typechat == "private":
            update.message.reply_text(
                "Io sono il bot personale di @LordPigeon e "
                "sono stato programmato in Python grazie all'aiuto di vari amici: "
                "\n• @Kaikyu "
                "\n• @canebrutto "
                "\n• @i7_8700k "
                "\n• @hugihadein \n"
                '\nFunziono su di un Raspberry Pi 3 Model B grazie a <a href="https://python-telegram-bot.org/">python-telegram-bot</a> e '
                'a <a href="https://github.com/KaikyuLotus/kitsu-maker-bot/blob/master/Utils/Logger.py">un logger di Kaikyu</a>. ',
                parse_mode="HTML",
                disable_web_page_preview=True,
                quote=True)
            log.a("%s ha usato /info" % subject)
        else:
            titlechat = update.message.chat.title
            clickinfokey = [[
                InlineKeyboardButton(
                    text="Clicca qui!",
                    url=f"https://telegram.me/{context.bot.username}?start=info"
                )
            ]]
            infogroupkeyboard = InlineKeyboardMarkup(clickinfokey)
            update.message.reply_text(
                "Avviami in chat privata per leggere più informazioni su di me.",
                parse_mode="markdown",
                reply_markup=infogroupkeyboard,
                quote=True)
            log.a("%s ha usato /info in %s" % (subject, titlechat))
    except Exception as err:
        log.e(err)
Exemple #15
0
def helpinline(update, context):
    try:
        idu = update.message.from_user.id
        nicku = update.message.from_user.username
        subject = (nicku or str(idu))
        trymekey = [[
            InlineKeyboardButton(text="Provami!", switch_inline_query="")
        ]]
        helpinlinekeyboard = InlineKeyboardMarkup(trymekey)
        update.message.reply_text(
            "*Lista delle funzioni inline*: "
            "\n1) `You know the rules and so do I` - _Per un triste addio a un picciotto disobbediente._ "
            "\n2) `Meteo` - _Scrivi il nome di una località e clicca per vederne le previsioni metereologiche._ "
            "\n3) `Formatta in HTMl` - _Scrivi un testo con tag HTML che siano compatibili con Telegram per vedere il risultato._ "
            "\n4) `Formatta in maiuscolo` - _Utile se vuoi ottenere rapidamente lettere accentate maiuscole da PC._ "
            "\n5) `Tripcode` - _Scrivi un messaggio e alla fine inserisci una #password (che inizi con l'hashtag) e il bot cripterà la tua password, utile nei gruppi anonimi._ "
            "\n"
            "\nEvita di usare il cancelletto (#) alla fine se vuoi usare le prime quattro funzioni.",
            parse_mode="markdown",
            reply_markup=helpinlinekeyboard,
            quote=True)
        log.a("%s ha usato /start helpinline" % subject)
    except Exception as err:
        log.e(err)
Exemple #16
0
def inlineresults(update, context):
    try:
        query = update.inline_query.query
        if not query:
            wtrquest = "New York"
            formatquest = "Nessun testo trovato, riprovare."
        else:
            wtrquest = str((re.compile(r'<[^>]+>')).sub("", query))
            formatquest = query
        results = [
            InlineQueryResultVideo(
                id="RickAstley",
                title="You know the rules and so do I",
                mime_type="video/mp4",
                video_url=dm.dataread("media")["Inline"]["VideoRickAstley"],
                thumb_url=dm.dataread("media")["Inline"]["ThumbRickAstley"]),
            InlineQueryResultPhoto(
                id="Meteo",
                title="Meteo di %s" % wtrquest,
                photo_url=str("https://wttr.in/" + wtrquest.replace(" ", "+") +
                              "_lang=it.png?v=1"),
                thumb_url=str("https://wttr.in/" + wtrquest.replace(" ", "+") +
                              "_0pq_lang=it.png?v=1")),
            InlineQueryResultArticle(
                id="FormatHTML",
                title="Formatta in HTML",
                input_message_content=InputTextMessageContent(
                    formatquest, parse_mode="HTML")),
            InlineQueryResultArticle(
                id="FormatUp",
                title="Formatta in maiuscolo",
                input_message_content=InputTextMessageContent(
                    formatquest.upper()))
        ]
        if not query:
            pass
        elif re.search(r'<[^>]+>', query):
            results.clear()
            results.append(
                InlineQueryResultArticle(
                    id="FormatHTML",
                    title="Formatta in HTML",
                    input_message_content=InputTextMessageContent(
                        query, parse_mode="HTML")))
        elif bool(re.match("#", query.split()[-1])) == False:
            pass
        else:
            results.clear()
            questlist = query.split()  # Divides the query into a list
            txtmsg = questlist[:-1]  # Takes the message before the hashtag
            upass = questlist[-1][1:]  # Takes the password after the hashtag
            txtmsg.append(tripcode(
                upass, 8))  # Appends the encrypted password to the message
            cryptmsg = " ".join(txtmsg)  # Joins the final list into a string
            results.append(
                InlineQueryResultArticle(
                    id="Tripcode",
                    title="Tripcode",
                    input_message_content=InputTextMessageContent(cryptmsg)))
        update.inline_query.answer(
            results,
            cache_time=4,
            switch_pm_text="Leggi le istruzioni in chat privata",
            switch_pm_parameter="helpinline")
    except Exception as err:
        log.e(err)
Exemple #17
0
def triggers(update, context):
    try:
        idu = update.message.from_user.id
        nicku = update.message.from_user.username
        subject = (nicku or str(idu))
        nameu = update.message.from_user.first_name
        chatid = update.message.chat.id
        content = update.message.text
        cont = content.lower()
        gasha = [0, 0, 0, "pon"]
        
        if content == "Salve" and idu == 254166588:
            update.message.reply_text("e sane")
            log.a("Per Matteo Socrati le ragazze sono salve, ma per me sono pure sane")
            return
        
        if "Prova" in content and random.choice(gasha) == "pon":
            update.message.reply_text("Funziona!", quote = True)
            log.a("%s ha provato!"%subject)
            return
        
        regex = "i'+m p+i+c+c+i+o+n+e"
        if re.search(regex, cont):
            try:
                impiccione = dm.dataread("media")["Triggers"]["Impiccione"]
                meridiana = dm.dataread("media")["Triggers"]["Sonounpiccione"]
                ambiguity = [0, "0"]
                if random.choice(ambiguity) == 0:
                    update.message.reply_photo(photo = impiccione,
                        quote = True)
                    log.a("%s è un imPiccione"%subject)
                    return
                else:
                    update.message.reply_audio(audio = meridiana,
                        quote = True)
                    log.a("%s è un Piccione"%subject)
                    return
            except Exception as err:
                log.e(err)
        
        regex = "i f+u+c+k y+o+u+r p+a+d+r+e"
        if re.search(regex, cont):
            try:
                if update.message.reply_to_message:
                    ida = update.message.reply_to_message.from_user.id
                    nicka = update.message.reply_to_message.from_user.username
                    addressee = (nicka or str(ida))
                    msgida = update.message.reply_to_message.message_id
                    chatid = update.message.chat.id
                    context.bot.send_message(chat_id = chatid,
                        reply_to_message_id = msgida,
                        text = "He's my puttana ",
                        parse_mode = "markdown")
                    log.a("%s si fa il padre di %s"%(subject, addressee))
                    return
                else:
                    update.message.reply_text("He's my puttana ",
                        parse_mode = "markdown",
                        quote = True)
                    log.a("%s segue PadriFibra"%subject)
                    return
            except Exception as err:
                log.e(err)
        
        regex = "k+o+s+o+v+o"
        if re.search(regex, cont):
            try:
                typechat = update.message.chat.type
                kosovo = dm.dataread("media")["Triggers"]["Kosovo"]
                if typechat == "private":
                    update.message.reply_voice(kosovo,
                        caption = "Stay tuned, @PadriFibra!",
                        quote = True)
                    log.a("%s ha lodato il Kosovo"%subject)
                    return
                else:
                    if random.choice(gasha) == 0:
                        titlechat = update.message.chat.title
                        log.a("%s non ha lodato abbastanza il Kosovo in %s"%(subject, titlechat))
                    elif random.choice(gasha) == "pon":
                        update.message.reply_voice(kosovo,
                            caption = "Stay tuned, @PadriFibra!",
                            quote = True)
                        log.a("%s ha lodato il Kosovo"%subject)
                    return
            except Exception as err:
                log.e(err)
        
        regex = "s+e+n+a+t+e"
        if re.search(regex, cont):
            try:
                if random.choice(gasha) == "pon":
                    senate = dm.dataread("media")["Triggers"]["Senate"]
                    update.message.reply_voice(senate,
                        caption = '<i>I am the <a href="https://t.me/ErarioPiccioni">Senate</a>!</i>',
                        parse_mode = "HTML",
                        quote = True)
                    log.a("I am the Senate, not %s"%subject)
                    return
                else:
                    return
            except Exception as err:
                log.e(err)
        
        regex = "b+u+o+n+s+a+l+v+e"
        if re.search(regex, cont):
            try:
                if update.message.reply_to_message:
                    ida = update.message.reply_to_message.from_user.id
                    nicka = update.message.reply_to_message.from_user.username
                    addressee = (nicka or (str(ida)))
                    chatid = update.message.chat.id
                    msgida = update.message.reply_to_message.message_id
                    namea = update.message.reply_to_message.from_user.first_name
                    context.bot.sendMessage(text = "Buonsalve, %s"%(nicka or namea),
                        chat_id = chatid,
                        reply_to_message_id = msgida,
                        quote = True)
                    log.a("%s ha salutato %s"%(subject, addressee))
                    return
                else:
                    update.message.reply_text("Buonsalve, %s!"%(nicku or nameu),
                        quote = True)
                    log.a("Ho ricambiato il saluto a %s"%subject)
                    return
            except Exception as err:
                log.e(err)
        
        regex = "b+o+t p+i+g+e+o+n, a+t+t+i+v+a+z+i+o+n+e"
        if re.search(regex, cont):
            try:
                update.message.reply_text("Bot Pigeon, attivato!",
                    quote = True)
                log.a("%s ha attivato il bot!"%subject)
                return
            except Exception as err:
                log.e(err)
        
    except Exception as err:
        log.e(err)