summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2010-05-02 23:40:21 +0200
committerMatthias Schiffer <matthias@gamezock.de>2010-05-02 23:40:21 +0200
commit323d31514f7e438df5883ad6cb9e17cce6a296b3 (patch)
tree2efeb977154ca92b0c8a39fe958e91166aca68df /modules
parent88a78fa5d77a3db1024375fe4c0b654038604edb (diff)
downloadcurunir-323d31514f7e438df5883ad6cb9e17cce6a296b3.tar
curunir-323d31514f7e438df5883ad6cb9e17cce6a296b3.zip
Added topic module
Diffstat (limited to 'modules')
-rw-r--r--modules/base.py14
-rw-r--r--modules/ddate.py6
-rw-r--r--modules/help.py7
-rw-r--r--modules/log.py22
-rw-r--r--modules/mysql.py2
-rw-r--r--modules/topic.py25
6 files changed, 66 insertions, 10 deletions
diff --git a/modules/base.py b/modules/base.py
index 9d54c40..b839e9b 100644
--- a/modules/base.py
+++ b/modules/base.py
@@ -5,8 +5,20 @@ class ModuleBase:
def commands(self):
return []
+ def helptexts(self):
+ return []
+
def message(self, message_type, message_from, message_subject, message_body, reply):
pass
- def groupchat(self, room, message_from, message_body, reply):
+ def groupchat(self, room, nick, text, handler):
+ pass
+
+ def join(self, room, nick, show, status, handler):
+ pass
+
+ def leave(self, room, nick, show, status, handler):
+ pass
+
+ def topic(self, room, nick, text, handler):
pass
diff --git a/modules/ddate.py b/modules/ddate.py
index eee8a29..5c6fd77 100644
--- a/modules/ddate.py
+++ b/modules/ddate.py
@@ -8,8 +8,8 @@ class Module(ModuleBase):
def commands(self):
return [('!ddate', 'Das heutige Datum im einzigen relevaten Kalender-System.')]
- def groupchat(self, room, message_from, message_body, reply):
- if not re.match(r'!ddate(?:\W|\Z)', message_body):
+ def groupchat(self, room, nick, text, handler):
+ if not re.match(r'!ddate(?:\W|\Z)', text):
return
- reply(subprocess.Popen(['ddate'], stdout=subprocess.PIPE).communicate()[0].strip())
+ handler.reply(subprocess.Popen(['ddate'], stdout=subprocess.PIPE).communicate()[0].strip())
diff --git a/modules/help.py b/modules/help.py
index 71d1a56..ed3e4d3 100644
--- a/modules/help.py
+++ b/modules/help.py
@@ -8,11 +8,12 @@ class Module(ModuleBase):
def commands(self):
return [('!help', 'Zeigt diese Hilfe an...')]
- def groupchat(self, room, message_from, message_body, reply):
- if not re.match(r'!help(?:\W|\Z)', message_body):
+ def groupchat(self, room, nick, text, handler):
+ if not re.match(r'!help(?:\W|\Z)', text):
return
commands = reduce(lambda l, mod: l + mod.commands(), self.manager.modules.itervalues(), [])
helpstring = reduce(lambda s, (c, h): s + c + ': ' + h + '\n', commands, '')
+ helptexts = '\n'.join(reduce(lambda l, mod: l + mod.helptexts(), self.manager.modules.itervalues(), []))
- reply('Befehle:\n\n' + helpstring)
+ handler.reply(('Befehle:\n' + helpstring + '\n' + helptexts).strip())
diff --git a/modules/log.py b/modules/log.py
index f97ad90..04ea721 100644
--- a/modules/log.py
+++ b/modules/log.py
@@ -5,7 +5,25 @@ class Module(ModuleBase):
ModuleBase.__init__(self, manager)
self.db = manager.get('mysql').db
- def groupchat(self, room, message_from, message_body, reply):
+ def helptexts(self):
+ return ['Chatlogs werden auch erstellt.']
+
+ def groupchat(self, room, nick, text, handler):
+ cursor = self.db.cursor()
+ cursor.execute('INSERT INTO log (`type`, `time`, `room`, `nick`, `text`) VALUES ("message", NOW(), %s, %s, %s)', (room, nick, text))
+ cursor.close()
+
+ def join(self, room, nick, show, status, handler):
+ cursor = self.db.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()
+
+ def leave(self, room, nick, show, status, handler):
+ cursor = self.db.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()
+
+ def topic(self, room, nick, text, handler):
cursor = self.db.cursor()
- cursor.execute('INSERT INTO log (time, room, nick, text) VALUES (NOW(), %s, %s, %s)', (room, message_from, message_body))
+ cursor.execute('INSERT INTO log (`type`, `time`, `room`, `nick`, `text`) VALUES ("topic", NOW(), %s, %s, %s)', (room, nick, text))
cursor.close()
diff --git a/modules/mysql.py b/modules/mysql.py
index 3b6c3b1..2db2817 100644
--- a/modules/mysql.py
+++ b/modules/mysql.py
@@ -7,4 +7,4 @@ class Module(ModuleBase):
conf = manager.config['mysql']
- self.db = MySQLdb.connect(host = conf['host'], user = conf['user'], passwd = conf['passwd'], db = conf['db'])
+ self.db = MySQLdb.connect(host = conf['host'], user = conf['user'], passwd = conf['passwd'], db = conf['db'], use_unicode = True, charset = 'utf8')
diff --git a/modules/topic.py b/modules/topic.py
new file mode 100644
index 0000000..bc8c83e
--- /dev/null
+++ b/modules/topic.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+
+from base import ModuleBase
+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')]
+
+ def groupchat(self, room, nick, text, handler):
+ if not re.match(r'!topic\W', text):
+ 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)