Exemplo n.º 1
0
def read_only(msg):
    if have_args(msg):
        ban_time = parse_time(parse_arg(msg)[1])
    else:
        ban_time = 60
    untildate = msg.date + ban_time
    bot.restrict_chat_member(msg.chat.id,
                             msg.reply_to_message.from_user.id,
                             until_date=untildate)
    ban_datetime = datetime.timedelta(seconds=ban_time)
    ban_time_str = str(ban_datetime).replace('day',
                                             'days').replace('dayss', 'days')
    if ban_datetime.days != 0:
        ban_time_str = ban_time_str.replace(
            ban_time_str.split(',')[0],
            get_text_translation(str(ban_datetime).split(',')[0], 'ru'))
    until_date_human = get_text_translation(
        datetime.datetime.fromtimestamp(untildate).strftime(
            '%A, %d %B %Y, %H:%M'), 'ru')
    bot.send_message(msg.chat.id,
                     text.group_commands['ru']['users']['ro'].format(
                         admin_id=msg.from_user.id,
                         admin_name=api.replacer(msg.from_user.first_name),
                         user_id=msg.reply_to_message.from_user.id,
                         user_name=api.replacer(
                             msg.reply_to_message.from_user.first_name),
                         time_sec=ban_time_str,
                         until_date=until_date_human),
                     parse_mode='HTML',
                     disable_web_page_preview=True)
Exemplo n.º 2
0
def kick_user(msg):
    if check_status(msg.from_user.id, msg.chat.id):
        if msg.reply_to_message:
            bot.kick_chat_member(msg.chat.id,
                                 msg.reply_to_message.from_user.id,
                                 until_date=str(time.time() + 31))
            bot.unban_chat_member(msg.chat.id,
                                  msg.reply_to_message.from_user.id)
            bot.reply_to(
                msg,
                text.group_commands[get_group_lang(
                    msg.chat.id)]['users']['kick'].format(
                        user_name=api.replacer(
                            msg.reply_to_message.from_user.first_name),
                        user_id=msg.reply_to_message.from_user.id,
                        admin_name=api.replacer(msg.from_user.first_name),
                        admin_id=msg.from_user.id),
                parse_mode='HTML')
        else:
            usr = bot.get_chat_member(msg.chat.id, parse_arg(msg)[1])
            bot.kick_chat_member(msg.chat.id,
                                 usr.user.id,
                                 until_date=str(time.time() + 31))
            bot.unban_chat_member(msg.chat.id, usr.user.id)
            bot.reply_to(msg,
                         text.group_commands[get_group_lang(
                             msg.chat.id)]['users']['kick'].format(
                                 user_name=api.replacer(usr.user.first_name),
                                 user_id=usr.user.id,
                                 admin_name=api.replacer(
                                     msg.from_user.first_name),
                                 admin_id=msg.from_user.id),
                         parse_mode='HTML')
    else:
        not_enought_rights(msg)
Exemplo n.º 3
0
def generate_rules_text(msg):
    example = api.get_group_params(msg.chat.id)['rules']['text']
    example = example.format(new_user_id=msg.new_chat_member.id,
                             new_user_firstname=api.replacer(
                                 msg.new_chat_member.first_name),
                             new_user_username=msg.new_chat_member.username,
                             chat_id=msg.chat.id,
                             chat_title=api.replacer(msg.chat.title))
    return example
Exemplo n.º 4
0
def new_warn(msg):
    user_id = msg.reply_to_message.from_user.id
    chat_id = msg.chat.id
    api.new_warn(user_id=user_id, chat_id=chat_id)
    curr = api.get_warns(user_id=user_id, chat_id=chat_id)
    kb = types.InlineKeyboardMarkup()
    kb.add(
        types.InlineKeyboardButton(
            text='Удалить предупреждения',
            callback_data='warns_del::{chat_id}::{user_id}'.format(
                user_id=user_id, chat_id=chat_id)))
    max_warns = int(api.get_group_params(msg.chat.id)['warns']['count'])
    bot.send_message(msg.chat.id,
                     text.group_commands[get_group_lang(
                         msg.chat.id)]['users']['warn'].format(
                             user_id=user_id,
                             user_name=api.replacer(
                                 msg.reply_to_message.from_user.first_name),
                             current_warns=curr,
                             max_warns=max_warns),
                     parse_mode='HTML',
                     reply_markup=kb)
    settings = api.get_group_params(chat_id)['warns']['action']
    if curr >= max_warns:
        if settings == 0:
            pass
        elif settings == 1:
            kick_user_warns(msg, max_warns)
        elif settings == 2:
            ban_user_warns(msg, max_warns)
        elif settings == 3:
            ro_user_warns(msg, max_warns)
        api.zeroing_warns(user_id, chat_id)
Exemplo n.º 5
0
def notify_new_user(user_obj, lang):
    bot.send_message(secret_config.reports_group_id,
                     text.service_messages['new_user'].format(
                         user_id=user_obj.id,
                         user_name=api.replacer(user_obj.first_name),
                         user_amount=api.get_users_count(),
                         user_lang=config.human_langs[lang]),
                     parse_mode='HTML')
Exemplo n.º 6
0
def read_only(msg):
    if have_args(msg):
        ban_time = parse_time(parse_arg(msg)[1])
    else:
        ban_time = 60
    bot.restrict_chat_member(msg.chat.id,
                             msg.reply_to_message.from_user.id,
                             until_date=str(time.time() + ban_time))
    bot.send_message(msg.chat.id,
                     text.group_commands['ru']['users']['ro'].format(
                         admin_id=msg.from_user.id,
                         admin_name=api.replacer(msg.from_user.first_name),
                         user_id=msg.reply_to_message.from_user.id,
                         user_name=api.replacer(
                             msg.reply_to_message.from_user.first_name),
                         time_sec=ban_time),
                     parse_mode='HTML',
                     disable_web_page_preview=True)
Exemplo n.º 7
0
def ro_user_warns(msg, max_warns):
    bot.restrict_chat_member(msg.chat.id,
                             msg.reply_to_message.from_user.id,
                             until_date=str(time.time() + 86400))
    bot.send_message(
        msg.chat.id,
        text.group_commands[get_group_lang(msg)]['users']['ro_warns'].format(
            user_id=msg.reply_to_message.from_user.id,
            user_name=api.replacer(msg.reply_to_message.from_user.first_name),
            count_warns=max_warns),
        parse_mode='HTML')
Exemplo n.º 8
0
def notify_new_chat(chat_obj):
    creator = api.get_creator(chat_obj)
    bot.send_message(secret_config.reports_group_id,
                     text.service_messages['new_chat'].format(
                         chat_name=chat_obj.title,
                         chat_id=chat_obj.id,
                         admin_name=api.replacer(creator.first_name),
                         admin_id=creator.id,
                         chat_users_amount=bot.get_chat_members_count(
                             chat_obj.id),
                         chat_amount=api.get_chats_count()),
                     parse_mode='HTML')
Exemplo n.º 9
0
def unban_user(msg, user_id):
    user = bot.get_chat_member(msg.chat.id, user_id)
    if user.status in ['restricted', 'kicked']:
        bot.restrict_chat_member(msg.chat.id,
                                 user_id,
                                 can_send_media_messages=True,
                                 can_add_web_page_previews=True,
                                 can_send_messages=True,
                                 can_send_other_messages=True)
        bot.send_message(msg.chat.id,
                         text.group_commands[get_group_lang(
                             msg.chat.id)]['users']['unbanned'].format(
                                 user_id=user.user.id,
                                 user_name=api.replacer(user.user.first_name),
                                 admin_id=msg.from_user.id,
                                 admin_name=api.replacer(
                                     msg.from_user.first_name)),
                         parse_mode='HTML')
    else:
        bot.send_message(
            msg.chat.id, text.group_commands[get_group_lang(
                msg.chat.id)]['errors']['not_restricted'])
Exemplo n.º 10
0
def ban_user(msg):
    if check_status(msg.from_user.id, msg.chat.id):
        kb = types.InlineKeyboardMarkup()
        btn = types.InlineKeyboardButton(
            text='Разбанить',
            callback_data='unban::{user_id}'.format(
                user_id=msg.reply_to_message.from_user.id, ))
        kb.add(btn)
        bot.kick_chat_member(msg.chat.id,
                             msg.reply_to_message.from_user.id,
                             until_date=str(time.time() + 31708800))
        bot.reply_to(msg,
                     text.group_commands[get_group_lang(
                         msg.chat.id)]['users']['banned'].format(
                             user_name=api.replacer(
                                 msg.reply_to_message.from_user.first_name),
                             user_id=msg.reply_to_message.from_user.id,
                             admin_name=api.replacer(msg.from_user.first_name),
                             admin_id=msg.from_user.id),
                     reply_markup=kb,
                     parse_mode='HTML')
    else:
        not_enought_rights(msg)