-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathorakel.py
executable file
·130 lines (117 loc) · 3.86 KB
/
orakel.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/python
# -*- coding: utf-8 -*-
# vim:set ts=8 sts=8 sw=8 tw=80 noet cc=80:
import sys
import configparser
import logging
from client import Client
from msgdatabase import MessageDatabase
from pingpong import PingPong
from alphabet import Alphabet
from count import Count
from search import Search
from greet import Greet
#from expression import Expression
from actions import Actions
from storage import Storage
from flooding import Flooding
from config import Configuration
from choice import Choice
from scripting import Scripting
from fatfox import FatFox
from burgi import Burgi
from cookies import Cookies
from mute import Mute
from status import Status
from url_title import Urltitle
from finder import Finder
from hands import Hands
from weather import Weather
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
def load_database(filename):
database = {}
with open(filename, "r") as f:
for line in f.readlines():
line = line.strip()
parts = line.split(";")
key = parts[0].strip().lower()
value = ";".join(parts[1:]).strip()
database[key] = value
return database
if __name__ == "__main__":
filename = "orakel.cfg"
config = configparser.SafeConfigParser()
config.read(filename)
jid = config.get("xmpp", "jid")
password = config.get("xmpp", "password")
room = config.get("xmpp", "room")
nick = config.get("xmpp", "nick")
logging.basicConfig(level=logging.INFO,
format='%(levelname)-8s %(message)s')
storage = Storage(config.get("db", "storage"))
status = Status()
conf = Configuration(storage, config)
questions = load_database(config.get("db", "questions"))
msgdb = MessageDatabase(questions)
pingpong = PingPong()
alphabet = Alphabet(storage, conf)
count = Count(storage, conf)
greet = Greet([ x.strip() for x in
config.get("modules", "greetings").split(",") ], nick)
flooding = Flooding(conf)
search_engines = load_database(config.get("db", "searchengines"))
search = Search(search_engines)
#expression = Expression()
actions = Actions(storage)
choice = Choice(conf)
scripting = Scripting(storage, search_engines=search_engines)
fatfox = FatFox()
burgi = Burgi()
cookies = Cookies()
#urltitle = Urltitle()
#finder = Finder()
hands = Hands(storage, conf, config.get("modules", "hands"))
weather = Weather(storage, conf, config.get("modules", "hands"))
mute = Mute(storage)
conf.add_handler('mute', mute.config_handler)
conf.add_handler(['show', 'mute'], mute.show_handler)
conf.add_handler(['show', 'participants'], status.show_participants)
conf.add_handler(['show', 'online', 'users'], status.show_online_users)
xmpp = Client(jid, password, room, nick)
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0045') # Multi-User Chat
xmpp.register_plugin('xep_0199') # XMPP Ping
xmpp.add_mentation_listener(mute.talk_muted)
xmpp.add_mentation_listener(conf)
xmpp.add_mentation_listener(msgdb)
xmpp.add_mentation_listener(actions.active)
xmpp.add_message_listener(mute.talk_muted)
xmpp.add_message_listener(conf)
xmpp.add_message_listener(pingpong)
xmpp.add_message_listener(alphabet)
xmpp.add_message_listener(count)
xmpp.add_message_listener(search)
xmpp.add_message_listener(greet)
xmpp.add_message_listener(flooding)
#xmpp.add_message_listener(expression)
xmpp.add_message_listener(fatfox)
#xmpp.add_message_listener(burgi)
xmpp.add_message_listener(cookies)
#xmpp.add_message_listener(urltitle)
xmpp.add_message_listener(actions.passive)
xmpp.add_message_listener(choice)
xmpp.add_message_listener(scripting)
xmpp.add_online_listener(mute.on_online)
#xmpp.add_message_listener(finder)
xmpp.add_message_listener(hands)
xmpp.add_message_listener(weather)
def get_participants():
return xmpp.participants
status.get_participants = get_participants
mute.set_role = xmpp.set_role
if xmpp.connect():
xmpp.process(block=True)
else:
print("Unable to connect")