Exemple #1
0
def top(bot, update):
    update.message.reply_text(get_hashtag_top_list_message(update))
    parallel.send_stats_event(update.message.from_user.id, update.message,
                              "top")
    if SUSPEND_CREATION:
        update.message.reply_text("Tag backup: " + EOF_LINK)
        return
Exemple #2
0
def inline_query(bot, update):
    query_text = update.inline_query.query

    #controlla che la query sia accettabile
    if not is_allowed_string(query_text):
        query_text = ""

    #controlla lunghezza, e taglia se si raggiunge il limite
    if len(query_text) > MAX_HASHTAG_SIZE:
        query_text = query_text[0:MAX_HASHTAG_SIZE]

    results = []

    #crea la query di default con la lista dei tag in top
    if query_text == "":
        top_tags = dbManager.get_top_list()
        for tag in top_tags:
            results.append(make_result_from_db_entry(tag))
    else:
        tags = dbManager.search_partial_tag(query_text)
        for tag in tags:
            results.append(make_result_from_db_entry(tag))

    if query_text == "":
        query_text = "default query"
    print("replied to inline: " + query_text)

    update.inline_query.answer(results)

    parallel.send_stats_event(update.inline_query.from_user.id,
                              update.inline_query, "inline_query")
Exemple #3
0
def mytags(bot, update):

    uid = update.message.from_user.id
    name = update.message.from_user.first_name
    username = update.message.from_user.username
    if username is None:
        username = ""

    print("Preparing mytags data for " + name + " @" + username)

    firebase.send_user_data(uid, name, username,
                            dbManager.get_user_hashtags(uid))

    print(name + " page is ready")
    update.message.reply_text(
        texts.get_text("mytags_message",
                       update.message.from_user.language_code) +
        str(update.message.from_user.id))

    parallel.send_stats_event(update.message.from_user.id, update.message,
                              "mytags")

    if SUSPEND_CREATION:
        update.message.reply_text("Tag backup: " + EOF_LINK)
        return
Exemple #4
0
def report(bot, update):

    if dbManager.is_user_banned(update.message.from_user.id) == True:
        return

    parallel.send_stats_event(update.message.from_user.id, update.message,
                              "report")

    parts = update.message.text.split(" ", 2)

    if len(parts) != 3:
        update.message.reply_text(
            texts.get_text("cmd_report_use",
                           update.message.from_user.language_code))
        return

    tag = check_if_hashtag(parts[1])
    if tag is None:
        update.message.reply_text(
            texts.get_text("cmd_report_use",
                           update.message.from_user.language_code))
        return

    #controlla lunghezza tag
    if len(parts[2]) < 6:
        update.message.reply_text(
            texts.get_text("report_short",
                           update.message.from_user.language_code))
        return

    res = dbManager.add_report(bot, tag, update.message.from_user.id, parts[2])

    if res == 0:
        update.message.reply_text(
            texts.get_text("report_send_success",
                           update.message.from_user.language_code))
        return

    if res == 1:
        update.message.reply_text(
            texts.get_text("report_send_error",
                           update.message.from_user.language_code))
        return

    if res == 2:
        update.message.reply_text(
            texts.get_text("report_no_tag_error",
                           update.message.from_user.language_code))
        return

    if res == 3:
        update.message.reply_text(
            texts.get_text("report_not_allowed",
                           update.message.from_user.language_code))
        return

    if SUSPEND_CREATION:
        update.message.reply_text("Tag backup: " + EOF_LINK)
        return
Exemple #5
0
def edit(bot, update):

    if SUSPEND_CREATION:
        update.message.reply_text(
            texts.get_text("suspend_input",
                           update.message.from_user.language_code) +
            "\nTag backup: " + EOF_LINK)
        return

    if dbManager.is_user_banned(update.message.from_user.id) == True:
        return

    parts = update.message.text.split()

    parallel.send_stats_event(update.message.from_user.id, update.message,
                              "edit")

    if len(parts) != 3:
        update.message.reply_text(
            texts.get_text("cmd_edit_use",
                           update.message.from_user.language_code))
        return

    #controlla i due tag
    old_tag = check_if_hashtag(parts[1])
    new_tag = check_if_hashtag(parts[2])

    if old_tag is None or new_tag is None:
        update.message.reply_text(
            texts.get_text("cmd_edit_use",
                           update.message.from_user.language_code))
        return

    uid = update.message.from_user.id
    #controlla che entrambi gli hashtag siano liberi o del propietario
    if dbManager.can_write_hashtag(old_tag,
                                   uid) == 0 and dbManager.can_write_hashtag(
                                       new_tag, uid) == 0:
        res = dbManager.change_hashtag(old_tag, new_tag)

        if res == 0:
            update.message.reply_text(
                texts.get_text("edit_tag_error",
                               update.message.from_user.language_code))
        else:
            update.message.reply_text(
                texts.get_text("edit_ok",
                               update.message.from_user.language_code).format(
                                   old=old_tag, new=new_tag))

    else:
        update.message.reply_text(
            texts.get_text("edit_perm_error",
                           update.message.from_user.language_code))
Exemple #6
0
def helpme(bot, update):
    if SUSPEND_CREATION:
        update.message.reply_text(
            texts.get_text("suspend_input",
                           update.message.from_user.language_code) +
            "\nTag backup: " + EOF_LINK)
        return

    update.message.reply_text(
        texts.get_text("help_reply", update.message.from_user.language_code))
    parallel.send_stats_event(update.message.from_user.id, update.message,
                              "help")
Exemple #7
0
def claim(bot, update):

    if SUSPEND_CREATION:
        update.message.reply_text(
            texts.get_text("suspend_input",
                           update.message.from_user.language_code) +
            "\nTag backup: " + EOF_LINK)
        return

    if dbManager.is_user_banned(update.message.from_user.id) == True:
        return

    tag = validate_cmd(update.message.text)

    parallel.send_stats_event(update.message.from_user.id, update.message,
                              "claim")

    if tag is None:
        update.message.reply_text(
            texts.get_text("claim_reply",
                           update.message.from_user.language_code))
        return

    #controlla che sia stato quotato un messaggio
    if update.message.reply_to_message is None:
        update.message.reply_text(
            texts.get_text("quote_missing",
                           update.message.from_user.language_code))
        return

    #cerca di creare il tag se possibile
    if dbManager.can_write_hashtag(tag, update.message.from_user.id) == 0:
        data = get_message_data(update.message.reply_to_message)

        #controlla validita dati
        if data is None:
            update.message.reply_text(
                texts.get_text("too_much_chars",
                               update.message.from_user.language_code))
        else:
            dbManager.create_hashtag(tag, update, data, False)
            update.message.reply_text(
                texts.get_text("claim_ok",
                               update.message.from_user.language_code) + tag)

    else:
        update.message.reply_text(
            texts.get_text("claim_error",
                           update.message.from_user.language_code))
Exemple #8
0
def start(bot, update):

    if SUSPEND_CREATION:
        update.message.reply_text(
            texts.get_text("suspend_input",
                           update.message.from_user.language_code) +
            "\nTag backup: " + EOF_LINK)
        return

    update.message.reply_text(
        texts.get_text("welcome_message",
                       update.message.from_user.language_code))
    dbManager.add_chat_to_bcast_list(update.message.chat.id)

    parallel.send_stats_event(update.message.from_user.id, update.message,
                              "start")
Exemple #9
0
def info(bot, update):

    tag = validate_cmd(update.message.text)

    parallel.send_stats_event(update.message.from_user.id, update.message,
                              "info")

    if tag is None:
        update.message.reply_text(
            texts.get_text("cmd_rm_use",
                           update.message.from_user.language_code))
        return

    res = dbManager.get_hashtag_info(tag)

    if res is None:
        update.message.reply_text(
            texts.get_text("not_found",
                           update.message.from_user.language_code))
        return

    #recupera la stringa giusta in base al tipo di tag e formattala di conseguenza
    reply = ""
    if res["reserved"] == True:
        reply = texts.get_text("info_msg_system",
                               update.message.from_user.language_code)
    else:
        reply = texts.get_text("info_msg_user",
                               update.message.from_user.language_code)

    reply = reply.format(
        tag=tag,
        type=res["data"]["type"],
        used=str(res["use_count"]),
        dtc=res["creation_date"].strftime("%d/%m/%y"),
        dte=dbManager.calculate_delta_now(res["last_use_date"]),
        inl=str(res["inline_count"] if "inline_count" in res else 0))

    update.message.reply_text(reply)

    if SUSPEND_CREATION:
        update.message.reply_text("Tag backup: " + EOF_LINK)
        return
Exemple #10
0
def hashtag_message(bot, update):
    tag = check_if_hashtag(find_first_hashtag(update.message.text))

    if tag is None:
        return

    dbManager.add_chat_to_bcast_list(update.message.chat.id)

    result = dbManager.search_hashtag(tag)

    parallel.send_stats_event(update.message.from_user.id, update.message,
                              "message")

    #hash non trovato
    if result["code"] != 0:
        return

    if result["type"] == "text":
        bot.sendMessage(update.message.chat.id, result["reply"])

    if result["type"] == "image":
        bot.sendPhoto(update.message.chat.id, result["reply"])

    if result["type"] == "gif":
        bot.sendDocument(update.message.chat.id, result["reply"])

    if result["type"] == "sticker":
        bot.sendSticker(update.message.chat.id, result["reply"])

    if result["type"] == "audio":
        bot.sendAudio(update.message.chat.id, result["reply"])

    if result["type"] == "voice":
        bot.sendVoice(update.message.chat.id, result["reply"])

    if result["type"] == "video":
        bot.sendVideo(update.message.chat.id, result["reply"])

    if SUSPEND_CREATION:
        update.message.reply_text("Tag backup: " + EOF_LINK)
        return
Exemple #11
0
def remove(bot, update):

    if SUSPEND_CREATION:
        update.message.reply_text(
            texts.get_text("suspend_input",
                           update.message.from_user.language_code) +
            "\nTag backup: " + EOF_LINK)
        return

    tag = validate_cmd(update.message.text)

    parallel.send_stats_event(update.message.from_user.id, update.message,
                              "remove")

    if tag is None:
        update.message.reply_text(
            texts.get_text("cmd_rm_use",
                           update.message.from_user.language_code))
        return

    #controlla se e' possibile rimuovere il tag
    res = dbManager.can_write_hashtag(tag, update.message.from_user.id, True)
    if res == 0:
        #rimuovi il tag
        dbManager.delete_hashtag(tag)
        update.message.reply_text(
            texts.get_text("tag_remove_ok",
                           update.message.from_user.language_code))
    else:
        if res == 3:
            update.message.reply_text(
                texts.get_text("rm_tag_free",
                               update.message.from_user.language_code))
        else:
            update.message.reply_text(
                texts.get_text("tag_not_owned",
                               update.message.from_user.language_code))