예제 #1
0
 def __init__(self):
     super(MessageHandler, self).__init__(
         Filters.text | Filters.sticker | Filters.photo,
         self.handle)
     self.data_learner = data_learner
     self.reply_generator = reply_generator
     self.media_checker = media_checker
     self.chance_repository = chance_repository
     self.spam_stickers = config.getlist('bot', 'spam_stickers')
     self.media_checker_messages = config.getlist('media_checker', 'messages')
예제 #2
0
 def __init__(self):
     self.chain_len = config.getint('grammar', 'chain_len')
     self.stop_word = config['grammar']['stop_word']
     self.endsen = config['grammar']['endsen']
     self.garbage = config['grammar']['garbage']
     # https://core.telegram.org/bots/api#messageentity
     self.garbage_entities = config.getlist('grammar', 'garbage_entities')
예제 #3
0
    def __init__(self, chance, message):
        super(Message, self).__init__(message)

        self.chance = chance
        self.entities = message.entities
        self.anchors = config.getlist('bot', 'anchors')

        if self.has_text():
            self.text = message.text
        else:
            self.text = ''
예제 #4
0
class Moderate(Base):
    aliases = ['mod_f', 'mod_d']
    gods = config.getlist('bot', 'god_mode', type=int)

    def execute(self, command):
        try:
            if not command.is_private() and not self.__is_admin(command):
                return self.reply(command, 'You don\'t have admin privileges!')

            if len(command.args) == 0:
                raise IndexError

            if command.name == 'mod_f':
                words = trigram_repository.find_word(command.chat_id,
                                                     command.args[0].strip())
                reply = '\n'.join(words)
                if reply.strip() == '':
                    reply = 'Nothing found'

                self.reply(command, reply)
            elif command.name == 'mod_d':
                trigram_repository.remove_word(command.chat_id,
                                               command.args[0].strip())
        except (IndexError, ValueError):
            self.reply(
                command, """Usage:
/mod_f <similar_word> for search
/mod_d <exact_word> for deletion""")

    def __is_admin(self, entity):
        user_id = entity.message.from_user.id
        admin_ids = list(
            map(lambda m: m.user.id,
                self.bot.get_chat_administrators(entity.chat_id)))

        return user_id in admin_ids \
               or user_id in self.gods