Ejemplo n.º 1
0
def schedule_own_private_digest(bot, job, data):
    start_in = 0
    for i in data:
        start_in += 0.1
        user = i[0]
        groups = i[1]

        user_id = user[0]
        lang = user[1]
        tot_msg = user[2]
        tot_grps = user[3]
        tot_pos = user[4]
        first_name = user[5]

        text = get_lang.get_string(
            lang, "hello_name").format(name=first_name) + "!\n"
        text += get_lang.get_string(lang, "digest_of_the_week_global").format(
            utils.sep_l(tot_msg, lang), utils.sep_l(tot_grps, lang),
            utils.sep_l(tot_pos, lang))
        reply_markup = keyboards.disable_private_own_weekly_digest_kb(lang)
        # append the text of any group for the same user
        for group in groups:
            title = group[0]
            username = group[1]
            msg_g = group[2]
            pos_g = group[3]
            text += get_lang.get_string(lang,
                                        "digest_of_the_week_detail").format(
                                            utils.sep_l(msg_g, lang), username,
                                            utils.sep_l(pos_g, lang))
        text += "\n#weekly_private_digest"
        # text completed can be scheduled
        job.job_queue.run_once(send_one_by_one,
                               start_in,
                               context=[user_id, text, reply_markup])
Ejemplo n.º 2
0
def group_rank_private(bot, update, args):
    user_id = update.message.from_user.id
    lang = utils.get_db_lang(user_id)
    if len(args) != 1:
        text = get_lang.get_string(lang, "error_param_group_rank_private")
        update.message.reply_text(text, parse_mode="HTML")
        return
    username = args[0]
    if username.startswith("@"):
        username = username.replace("@", "")

    query = "SELECT group_id FROM supergroups_ref WHERE LOWER(username) = LOWER(%s)"
    extract = database.query_r(query, username)

    if len(extract) > 1:
        print("error too many")
        return

    if len(extract) == 0:
        # the group does not exist otherwise anything is returned and if None is NULL
        text = get_lang.get_string(lang, "cant_check_this").format(
            html.escape(username))
        update.message.reply_text(text=text)
        return

    group_id = extract[0][0]
    update.message.reply_text(text=group_rank_text(group_id, lang),
                              parse_mode="HTML")
Ejemplo n.º 3
0
def change_vote_kb(group_id, lang, vote_first_time=False):
    button_back = InlineKeyboardButton(
        text=get_lang.get_string(lang, "change_vote")
        if vote_first_time is False else get_lang.get_string(lang, "vote"),
        callback_data="change_vote:{}".format(group_id))
    buttons_list = [[button_back]]
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
Ejemplo n.º 4
0
def advanced_commands_kb(lang):
    advanced_commands = InlineKeyboardButton(text=get_lang.get_string(
        lang, "advanced_commands"),
                                             callback_data="advanced_commands")
    back = InlineKeyboardButton(text=get_lang.get_string(lang, "back"),
                                callback_data="back_main_private_help")
    buttons_list = [[advanced_commands], [back]]
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
Ejemplo n.º 5
0
def round_seconds(seconds, lang, short=False):
    if seconds < 60:
        return get_lang.get_string(lang, "seconds_ago").format(seconds) if short is False else get_lang.get_string(lang, "seconds_ago_short").format(seconds)
    elif 60 <= seconds < 60*60:
        unit = seconds/60
        r_unit = round(unit)
        return get_lang.get_string(lang, "about_minutes_ago").format(r_unit) if short is False else get_lang.get_string(lang, "about_minutes_ago_short").format(r_unit)
    else:
        unit = seconds/(60*60)
        r_unit = round(unit)
        return get_lang.get_string(lang, "about_hours_ago").format(r_unit) if short is False else get_lang.get_string(lang, "about_hours_ago").format(r_unit)
Ejemplo n.º 6
0
def private_digest_kb(lang):
    button0 = InlineKeyboardButton(text=get_lang.get_string(
        lang, "private_your_own_digest_button"),
                                   callback_data="private_your_own_digest")
    button1 = InlineKeyboardButton(text=get_lang.get_string(
        lang, "private_groups_digest_button"),
                                   callback_data="private_groups_digest")
    button2 = InlineKeyboardButton(text=get_lang.get_string(lang, "back"),
                                   callback_data="main_private_settings")
    buttons_list = [[button0], [button1], [button2]]
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
Ejemplo n.º 7
0
def main_private_settings_kb(lang):
    button0 = InlineKeyboardButton(text=get_lang.get_string(
        lang, "private_lang_button"),
                                   callback_data="private_lang")
    button1 = InlineKeyboardButton(text=get_lang.get_string(
        lang, "private_region_button"),
                                   callback_data="private_region")
    button2 = InlineKeyboardButton(text=get_lang.get_string(
        lang, "private_digest_button"),
                                   callback_data="private_digest_button")
    buttons_list = [[button0], [button1], [button2]]
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
Ejemplo n.º 8
0
def vote(bot, update, args):
    user_id = update.message.from_user.id
    lang = utils.get_db_lang(user_id)
    if len(args) != 1:
        text = get_lang.get_string(lang, "insert_param_vote")
        update.message.reply_text(text, parse_mode="HTML")
        return
    username = args[0]
    if username.startswith("@"):
        username = username.replace("@", "")

    query = """
    SELECT s.group_id, s_ref.username, s_ref.title, v.vote, v.vote_date
    FROM supergroups_ref AS s_ref
    RIGHT JOIN supergroups AS s
    ON s_ref.group_id = s.group_id
    LEFT OUTER JOIN votes AS v 
    ON v.group_id = s.group_id
    AND v.user_id = %s
    WHERE LOWER(s_ref.username) = LOWER(%s) 
        AND s.bot_inside = TRUE
    """

    extract = database.query_r(query, user_id, username)

    if len(extract) == 0:
        # the group does not exist otherwise anything is returned and if None is NULL
        text = get_lang.get_string(lang, "cant_vote_this")
        update.message.reply_text(text=text)
        return

    if len(extract) > 1:
        print("error too many")
        return

    extract = extract[0]
    text = get_lang.get_string(lang, "vote_this_group").format(
        extract[0], extract[1], extract[2])
    if extract[3] and extract[4] is not None:
        stars = emojis.STAR * extract[3]
        date = utils.formatted_date_l(extract[4].date(), lang)
        text += "\n\n" + get_lang.get_string(lang, "already_voted").format(
            stars, date)

    if extract[3] and extract[4] is not None:
        reply_markup = keyboards.change_vote_kb(extract[0], lang)
    else:
        text += "\n\n"
        text += get_lang.get_string(lang, "vote_from_one_to_five")
        reply_markup = keyboards.vote_group_kb(extract[0], lang)
    update.message.reply_text(text=text, reply_markup=reply_markup)
Ejemplo n.º 9
0
def filter_category_button(lang, base, chosen_page):
    category = base.split(":")[4]
    if category != "":
        return [
            InlineKeyboardButton(
                text=get_lang.get_string(lang, 'remove_filter'),
                callback_data=":".join(base.split(":")[:4]).format(page=1) +
                ":")
        ]
    return [
        InlineKeyboardButton(
            text=get_lang.get_string(lang, 'filter_by_category'),
            callback_data='fc:' + base.format(page=chosen_page))
    ]
Ejemplo n.º 10
0
def generic_leaderboard_kb(lang, region):
    members = InlineKeyboardButton(
        text=get_lang.get_string(lang, "by_members"),
        callback_data="leaderboard_by:" + leaderboards.Leaderboard.MEMBERS +
        ":" + region)
    messages = InlineKeyboardButton(
        text=get_lang.get_string(lang, "by_messages"),
        callback_data="leaderboard_by:" + leaderboards.Leaderboard.MESSAGES +
        ":" + region)
    votes = InlineKeyboardButton(text=get_lang.get_string(lang, "by_votes"),
                                 callback_data="leaderboard_by:" +
                                 leaderboards.Leaderboard.VOTES + ":" + region)
    buttons_list = [[members], [messages], [votes]]
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
Ejemplo n.º 11
0
def weekly_own_digest_kb(lang, value):
    yes = get_lang.get_string(lang, "yes")
    no = get_lang.get_string(lang, "no")
    back = get_lang.get_string(lang, "back")
    button_yes = InlineKeyboardButton(
        text=emojis.CURRENT_CHOICE + yes if value is True else yes,
        callback_data="set_weekly_own_digest:true")
    button_no = InlineKeyboardButton(
        text=emojis.CURRENT_CHOICE + no if value is False else no,
        callback_data="set_weekly_own_digest:false")
    button_back = InlineKeyboardButton(text=back,
                                       callback_data="back_private_digest")
    buttons_list = [[button_yes, button_no], [button_back]]
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
Ejemplo n.º 12
0
def filter_by_category_leaderboard_kb(lang, base, back_callback):
    buttons_list = []
    strings = get_lang.get_string(lang, "categories")
    for i in sorted(categories.CODES.items(), key=lambda x: x[1]):
        buttons_list.append(
            InlineKeyboardButton(text=strings[i[1]],
                                 callback_data=base + str(i[0])))
    footer = InlineKeyboardButton(text=get_lang.get_string(lang, "back"),
                                  callback_data=back_callback)
    footer_buttons = [footer]
    buttons_list = build_menu(buttons_list,
                              n_cols=2,
                              footer_buttons=footer_buttons)
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
Ejemplo n.º 13
0
def adult_content_kb(lang, value):
    yes = get_lang.get_string(lang, "yes")
    no = get_lang.get_string(lang, "no")
    back = get_lang.get_string(lang, "back")
    button_yes = InlineKeyboardButton(text=emojis.CURRENT_CHOICE +
                                      yes if value is True else yes,
                                      callback_data="set_adult_true")
    button_no = InlineKeyboardButton(text=emojis.CURRENT_CHOICE +
                                     no if value is False else no,
                                     callback_data="set_adult_false")
    button_back = InlineKeyboardButton(
        text=back, callback_data="main_group_settings_creator")
    buttons_list = [[button_yes, button_no], [button_back]]
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
Ejemplo n.º 14
0
def disable_private_own_weekly_digest_kb(lang):
    disable = InlineKeyboardButton(
        text=get_lang.get_string(lang, "disable"),
        callback_data="private_your_own_digest:new_msg")
    buttons_list = [[disable]]
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
Ejemplo n.º 15
0
def start_no_params(bot, update):
    lang = utils.get_db_lang(update.message.from_user.id)
    text = get_lang.get_string(lang, "help_message")
    reply_markup = keyboards.help_kb(lang)
    update.message.reply_text(text=text,
                              parse_mode="HTML",
                              reply_markup=reply_markup)
Ejemplo n.º 16
0
def vote_link_kb(lang):
    button_back = InlineKeyboardButton(
        text=get_lang.get_string(lang, "back"),
        callback_data="main_group_settings_admin")
    buttons_list = [[button_back]]
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
Ejemplo n.º 17
0
def vote_intro(group_id, lang):
    query = "SELECT username, title FROM supergroups_ref WHERE group_id = %s"
    extract = database.query_r(query, group_id, one=True)
    if extract is None:
        return None
    else:
        return get_lang.get_string(lang, "vote_this_group").format(group_id, extract[0], extract[1])
Ejemplo n.º 18
0
def current_page_admin(bot, query):
    group_id = query.message.chat.id
    query_db = "SELECT lang FROM supergroups WHERE group_id = %s"
    extract = database.query_r(query_db, group_id, one=True)
    lang = extract[0] if extract is not None else None
    query.answer(get_lang.get_string(lang, "already_this_page"),
                 show_alert=True)
Ejemplo n.º 19
0
def feedback_reply_kb(lang):
    reply = InlineKeyboardButton(text=get_lang.get_string(
        lang, "feedback_reply"),
                                 callback_data="feedback_reply")
    buttons_list = [[reply]]
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
Ejemplo n.º 20
0
def language_private(bot, update):
    query = "SELECT lang FROM users WHERE user_id = %s"
    extract = database.query_r(query, update.message.from_user.id, one=True)
    lang = extract[0]
    text = get_lang.get_string(lang, "choose_your_lang")
    reply_markup = keyboards.private_language_kb(lang, back=False)
    update.message.reply_text(text=text, reply_markup=reply_markup)
Ejemplo n.º 21
0
def settings_group(bot, update):
    query_db = "SELECT lang FROM supergroups WHERE group_id = %s"
    lang = database.query_r(query_db, update.message.chat.id, one=True)[0]
    text = get_lang.get_string(lang, "choose_group_lang")
    reply_markup = keyboards.main_group_settings_kb(lang)
    update.message.reply_text(text=text,
                              reply_markup=reply_markup,
                              quote=False)
Ejemplo n.º 22
0
def region(bot, update):
    query = "SELECT lang, region FROM users WHERE user_id = %s"
    extract = database.query_r(query, update.message.from_user.id, one=True)
    lang = extract[0]
    region = extract[1]
    text = get_lang.get_string(lang, "choose_region")
    reply_markup = keyboards.private_region_kb(lang, region)
    update.message.reply_text(text=text, reply_markup=reply_markup)
Ejemplo n.º 23
0
def feedback_reply(bot, query):
    try:
        query.message.edit_reply_markup(reply_markup=None)
    except TelegramError as e:
        if str(e) != "Message is not modified": print(e)
    lang = utils.get_db_lang(query.from_user.id)
    text = get_lang.get_string(lang, "feedback_message")
    bot.sendMessage(chat_id=query.from_user.id, text=text)
Ejemplo n.º 24
0
def group_categories_kb(lang, current_category):
    buttons_list = []
    strings = get_lang.get_string(lang, "categories")
    for i in sorted(categories.CODES.items(), key=lambda x: x[1]):
        buttons_list.append(
            InlineKeyboardButton(
                text=emojis.CURRENT_CHOICE +
                strings[i[1]] if i[0] == current_category else strings[i[1]],
                callback_data="set_group_category:" + str(i[0])))
    footer = InlineKeyboardButton(text=get_lang.get_string(lang, "back"),
                                  callback_data="main_group_settings_creator")
    footer_buttons = [footer]
    buttons_list = build_menu(buttons_list,
                              n_cols=2,
                              footer_buttons=footer_buttons)
    keyboard = InlineKeyboardMarkup(buttons_list)
    return keyboard
Ejemplo n.º 25
0
def leave_banned_group(bot, update):
    query_db = "SELECT lang, banned_until, ban_reason FROM supergroups WHERE group_id = %s"
    extract = database.query_r(query_db, update.message.chat.id, one=True)
    lang = extract[0]
    banned_until = extract[1]
    reason = extract[2]
    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)
    update.message.reply_text(text=text, quote=False, parse_mode='HTML')
    bot.leaveChat(update.message.chat.id)
    query = "UPDATE supergroups SET bot_inside = FALSE WHERE group_id = %s"
    database.query_w(query, update.message.chat.id)
Ejemplo n.º 26
0
def private_digest(bot, query):
    query.answer()
    lang = utils.get_db_lang(query.from_user.id)
    text = get_lang.get_string(lang, "private_digest")
    reply_markup = keyboards.private_digest_kb(lang)
    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.º 27
0
 def wrapped(bot, query, *args, **kwargs):
     if query.message.chat.type == "private":
         return
     if not query.message.chat.get_member(query.from_user.id).status in ["administrator", "creator"]:
         lang = get_db_lang(query.from_user.id)
         text = get_lang.get_string(lang, "button_for_admins")
         query.answer(text=text, show_alert=True)
         return
     return func(bot, query, *args, **kwargs)
Ejemplo n.º 28
0
def remember_to_set_lang(bot, update):
    if not rtsl_is_creator(bot, update):
        return
    if rtsl_already_sent(bot, update):
        return
    lang = None
    text = get_lang.get_string(lang, "hey_no_lang_set")
    reply_markup = keyboards.select_group_lang_kb(lang, back=False)
    update.message.reply_text(text=text, reply_markup=reply_markup)
Ejemplo n.º 29
0
 def wrapped(bot, update, *args, **kwargs):
     if update.message.chat.type == "private":
         lang = get_db_lang(update.effective_user.id)
         text = get_lang.get_string(lang, "this_command_only_creator").format(update.message.text.split(" ")[0])
         update.message.reply_text(text)
         return
     status = update.effective_chat.get_member(update.message.from_user.id).status
     if status not in ["creator"]:
         lang = get_db_lang(update.effective_user.id)
         text = get_lang.get_string(lang, "this_command_only_creator").format(update.message.text.split(" ")[0])
         try:
             chat_id = update.message.from_user.id
             bot.send_message(chat_id=chat_id, text=text)
         except:
             if status in ['administrator']:
                 update.message.reply_text(text)
         return
     return func(bot, update, *args, **kwargs)
Ejemplo n.º 30
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!")