def on_message(self, msg): if not hasattr(msg, 'text'): return False if msg.text.lower() == 'timer start': log.info('Timer started for %s' % msg.chat.id) loop = asyncio.get_event_loop() self._user_ids[msg.chat.id] = loop.create_task(self.ticker(msg.chat.id, 5)) m = sendMessage() m.chat_id = msg.chat.id self._chat_id = msg.chat.id m.text = 'Timer started' yield from self.send_method(m) return True if msg.text.lower() == 'timer stop': log.info('Timer started for %s' % msg.chat.id) if msg.chat.id in self._user_ids: self._user_ids[msg.chat.id].cancel() del self._user_ids[msg.chat.id] m = sendMessage() m.chat_id = msg.chat.id m.text = 'Timer stopped' yield from self.send_method(m) return True
def on_message(self, msg): if not hasattr(msg, 'text'): return False if msg.text.lower() == 'timer start': log.info('Timer started for %s' % msg.chat.id) loop = asyncio.get_event_loop() self._user_ids[msg.chat.id] = loop.create_task( self.ticker(msg.chat.id, 5)) m = sendMessage() m.chat_id = msg.chat.id self._chat_id = msg.chat.id m.text = 'Timer started' yield from self.send_method(m) return True if msg.text.lower() == 'timer stop': log.info('Timer started for %s' % msg.chat.id) if msg.chat.id in self._user_ids: self._user_ids[msg.chat.id].cancel() del self._user_ids[msg.chat.id] m = sendMessage() m.chat_id = msg.chat.id m.text = 'Timer stopped' yield from self.send_method(m) return True
def send_message(self, chat_id, message): # do message send with markdown enabled m = sendMessage() m.chat_id = chat_id m.text = message m.parse_mode = 'Markdown' m.disable_web_page_preview = True res = yield self.send_method(m) defer.returnValue(res)
def test_name(self): m = Float() self.assertEqual('Float', m._name) m = Message() self.assertEqual('Message', m._name) m = sendMessage() self.assertEqual('sendMessage', m._name)
def on_message(self, msg): if isinstance(msg, Message): if msg.text.lower() == 'timer start': self._loop.start(interval=5, now=False) m = sendMessage() m.chat_id = msg.chat.id self._chat_id = msg.chat.id m.text = 'Timer started' yield self.send_message(m) defer.returnValue(True) if msg.text.lower() == 'timer stop': self._loop.stop() m = sendMessage() m.chat_id = msg.chat.id self._chat_id = None m.text = 'Timer stopped' yield self.send_message(m) defer.returnValue(True)
def on_message(self, msg): if hasattr(msg, 'text'): m = sendMessage() m.chat_id = msg.chat.id if msg.text == 'Hello': m.text = 'Hello my name is %s' % os.environ['BOT_NAME'] else: m.text = 'You said: "%s"' % msg.text rsp = yield from self.send_method(m) return True
def test_basic_assign(self): m = sendMessage() m.chat_id = 1234 m.text = 'hello there' self.assertEqual(1234, m.chat_id) self.assertEqual('hello there', m.text) ex = {'chat_id': 1234, 'text': 'hello there'} self.assertEquals(ex, m._to_raw()) m.chat_id = 5678 ex = {'chat_id': 5678, 'text': 'hello there'} self.assertEquals(ex, m._to_raw())
def on_message(self, msg): if hasattr(msg, 'text'): m = sendMessage() m.chat_id = msg.chat.id m.parse_mode = 'Markdown' if msg.text[:5] == '!wolf': response = self.wolf_query(wolf_params(msg.text)) if len(response) > 0: m.text = '\n'.join(filter(None, response)) else: m.text = "I don't have a response to that" yield from self.send_method(m) # if True is returned, other plugins will process the # same message. If False is returned, execution will not continue. return False
def on_message(self, msg): if hasattr(msg, 'text'): m = sendMessage() m.chat_id = msg.chat.id if msg.text == 'Hello': m.text = 'Hello my name is %s' % os.environ['BOT_NAME'] else: m.text = 'You said: "%s"' % msg.text elif hasattr(msg, 'photo'): m = sendPhoto() m.chat_id = msg.chat.id m.caption = "What a pong!" m.photo = msg.photo[0].file_id else: return False rsp = yield from self.send_method(m) return True
def on_message(self, msg): if hasattr(msg, 'text'): m = sendMessage() m.chat_id = msg.chat.id if msg.text == 'Hello': m.text = 'Hello my name is %s' % os.environ['BOT_NAME'] else: m.text = 'You said: "%s"' % msg.text elif hasattr(msg, 'photo'): m = sendPhoto() m.chat_id = msg.chat.id m.caption = "What a pong!" m.photo = msg.photo[0].file_id else: defer.returnValue(True) log.msg("REPLY: %s" % m) rsp = yield self.send_method(m) log.msg("RSP: %s" % rsp) defer.returnValue(True)
def on_message(self, msg): if msg.text: m = sendMessage() m.chat_id = msg.chat.id if msg.text == 'Hello': m.text = 'Hello my name is %s' % os.environ['BOT_NAME'] else: m.text = '"%s"?' % msg.text elif msg.photo: m = sendPhoto() m.chat_id = msg.chat.id m.caption = "What a pong?" m.photo = msg.photo[0].file_id else: return log.msg("REPLY: %s" % m) rsp = yield self.send_message(m) log.msg("RSP: %s" % rsp) defer.returnValue(True)
def on_tick(self, chat_id): log.info('Sending time to %s' % chat_id) m = sendMessage() m.chat_id = chat_id m.text = "Time now is: %s" % datetime.now() yield from self.send_method(m)
def on_tick(self): m = sendMessage() m.chat_id = self._chat_id m.text = "Time now is: %s" % datetime.now() yield self.send_message(m)