File: poller_plugin.py

package info (click to toggle)
errbot 6.1.7%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 3,712 kB
  • sloc: python: 13,831; makefile: 164; sh: 97
file content (24 lines) | stat: -rw-r--r-- 762 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from __future__ import absolute_import

from errbot import BotPlugin, botcmd


class PollerPlugin(BotPlugin):
    def delayed_hello(self, frm):
        self.send(frm, "Hello world! was sent 5 seconds ago")

    @botcmd
    def hello(self, msg, args):
        """Say hello to the world."""
        self.start_poller(0.1, self.delayed_hello, times=1, kwargs={"frm": msg.frm})
        return "Hello, world!"

    def delayed_hello_loop(self, frm):
        self.send(frm, "Hello world! was sent 5 seconds ago")
        self.stop_poller(self.delayed_hello_loop, args=(frm,))

    @botcmd
    def hello_loop(self, msg, args):
        """Say hello to the world."""
        self.start_poller(0.1, self.delayed_hello_loop, args=(msg.frm,))
        return "Hello, world!"