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)
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 'Сервер вернул некорректный ответ.'
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'])
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'])
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)
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(('Да', 'Нет'))
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))
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']))
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']))