diff --git a/connection/xmpp.py b/connection/xmpp.py
index dd1c061..d6e3a3f 100644
--- a/connection/xmpp.py
+++ b/connection/xmpp.py
@@ -33,6 +33,7 @@ class MucHandler(MucRoomHandler):
def set_topic(self, topic):
self.room_state.set_subject(topic)
+ self.room_state.subject = topic
def message_received(self, user, stanza):
if(user == None or user.same_as(self.room_state.me) or stanza.get_body() == None):
diff --git a/modules/log.py b/modules/log.py
index ff8093e..74e813a 100644
--- a/modules/log.py
+++ b/modules/log.py
@@ -3,27 +3,31 @@ from . import ModuleBase
class Module(ModuleBase):
def __init__(self, manager):
ModuleBase.__init__(self, manager)
- self.mysql = manager.get('mysql')
+ self.pgsql = manager.get('pgsql')
def helptexts(self):
return ['Chatlogs werden auch erstellt.']
def groupchat(self, room, nick, text, handler):
- cursor = self.mysql.cursor()
- cursor.execute('INSERT INTO log (`type`, `time`, `room`, `nick`, `text`) VALUES ("message", NOW(), %s, %s, %s)', (room, nick, text))
+ cursor = self.pgsql.cursor()
+ cursor.execute('INSERT INTO log ("type", "time", "room", "nick", "text") VALUES (\'message\', now(), %s, %s, %s)', (room, nick, text))
cursor.close()
+ self.pgsql.commit()
def join(self, room, nick, show, status, handler):
- cursor = self.mysql.cursor()
- cursor.execute('INSERT INTO log (`type`, `time`, `room`, `nick`, `show`, `text`) VALUES ("join", NOW(), %s, %s, %s, %s)', (room, nick, show, status))
+ cursor = self.pgsql.cursor()
+ cursor.execute('INSERT INTO log ("type", "time", "room", "nick", "show", "text") VALUES (\'join\', now(), %s, %s, %s, %s)', (room, nick, show, status))
cursor.close()
+ self.pgsql.commit()
def leave(self, room, nick, show, status, handler):
- cursor = self.mysql.cursor()
- cursor.execute('INSERT INTO log (`type`, `time`, `room`, `nick`, `show`, `text`) VALUES ("leave", NOW(), %s, %s, %s, %s)', (room, nick, show, status))
+ cursor = self.pgsql.cursor()
+ cursor.execute('INSERT INTO log ("type", "time", "room", "nick", "show", "text") VALUES (\'leave\', now(), %s, %s, %s, %s)', (room, nick, show, status))
cursor.close()
+ self.pgsql.commit()
def topic(self, room, nick, text, handler):
- cursor = self.mysql.cursor()
- cursor.execute('INSERT INTO log (`type`, `time`, `room`, `nick`, `text`) VALUES ("topic", NOW(), %s, %s, %s)', (room, nick, text))
+ cursor = self.pgsql.cursor()
+ cursor.execute('INSERT INTO log ("type", "time", "room", "nick", "text") VALUES (\'topic\', now(), %s, %s, %s)', (room, nick, text))
cursor.close()
+ self.pgsql.commit()
diff --git a/modules/mensa.py b/modules/mensa.py
index 3c3a197..b14ac02 100644
--- a/modules/mensa.py
+++ b/modules/mensa.py
@@ -32,8 +32,8 @@ class Module(ModuleBase):
return
def handle_data(data):
- r = re.compile(r'.*?
]*>(.*?)
.*?]*>(.*?)
', re.DOTALL)
- r2 = re.compile(r'.*?]*>(.*?) | ', re.DOTALL)
+ r = re.compile(r'.*?]*>(.*?)
.*?]*>(.*?)
', re.DOTALL|re.IGNORECASE)
+ r2 = re.compile(r'.*?]*>(.*?) | ', re.DOTALL|re.IGNORECASE)
def handle_data_row(data, pos):
match = r.match(data, pos)
@@ -59,7 +59,7 @@ class Module(ModuleBase):
return (ret, match.end())
- match = re.compile(r'^.*?]*>.*?]*>.*?(\d+)\.(\d+)\. - \d+\.\d+\.(\d+).*? | .*?]*>Freitag | \s*(.*?)
.*$', re.DOTALL).match(data)
+ match = re.compile(r'^.*?]*>.*?]*>.*?(\d+)\.(\d+)\. ?- ?\d+\.\d+\.(\d+).*? | .*?]*>Freitag | \s*(.*?)
.*$', re.DOTALL|re.IGNORECASE).match(data)
if not match:
return False
@@ -79,7 +79,7 @@ class Module(ModuleBase):
row = handle_data_row(data, pos)
if not row:
- return False
+ break
meals.append(row[0])
pos = row[1]
@@ -95,6 +95,7 @@ class Module(ModuleBase):
s = s.replace('Ü', 'Ü')
s = s.replace('ß', 'ß')
s = s.replace('é', 'é')
+ s = s.replace('è', 'è')
s = s.replace('“', '“')
s = s.replace('„', '„')
s = s.replace('–', '–')
@@ -113,6 +114,12 @@ class Module(ModuleBase):
stripunescape = (lambda item: (unescape(item[0].strip()), unescape(item[1].strip())))
meals = map(lambda item: map(stripunescape, item), meals)
+ if len(meals) == 0:
+ return False
+
+ while len(meals) < 6:
+ meals.insert(len(meals)-1, [[None], [None], [None], [None], [None]])
+
reply = 'Mensa-Menü für den %s\n\n' % day.strftime('%d.%m.%y')
if meals[0][weekday][0]:
reply += 'Eintopf: %s (%s)\n' % meals[0][weekday]
diff --git a/modules/pgsql.py b/modules/pgsql.py
new file mode 100644
index 0000000..a09a6de
--- /dev/null
+++ b/modules/pgsql.py
@@ -0,0 +1,30 @@
+from . import ModuleBase
+import psycopg2
+
+class Module(ModuleBase):
+ def __init__(self, manager):
+ ModuleBase.__init__(self, manager)
+
+ self.conf = manager.config['pgsql']
+
+ self.db = False
+ self._connect()
+
+ def _connect(self):
+ if self.db:
+ try:
+ self.db.close()
+ except:
+ pass
+
+ self.db = psycopg2.connect(host = self.conf['host'], user = self.conf['user'], password = self.conf['passwd'], database = self.conf['db'])
+
+ def cursor(self):
+ try:
+ return self.db.cursor()
+ except psycopg2.OperationalError:
+ self._connect()
+ return self.db.cursor()
+
+ def commit(self):
+ self.db.commit()
diff --git a/modules/topic.py b/modules/topic.py
index d878a91..bdc5143 100644
--- a/modules/topic.py
+++ b/modules/topic.py
@@ -6,24 +6,57 @@ import re
class Module(ModuleBase):
def __init__(self, manager):
ModuleBase.__init__(self, manager)
-
+
def commands(self):
- return [('!topic []', 'Fügt einen Text zum Thema des Chatraums hinzu oder zeigt das aktuelle Topic an')]
-
+ return [
+ ('!topic [s[how]]', 'Zeigt das aktuelle Topic mit IDs an'),
+ ('!topic a[dd] ', 'Fügt einen Text zum Thema des Chatraums hinzu'),
+ ('!topic d[el[ete]] ', 'Entfernt das Topic mit der ID')
+ ]
+
+ def _reply_topic(self, handler, prefix):
+ topic = handler.get_topic()
+ if topic is None or topic == '':
+ handler.reply('Es ist kein Topic gesetzt.')
+ return
+ topics = [s.strip() for s in topic.split('|')]
+ idtopics = zip(range(len(topics)), topics)
+ idtopicstrings = ["%i: %s" % t for t in idtopics]
+ handler.reply(prefix + '\n\n' + '\n'.join(idtopicstrings))
+
def groupchat(self, room, nick, text, handler):
- if not re.match(r'!topic(?:\W|\Z)', text):
+ if not re.match(r'!topic(?:\s|\Z)', text):
return
-
- if not re.match(r'!topic\W', text):
- handler.reply(handler.get_topic())
+
+ if re.match(r'!topic(?:\s+(?:s(?:how)?)?\s*)?\Z', text):
+ self._reply_topic(handler, 'Aktuelles Topic:')
return
-
- topic = re.sub(r'!topic\W+', '', text)
- if topic == '':
- return
-
+
oldtopic = handler.get_topic()
- if oldtopic != '' and oldtopic != None:
- topic += ' | ' + oldtopic
-
- handler.set_topic(topic)
+
+ if re.match(r'!topic\s+a(?:dd)?\s', text):
+ topic = re.sub(r'!topic\s+a(?:dd)?\s+', '', text)
+ if topic == '':
+ return
+
+ if oldtopic != '' and oldtopic is not None:
+ topic += ' | ' + oldtopic
+
+ handler.set_topic(topic)
+ self._reply_topic(handler, 'Neues Topic:')
+ return
+
+ if re.match(r'!topic\s+d(?:el(?:ete)?)?\s', text):
+ try:
+ topicid = int(re.sub(r'!topic\s+d(?:el(?:ete)?)?\s+', '', text))
+ except:
+ return
+
+ topics = [s.strip() for s in oldtopic.split('|')]
+ if topicid < 0 or topicid >= len(topics):
+ return
+
+ del topics[topicid]
+
+ handler.set_topic(' | '.join(topics))
+ self._reply_topic(handler, 'Neues Topic:')