-
Notifications
You must be signed in to change notification settings - Fork 4
/
foorl.py
executable file
·69 lines (58 loc) · 1.96 KB
/
foorl.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
#!/usr/bin/python3
from hub import HubBot
from sleekxmpp.exceptions import IqError
from sleekxmpp.xmlstream import ET
import subprocess
import re
import logging
import foomodules
class Foorl(HubBot):
def __init__(self, config_module_name, config_module_path=None):
self.config = foomodules.FoorlConfig(
config_module_name,
import_path=config_module_path
)
super(Foorl, self).__init__(self.config.localpart, self.config.resource, self.config.password)
def sessionStart(self, event):
super(Foorl, self).sessionStart(event)
self.config.session_start(self)
def sessionEnd(self, event):
for hook in self.config.hooks.get("session_end", []):
try:
hook()
except Exception as err:
logging.exception(err)
def reply(self, msg, content):
if msg["type"] == "groupchat":
self.send_message(msg["mucroom"], mbody=content, mtype="groupchat")
else:
self.send_message(msg["from"], mbody=content, mtype=msg["type"])
def message(self, msg):
self.config.dispatch(msg)
if __name__=="__main__":
try:
import setproctitle
setproctitle.setproctitle("foorl")
except ImportError:
pass
logging.basicConfig(level=logging.INFO,
format='%(levelname)-8s %(message)s')
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--config-path",
dest="config_module_path",
help="Path to the config module. If unset, only the usual python path \
is searched",
default=None,
)
parser.add_argument(
"--config-module",
dest="config_module_name",
default="foorl_config",
help="Name of the python module containing the foorl configuration."
)
args = parser.parse_args()
del parser
bot = Foorl(args.config_module_name, args.config_module_path)
bot.run()