Added log module
This commit is contained in:
parent
0277a779c9
commit
d537d4b69b
6 changed files with 38 additions and 7 deletions
|
@ -6,5 +6,12 @@ config = {
|
|||
'rooms': [],
|
||||
'nick': '',
|
||||
|
||||
'mysql': {
|
||||
'host': '',
|
||||
'user': '',
|
||||
'passwd': '',
|
||||
'db': ''
|
||||
},
|
||||
|
||||
'modules': []
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class MucHandler(MucRoomHandler):
|
|||
if(user.same_as(self.room_state.me)):
|
||||
return
|
||||
|
||||
for mod in self.client.module_manager.modules:
|
||||
for mod in self.client.module_manager.modules.itervalues():
|
||||
mod.groupchat(stanza.get_from().bare().as_unicode(), stanza.get_from().resource, stanza.get_body(), self.room_state.send_message)
|
||||
|
||||
def user_joined(self, user, stanza):
|
||||
|
|
14
curunir.py
14
curunir.py
|
@ -6,14 +6,18 @@ from config import config
|
|||
class ModuleManager:
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.modules = []
|
||||
self.modules = {}
|
||||
|
||||
for mod in config['modules']:
|
||||
self.load(mod)
|
||||
self.get(mod)
|
||||
|
||||
def get(self, name):
|
||||
if not name in self.modules:
|
||||
mod = __import__('modules.' + name, globals(), locals(), ['Module'])
|
||||
self.modules[name] = mod.Module(self)
|
||||
|
||||
return self.modules[name]
|
||||
|
||||
def load(self, name):
|
||||
mod = __import__('modules.' + name, globals(), locals(), ['Module'])
|
||||
self.modules.append(mod.Module(self))
|
||||
|
||||
run = True
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class Module(ModuleBase):
|
|||
if not re.match(r'!help(?:\W|\Z)', message_body):
|
||||
return
|
||||
|
||||
commands = reduce(lambda l, mod: l + mod.commands(), self.manager.modules, [])
|
||||
commands = reduce(lambda l, mod: l + mod.commands(), self.manager.modules.itervalues(), [])
|
||||
helpstring = reduce(lambda s, (c, h): s + c + ': ' + h + '\n', commands, '')
|
||||
|
||||
reply('Befehle:\n\n' + helpstring)
|
||||
|
|
10
modules/log.py
Normal file
10
modules/log.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from base import ModuleBase
|
||||
|
||||
class Module(ModuleBase):
|
||||
def __init__(self, manager):
|
||||
ModuleBase.__init__(self, manager)
|
||||
self.db = manager.get('mysql').db
|
||||
|
||||
def groupchat(self, room, message_from, message_body, reply):
|
||||
cursor = self.db.cursor()
|
||||
cursor.execute('INSERT INTO log (time, room, nick, text) VALUES (NOW(), %s, %s, %s)', (room, message_from, message_body))
|
10
modules/mysql.py
Normal file
10
modules/mysql.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from base import ModuleBase
|
||||
import MySQLdb
|
||||
|
||||
class Module(ModuleBase):
|
||||
def __init__(self, manager):
|
||||
ModuleBase.__init__(self, manager)
|
||||
|
||||
conf = manager.config['mysql']
|
||||
|
||||
self.db = MySQLdb.connect(host = conf['host'], user = conf['user'], passwd = conf['passwd'], db = conf['db'])
|
Reference in a new issue