예제 #1
0
파일: models.py 프로젝트: r4nx/bhbot
 def dispatch(self, text: str, context: dict) -> Optional[str]:
     args = text.split(' ')
     if len(args) < 1:
         return get_phrase('EMPTY_CMD')
     try:
         cmd = self.commands[args[0]]
     except KeyError:
         return get_phrase('CMD_NOT_FOUND')
     else:
         context['trigger'] = args[0]
         context['args'] = args[1:]  # Trimming command name
         return cmd(context)
예제 #2
0
    def __call__(self, context: dict) -> str:
        if len(context['args']) < 1:
            return get_phrase('NOT_ENOUGH_ARGUMENTS')

        exp = ' '.join(context['args'])
        try:
            resp = requests.post(INTERPRETER_URL, data={'exp': exp}).json()
        except requests.RequestException:
            logger.exception(
                'Error occured while sending request to Haskell interpreter.')
            return 'Произошла ошибка при отправке запроса.'
        except ValueError:
            return 'Произошла ошибка при декодировании ответа сервера.'
        else:
            success = resp.get('success')
            if success is not None:
                stdout = success.get('stdout')
                output = '\n'.join(line.strip() for line in stdout) if type(
                    stdout) == list else '// No output provided'

                value = success.get('value', '// No value provided')

                return 'Output:\n{}\n\nValue:\n{}'.format(output, value)
            elif 'error' in resp:
                return 'Error:\n{}'.format(resp['error'])
            else:
                return 'Сервер вернул некорректный ответ.'
예제 #3
0
파일: when.py 프로젝트: r4nx/bhbot
    def __call__(self, context: dict) -> str:
        if len(context['args']) < 1:
            return get_phrase('NOT_ENOUGH_ARGUMENTS')

        random.seed(time())
        now = datetime.now()
        return (now + timedelta(days=random.randint(0, 500))).strftime('%d.%m.%Y') + \
            ' ' + ' '.join(context['args'])
예제 #4
0
파일: pseudowho.py 프로젝트: r4nx/bhbot
    def __call__(self, context: dict) -> str:
        if len(context['args']) < 1:
            return get_phrase('NOT_ENOUGH_ARGUMENTS')

        members = {
            'кому': members_dative,
            'кого': members_genetive
        }.get(context['trigger'].lower(), members_nominative)

        random.seed(time())
        return random.choice(members) + ' ' + ' '.join(context['args'])
예제 #5
0
    def __call__(self, context: dict) -> str:
        if len(context['args']) < 1:
            return get_phrase('NOT_ENOUGH_ARGUMENTS')

        text = ' '.join(context['args'])
        variants = [variant.strip() for variant in text.split('или')]
        variants = list(filter(lambda variant: len(variant) > 0, variants))

        if len(variants) < 2:
            return 'Недостаточно вариантов.'

        random.seed(time())
        return random.choice(variants)
예제 #6
0
    def __call__(self, context: dict) -> str:
        if len(context['args']) < 1:
            return get_phrase('NOT_ENOUGH_ARGUMENTS')

        question = ' '.join(context['args'])

        random.seed(time())

        if ' фп ' in (' ' + question):
            return random.choice(
                ('приличные люди такое не спрашивают',
                 'ты че говнарь такое спрашивать', 'не туда воюешь дебил',
                 'слыш ты ахуел', 'мда', 'еблан?'))

        return random.choice(('Да', 'Нет'))
예제 #7
0
파일: pseudolist.py 프로젝트: r4nx/bhbot
    def __call__(self, context: dict) -> str:
        if len(context['args']) < 1:
            return get_phrase('NOT_ENOUGH_ARGUMENTS')
        random.seed(time())
        attempts = 0
        selected = []
        while len(selected) < random.randint(1, min(
                5, len(members))) and attempts < 5:
            member = random.choice(members)
            if member not in selected:
                selected.append(member)
            else:
                attempts += 1

        return 'Список {}:\n{}'.format(' '.join(context['args']),
                                       '\n'.join(selected))
예제 #8
0
파일: evgensim.py 프로젝트: r4nx/bhbot
 def __call__(self, context: dict) -> str:
     if len(context['args']) < 1:
         return get_phrase('NOT_ENOUGH_ARGUMENTS')
     evgen_templates = ['эмм\n{}', '{} как бы']
     random.seed(time())
     return random.choice(evgen_templates).format(' '.join(context['args']))
예제 #9
0
    def __call__(self, context: dict) -> str:
        if len(context['args']) < 1:
            return get_phrase('NOT_ENOUGH_ARGUMENTS')

        random.seed(time())
        return '{:d}% {}'.format(random.randint(0, 100), ' '.join(context['args']))