def _block(self, bot, update):
        message = update.message

        if message.from_user.id != self._admin_id and not is_user_group_admin(bot, message.from_user.id,
                                                                              message.chat_id, self._admin_id):
            message.reply_text(text=self._ADMIN_RESTRICTION_MESSAGE, quote=False)
            return

        if message.reply_to_message is None or message.reply_to_message.sticker is None:
            message.reply_text(text='Команда предназначена только блокирования ХОХЛЯЦКИХ стикерпаков!', quote=False)
            return

        sticker = message.reply_to_message.sticker

        stickerpack, created = BlockedStickerpack.get_or_create(name=sticker.set_name)

        pack_name = stickerpack.name
        pack_link = self._get_stickers_link(pack_name)

        if not created:
            response_text = f'Стикерпак [{pack_name}]({pack_link}) уже заблокирован.'
        else:
            sticker_from = get_username_or_name(message.reply_to_message.from_user)
            who_block = get_username_or_name(message.from_user)

            response_text = f'Ебучий стикерпак [{pack_name}]({pack_link}) успешно заблокирован!\n' \
                            f'Гнусный стикер отправил: {sticker_from} | Заблокировал: лично В.В. ПУТИН'

        message.reply_text(text=response_text, parse_mode=ParseMode.MARKDOWN, quote=False)
Exemple #2
0
    def _display_statistic(self, bot, update):
        message = update.message
        
        if message.chat_id not in (self._chat_id, self._admin_id):
            return

        user, _ = User.get_or_create(user_id=message.from_user.id,
                                     defaults={
                                         'username': get_username_or_name(
                                             message.from_user)})
        
        if not user.user_messages_info.exists():
            bot.sendMessage(chat_id=message.chat_id,
                            reply_to_message_id=message.message_id,
                            text='Ты не писал ещё ничего, алло')
            return
        
        number = user.user_messages_info.get().number
        
        if 11 <= number % 100 <= 14:
            words = 'нужных сообщений'
        elif number % 10 == 1:
            words = 'нужное сообщение'
        elif 2 <= number % 10 <= 4:
            words = 'нужных сообщения'
        else:
            words = 'нужных сообщений'
        
        bot.sendMessage(chat_id=message.chat_id,
                        reply_to_message_id=message.message_id,
                        text='ты написал {0} никому не {1}.'.format(number,
                                                                    words))
Exemple #3
0
    def _update_statistic(self, bot, update):
        message: Message = update.message
        if message.chat_id != self._chat_id:
            return
        
        user, _ = User.get_or_create(user_id=message.from_user.id, defaults={
            'username': get_username_or_name(message.from_user)})

        actual_username = get_username_or_name(message.from_user)
        if user.username != actual_username:
            user.username = actual_username
            user.save()
        
        user_messages_info, _ = UserMessagesInfo \
            .get_or_create(user=user, defaults={'number': 0})
        user_messages_info.number += 1
        user_messages_info.save()
Exemple #4
0
    def _update_last_users(self, bot, update):
        message = update.message
        if message.chat_id != self._chat_id:
            return

        user, _ = User.get_or_create(
            user_id=message.from_user.id,
            defaults={'username': get_username_or_name(message.from_user)})

        LastUsers.delete().where(LastUsers.user == user).execute()

        LastUsers.create(user=user)

        last_ids = [
            row.id for row in LastUsers.select(LastUsers.id).order_by(
                LastUsers.id.desc())
        ]

        if len(last_ids) > self._LAST_USERS_MAX_SIZE:
            border_id = last_ids[self._LAST_USERS_MAX_SIZE - 1]
            LastUsers.delete().where(LastUsers.id < border_id).execute()
Exemple #5
0
    def _kto_zloy(self, bot, update):
        message = update.message

        chat_id = message.chat_id

        if chat_id != self._chat_id:
            return

        if random.randint(1, 10) == 1:
            bot.sendMessage(chat_id=chat_id, text='я люблю Россию! ¯\_(ツ)_/¯')
            return

        last_usernames = [
            row.username
            for row in User.select(User.username).where(User.username != "")
        ]

        random_user = random.choice(last_usernames)

        if random_user == get_username_or_name(message.from_user):
            random_user = '******'
        bot.sendMessage(chat_id=chat_id, text='%s хохол' % random_user)
Exemple #6
0
    def _me(self, bot, update, args):
        message = update.message

        text = "{0} {1}".format(get_username_or_name(message.from_user),
                                ' '.join(args))
        bot.sendMessage(chat_id=self._chat_id, text=text)