Compare commits
10 commits
9ead5a211c
...
7825748a26
Author | SHA1 | Date | |
---|---|---|---|
7825748a26 | |||
64efcb0fd8 | |||
dbc091688f | |||
bb0168b6b8 | |||
33bbc21b0f | |||
a52e07d904 | |||
aba29f23e6 | |||
b07ceef46b | |||
ab10b2ae43 | |||
b414e5f1ca |
5 changed files with 104 additions and 29 deletions
|
@ -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):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -32,8 +32,8 @@ class Module(ModuleBase):
|
|||
return
|
||||
|
||||
def handle_data(data):
|
||||
r = re.compile(r'.*?<tr[^>]*>(.*?)</tr>.*?<tr[^>]*>(.*?)</tr>', re.DOTALL)
|
||||
r2 = re.compile(r'.*?<td[^>]*>(.*?)</td>', re.DOTALL)
|
||||
r = re.compile(r'.*?<tr[^>]*>(.*?)</tr>.*?<tr[^>]*>(.*?)</tr>', re.DOTALL|re.IGNORECASE)
|
||||
r2 = re.compile(r'.*?<td[^>]*>(.*?)</td>', 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'^.*?<table[^>]*>.*?<td[^>]*>.*?(\d+)\.(\d+)\. - \d+\.\d+\.(\d+).*?</td>.*?<td[^>]*>Freitag</td>\s*</tr>(.*?)</table>.*$', re.DOTALL).match(data)
|
||||
match = re.compile(r'^.*?<table[^>]*>.*?<td[^>]*>.*?(\d+)\.(\d+)\. ?- ?\d+\.\d+\.(\d+).*?</td>.*?<td[^>]*>Freitag</td>\s*</tr>(.*?)</table>.*$', 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]
|
||||
|
|
30
modules/pgsql.py
Normal file
30
modules/pgsql.py
Normal file
|
@ -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()
|
|
@ -6,24 +6,57 @@ import re
|
|||
class Module(ModuleBase):
|
||||
def __init__(self, manager):
|
||||
ModuleBase.__init__(self, manager)
|
||||
|
||||
|
||||
def commands(self):
|
||||
return [('!topic [<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] <Topic>', 'Fügt einen Text zum Thema des Chatraums hinzu'),
|
||||
('!topic d[el[ete]] <ID>', '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:')
|
||||
|
|
Reference in a new issue