Ejemplo n.º 1
0
def set_weekly_own_digest(bot, query):
    value = True if query.data.split(":")[1] == "true" else False
    query_db = "UPDATE users SET weekly_own_digest = %s WHERE user_id = %s RETURNING lang"
    extract = database.query_wr(query_db, value, query.from_user.id)
    lang = extract[0][0]
    reply_markup = keyboards.weekly_own_digest_kb(lang, value)
    query.answer()
    try:
        query.message.edit_reply_markup(reply_markup=reply_markup)
    except TelegramError as e:
        if str(e) != "Message is not modified": print(e)
Ejemplo n.º 2
0
def set_private_region(bot, query):
    region = query.data.split(":")[1]
    query_db = "UPDATE users SET region = %s WHERE user_id = %s RETURNING lang"
    extract = database.query_wr(query_db, region, query.from_user.id, one=True)
    lang = extract[0]
    query.answer()
    try:
        query.message.edit_reply_markup(
            reply_markup=keyboards.private_region_kb(lang, region))
    except TelegramError as e:
        if str(e) != "Message is not modified": print(e)
Ejemplo n.º 3
0
def set_adult(bot, query):
    value = query.data.replace("set_adult_", "")
    final_value = True if value == "true" else False
    query_db = "UPDATE supergroups SET nsfw = %s WHERE group_id = %s RETURNING lang"
    extract = database.query_wr(query_db,
                                final_value,
                                query.message.chat.id,
                                one=True)
    lang = extract[0]
    query.answer()
    text = get_lang.get_string(lang, "have_adult")
    reply_markup = keyboards.adult_content_kb(lang, final_value)
    try:
        query.edit_message_text(text=text, reply_markup=reply_markup)
    except TelegramError as e:
        if str(e) != "Message is not modified": print(e)
Ejemplo n.º 4
0
def add_supergroup_db(bot, update):
    query = """INSERT INTO 
    supergroups(group_id, joined_the_bot, last_date) 
    VALUES (%s, %s, %s) 
    ON CONFLICT (group_id) DO 
    UPDATE SET last_date = %s, bot_inside = TRUE 
    WHERE supergroups.group_id = %s
    RETURNING lang"""
    extract = database.query_wr(query,
                                update.message.chat.id,
                                update.message.date,
                                update.message.date,
                                update.message.date,
                                update.message.chat.id,
                                one=True)
    return extract[0]
def ban_group(bot, update, args):
    if len(args) < 3:
        text = "specify id for days\nexample: -34545322 for 30 (optional: for too much spam)"
        update.message.reply_text(text)
        return

    params = " ".join(args).split(" for ")
    group_id = params[0]
    days = int(params[1])
    try:
        reason = params[2]
    except IndexError:
        reason = None
    query = """
        UPDATE supergroups 
        SET 
            banned_on = now(), 
            banned_until = now() + interval '%s days',
            ban_reason = %s 
        WHERE group_id = %s
        RETURNING lang, banned_until
    """

    extract = database.query_wr(query, days, reason, group_id, one=True)
    lang = extract[0]
    banned_until = extract[1]
    shown_reason = html.escape(
        reason) if reason is not None else get_lang.get_string(
            lang, "not_specified")
    shown_reason = "<code>{}</code>".format(shown_reason)
    text = get_lang.get_string(lang, "banned_until_leave").format(
        utils.formatted_datetime_l(banned_until.replace(microsecond=0), lang),
        shown_reason)
    text += utils.text_mention_creator(bot, group_id)
    try:
        bot.send_message(chat_id=group_id, text=text, parse_mode='HTML')
        bot.leaveChat(group_id)
    except Unauthorized as e:
        update.message.reply_text(e.message)

    query = "UPDATE supergroups SET bot_inside = FALSE WHERE group_id = %s"
    database.query_w(query, group_id)
    update.message.reply_text("Done!")
Ejemplo n.º 6
0
def set_vote(bot, query):
    lang = utils.get_db_lang(query.from_user.id)
    vote = query.data.split(":")[1]
    group_id = query.data.split(":")[2]
    if vote == "cancel":
        text = get_lang.get_string(lang, "canceled")
        query.answer(text=text, show_alert=True)
        text = utils.vote_intro(group_id, lang)
        # check if it's need to add the "already_voted"
        query_db = "SELECT vote, vote_date FROM votes WHERE user_id = %s AND group_id = %s"
        extract = database.query_r(query_db,
                                   query.from_user.id,
                                   group_id,
                                   one=True)
        if extract is not None:
            stars = emojis.STAR * extract[0]
            date = utils.formatted_date_l(extract[1].date(), lang)
            text += "\n\n" + get_lang.get_string(lang, "already_voted").format(
                stars, date)
        try:
            query.edit_message_text(text=text,
                                    reply_markup=keyboards.change_vote_kb(
                                        group_id, lang, vote_first_time=True))
        except TelegramError as e:
            if str(e) != "Message is not modified": print(e)
        return
    vote = int(vote)
    alert = ""
    query_db = """
    INSERT INTO votes 
    (user_id, group_id, vote, vote_date) 
    VALUES (%s, %s, %s, now())
    ON CONFLICT DO NOTHING
    RETURNING*
    """
    extract = database.query_wr(query_db,
                                query.from_user.id,
                                group_id,
                                vote,
                                one=True)
    if extract is not None:
        alert = get_lang.get_string(lang, "registered_vote")
    else:
        query_db = """
        UPDATE votes 
        SET 
            vote = %s, 
            vote_date = now() 
        WHERE 
            user_id = %s AND 
            group_id = %s
        """
        database.query_w(query_db, vote, query.from_user.id, group_id)
        alert = get_lang.get_string(lang, "updated_vote")
    query.answer(text=alert, show_alert=True)
    text = "{}\n\n{}\n{}".format(utils.vote_intro(group_id, lang), alert,
                                 emojis.STAR * vote)
    try:
        query.edit_message_text(text=text,
                                reply_markup=keyboards.change_vote_kb(
                                    group_id, lang))
    except TelegramError as e:
        if str(e) != "Message is not modified": print(e)