-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmstr.py
94 lines (71 loc) · 2.84 KB
/
mstr.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from errbot import BotPlugin, botcmd, arg_botcmd, webhook
class Mstr(BotPlugin):
"""
This plugins allows to interact with a MSTR project
"""
def activate(self):
"""
Triggers on plugin activation
You should delete it if you're not using it to override any default behaviour
"""
super(Mstr, self).activate()
def deactivate(self):
"""
Triggers on plugin deactivation
You should delete it if you're not using it to override any default behaviour
"""
super(Mstr, self).deactivate()
def get_configuration_template(self):
"""
Defines the configuration structure this plugin supports
You should delete it if your plugin doesn't use any configuration like this
"""
return {'EXAMPLE_KEY_1': "Example value",
'EXAMPLE_KEY_2': ["Example", "Value"]
}
def check_configuration(self, configuration):
"""
Triggers when the configuration is checked, shortly before activation
Raise a errbot.utils.ValidationException in case of an error
You should delete it if you're not using it to override any default behaviour
"""
super(Mstr, self).check_configuration(configuration)
def callback_connect(self):
"""
Triggers when bot is connected
You should delete it if you're not using it to override any default behaviour
"""
pass
def callback_message(self, message):
"""
Triggered for every received message that isn't coming from the bot itself
You should delete it if you're not using it to override any default behaviour
"""
self.log.info("I just received a message! %s",message)
self.send(message.frm,message.body)
@webhook
def example_webhook(self, incoming_request):
"""A webhook which simply returns 'Example'"""
return "Example"
# Passing split_args_with=None will cause arguments to be split on any kind
# of whitespace, just like Python's split() does
@botcmd(split_args_with=None)
def example(self, message, args):
"""A command which simply returns 'Example'"""
return "Example"
@arg_botcmd('name', type=str)
@arg_botcmd('--favorite-number', type=int, unpack_args=False)
def hello(self, message, args):
"""
A command which says hello to someone.
If you include --favorite-number, it will also tell you their
favorite number.
"""
self.log.debug("I just received a Hello!")
if args.favorite_number is None:
return "Hello {name}".format(name=args.name)
else:
return "Hello {name}, I hear your favorite number is {number}".format(
name=args.name,
number=args.favorite_number,
)