예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
 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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
 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)
예제 #7
0
    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
예제 #8
0
    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())
예제 #9
0
    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())
예제 #10
0
    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
예제 #11
0
    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
예제 #12
0
    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
예제 #13
0
    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)
예제 #14
0
    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)
예제 #15
0
    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)
예제 #16
0
    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)
예제 #17
0
 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)
예제 #18
0
 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)
예제 #19
0
 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)