Exemplo n.º 1
0
def now_i(self, _, cmd):
    speakers = __tts_selector(self.cfg)
    prov = self.cfg.gts('providertts')
    if speakers is None:
        return Say(F('Не поддерживается для {}', prov))

    if cmd:
        cmd = cmd.lower()
        if prov == 'yandex':
            for key, val in YANDEX_EMOTION.items():
                if cmd == val.lower():
                    return __now_i_set_emo(self, key)
        for key, val in speakers.items():
            if cmd == val.lower():
                return __now_i_set_speaker(self, key, self.cfg[prov], speakers,
                                           prov == 'yandex')
    return Next
Exemplo n.º 2
0
def now_i(self, _, cmd):
    speakers = __tts_selector(self.cfg)
    prov = self.cfg.gts('providertts')
    if speakers is None:
        return Say(LNG['who_now_no_support'].format(prov))

    if cmd:
        if prov == 'yandex':
            for key, val in YANDEX_EMOTION.items():
                if cmd == val:
                    return __now_i_set_emo(self, key)
        cmd = cmd[0].upper() + cmd[1:]
        for key, val in speakers.items():
            if cmd == val:
                return __now_i_set_speaker(self, key, self.cfg[prov], speakers,
                                           prov == 'yandex')
    return Next
Exemplo n.º 3
0
def now_i(self, _, cmd):
    speakers = __tts_selector(self)
    prov = self.cfg['providertts']
    if speakers is None:
        return Say('Не поддерживается для {}'.format(prov))

    if cmd:
        if prov == 'yandex':
            for key, val in utils.YANDEX_EMOTION.items():
                if cmd == val:
                    return __now_i_set_emo(self, key)
        cmd = cmd[0].upper() + cmd[1:]
        for key, val in speakers.items():
            if cmd == val:
                return __now_i_set_speaker(self, key, self.cfg[prov], speakers,
                                           prov == 'yandex')
    return Next
Exemplo n.º 4
0
def counter(_, __, cmd):
    max_count = 20
    data = cmd.lower().split()

    if len(data) == 2 and data[0] == 'до' and utils.is_int(
            data[1]) and int(data[1]) > 1:
        all_num = int(data[1])
        from_ = 1
        to_ = int(data[1])
        inc_ = 1
    elif len(data) == 4 and utils.is_int(data[1]) and utils.is_int(data[3]) \
            and data[0] == 'от' and data[2] == 'до' and abs(int(data[3]) - int(data[1])) > 0:
        all_num = abs(int(data[3]) - int(data[1]))
        from_ = int(data[1])
        to_ = int(data[3])
        inc_ = 1 if from_ < to_ else -1
    else:
        return Next

    if all_num > 500:
        return Say(
            'Это слишком много для меня - считать {} чисел.'.format(all_num))

    numbers = []
    count = 0
    say = []
    while True:
        numbers.append(str(from_))
        count += 1
        if count == max_count:
            say.append(', '.join(numbers))
            count = 0
            numbers = []
        if from_ == to_:
            break
        from_ += inc_

    if len(numbers):
        say.append(', '.join(numbers))
    say.append('Я всё сосчитала')
    return SayLow(phrases=say)
Exemplo n.º 5
0
def counter(_, __, cmd):
    max_count = 20
    data = cmd.lower().split()

    if len(data) == 2 and data[0] == LNG['count_to'] and utils.is_int(
            data[1]) and int(data[1]) > 1:
        all_num = int(data[1])
        from_ = 1
        to_ = int(data[1])
        inc_ = 1
    elif len(data) == 4 and utils.is_int(data[1]) and utils.is_int(data[3]) \
            and data[0] == LNG['count_from'] and data[2] == LNG['count_to'] and abs(int(data[3]) - int(data[1])) > 0:
        all_num = abs(int(data[3]) - int(data[1]))
        from_ = int(data[1])
        to_ = int(data[3])
        inc_ = 1 if from_ < to_ else -1
    else:
        return Next

    if all_num > 500:
        return Say(LNG['count_to_long'].format(all_num))

    numbers = []
    count = 0
    say = []
    while True:
        numbers.append(str(from_))
        count += 1
        if count == max_count:
            say.append(', '.join(numbers))
            count = 0
            numbers = []
        if from_ == to_:
            break
        from_ += inc_

    if len(numbers):
        say.append(', '.join(numbers))
    say.append(LNG['count_complete'])
    return SayLow(phrases=say)
Exemplo n.º 6
0
def help_(self, _, phrase):
    def words():
        triggers = [x[0] for x in self.words_by_f_all(f)]
        if not triggers:
            return ''
        return ', '.join(triggers) or F('любую фразу')

    if phrase:
        phrase = phrase.lower()
        if phrase in self.by_name:
            f = self.by_name[phrase]
            module = self.all[f]
            is_del = '' if module['enable'] else F('. Модуль удален')
            msg = F(
                'Модуль {} доступен в режиме {}. Для активации скажите {}. Модуль предоставляет {} {}'
            )
            say = msg.format(phrase, get_mode_say(module['mode']), words(),
                             module['desc'], is_del)
            return Say(say)
        else:
            return Next

    say, deleted = [], []
    for f, module in self.all.items():
        if module['enable']:
            say.append(
                F('Скажите {}. Это активирует {}. Модуль предоставляет {}',
                  words(), module['name'], module['desc']))
        else:
            deleted.append(module['name'])

    if say:
        say.insert(0, F('Всего доступно {} модулей. Вот они:', len(say)))
    if len(deleted):
        say.append(
            F('Всего {} модулей удалены, это: {}', len(deleted),
              ', '.join(deleted)))
    say.append(F('Работа модуля помощь завершена.'))
    return SayLow(say)
Exemplo n.º 7
0
def manager(self, phrase, mod_name):
    mod_name = mod_name.lower()
    if mod_name not in self.by_name:
        self.log(F('Модуль {} не найден', mod_name), logger.INFO)
        return Next
    mod_ = self.by_name[mod_name]
    if self.all[mod_]['hardcoded']:
        return Say(F('Модуль {} системный, его нельзя настраивать', mod_name))

    modes = {
        F('активировать'): NM,
        F('деактивировать'): DM,
        F('активировать везде'): ANY
    }
    enables = {F('удалить'): False, F('восстановить'): True}
    if phrase in modes:
        if not self.all[mod_]['enable']:
            return Say(
                F('Модуль {} удален. Вначале его нужно восстановить',
                  mod_name))
        new_mode = modes[phrase]
        if self.all[mod_]['mode'] == new_mode:
            return Say(
                F('Модуль {} уже в режиме {}', mod_name,
                  get_mode_say(new_mode)))
        say = F('Теперь модуль {} доступен в режиме {}', mod_name,
                get_mode_say(new_mode))
        return Say(say), Set(mod_mode=[mod_, new_mode])
    elif phrase in enables:
        enable = enables[phrase]
        if self.all[mod_]['enable'] == enable:
            return Say(
                F('Модуль {} и так {}', mod_name, get_enable_say(enable)))
        say = F('Модуль {} {}', mod_name, get_enable_say(enable))
        return Say(say), Set(mod_enable=[mod_, enable])
    else:
        self.log(F('Это невозможно, откуда тут {}', phrase), logger.CRIT)
        return Next
Exemplo n.º 8
0
def this_say(_, __, phrase):
    return Say(phrase) if phrase else None
Exemplo n.º 9
0
def reboot_(*_):
    return Say(
        F('Терминал перезагрузится через 5... 4... 3... 2... 1...')), Set(
            die=[5, True])
Exemplo n.º 10
0
def terminator(_, __, phrase):
    return Say(F('Соответствие фразе не найдено: {}', phrase))
Exemplo n.º 11
0
def terminate_(*_):
    return Say(LNG['term_bye']), Set(die=5)
Exemplo n.º 12
0
def terminate_(*_):
    return Say(F('Come Along With Me.')), Set(die=5)
Exemplo n.º 13
0
 def _mod_callback(self, *_):
     try:
         return Say(random_quotes())
     except RuntimeError as e:
         self.log(e, logger.WARN)
Exemplo n.º 14
0
 def _ga_stop_callback(self, *_):
     self._queue.put_nowait('stop')
     return Say(PHRASES['stop_say'])
Exemplo n.º 15
0
def reboot_(*_):
    return Say(LNG['rbt_bye']), Set(die=[5, True])
Exemplo n.º 16
0
def debug(_, phrase, *__):
    if phrase == LNG['debug_phrase_exit']:
        return Set(debug=False), Say(LNG['debug_say_exit'])
    elif phrase == LNG['debug_phrase_enter']:
        return Set(debug=True), Say(LNG['debug_say_enter'])
    return Next
Exemplo n.º 17
0
def terminator(_, __, phrase):
    return Say(LNG['terminator_say'].format(phrase))