Ejemplo n.º 1
0
 def run_command(self, args):
     time = 60
     if len(args) > 0:
         try:
             time = int(args[0])
         except:
             return '%s is not a valid amount of minutes' % args[0]
     loop = asyncio.get_event_loop()
     loop.create_task(
         temporary_setting_change(self.settings, 'trigger', 0.0, time * 60))
     print('Sleep mode activated!')
     return 'Sleep mode activated for %s minutes.' % time
Ejemplo n.º 2
0
 def run_command(self, args):
     if len(args[0]) > self.settings['tts_max_length']:
         return 'Sorry, too long message! (max length %s characters)' % self.settings['tts_max_length']
     if len(args) > 1:
         lang = args[1]
     else:
         lang = random.choice(self.settings['tts_lang'])
     if not self.settings['tts_cooldown']:
         loop = asyncio.get_event_loop()
         loop.create_task(
             temporary_setting_change(self.settings, 'tts_cooldown', True, self.settings['tts_cooldown_time'])
             )
         return (args[0], 'voice', lang)
     else:
         return 'Sorry, cooling down (-: (text to speak cooldown is %s seconds)' % self.settings['tts_cooldown_time']
Ejemplo n.º 3
0
 async def do_handle(self, msg):
     chat_id = msg['chat']['id']
     reply_to_me = dict_contains_key(
         msg, 'reply_to_message.from.username') and msg['reply_to_message'][
             'from']['username'] == self.settings['name']
     message = self.process_msg(msg)
     if message and not reply_to_me:
         random.shuffle(message)
         messagestr = ' '.join(message)
         voice_possible = len(messagestr) < self.settings[
             'tts_max_length'] and not self.settings['tts_cooldown']
         if voice_possible and random.random() < self.settings['trigger']:
             loop = asyncio.get_event_loop()
             loop.create_task(
                 temporary_setting_change(
                     self.settings, 'tts_cooldown', True,
                     self.settings['tts_cooldown_time']))
             await self.send_voice(chat_id, messagestr)
         else:
             await self.send_message(chat_id, messagestr)
     return True