-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_plugin.py
68 lines (56 loc) · 2.34 KB
/
example_plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
An example of a simple plugin which showcases all the basic API.
"""
from orgassist import log
from orgassist.assistant import Assistant, AssistantPlugin
@Assistant.plugin('owa')
class OwaPlugin(AssistantPlugin):
"""
An example of a simple orgassist plugin.
"""
def validate_config(self):
"""
Called first: Use this method to read config parameters and substitute
defaults were appropriate.
You should touch all your config variables here so we can inform the
user if he have mistyped something in the config file (even when --test
parameter is given)
Available API: self.config, self.assistant, self.scheduler.
self.state might not be fully populated and ready yet.
"""
log.info("1. Validate and read config")
self.parameter = self.config.get('parameter',
assert_type=int,
default=42)
def register(self):
"""
Called second: Use this method to register any commands/callbacks via the
self.assistant API.
"""
log.info("2. Register plugin commands")
# You can register some commands here
commands = [
(['owa_refresh'], self.handle_refresh),
]
for aliases, callback in commands:
self.assistant.command.register(aliases, callback)
def initialize(self):
"""
Called third, after all plugins are registered. Use it to initialize the
plugin.
It's a good place to register periodic callbacks using self.scheduler.
You can also use other plugins public API via the self.state object.
"""
log.info("3. Initialize the plugin")
# There might be some operation you need to do periodically:
self.scheduler.every(30).seconds.do(self.periodic)
def handle_refresh(self, message):
"Example: Command executed"
reply = "You (%s) have sent: %s (parameter: %d)" % (message.sender, message.text,
self.parameter)
message.respond(reply)
def periodic(self):
"Example: Periodic operations"
log.info("Periodic operation executed")
# Use shared state to talk to core plugins
self.state['calendar'].add_events([], 'owa')