view MoinMoin/jabber/ @ 2088:a99ed13fec1e

Introduce a shared secret for wiki-bot communication + some code style fixes.
author Karol 'grzywacz' Nowak <>
date Sun, 03 Jun 2007 19:44:56 +0200
parents 5e0c667c79cb
children 4ec961fd40d9
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - a xmlrpc server and client for the notification bot

    This is a bot for notification and simple editing
    operations. Developed as a Google Summer of Code 

    @copyright: 2007 by Karol Nowak <>
    @license: GNU GPL, see COPYING for details.

import time, xmlrpclib
from threading import Thread
from SimpleXMLRPCServer import SimpleXMLRPCServer

class NotificationCommand:
    """Class representing a notification request"""
    def __init__(self, jid, text):
        self.jid = jid
        self.text = text

class XMLRPCClient(Thread):
    """XMLRPC Client
    It's responsible for performing XMLRPC operations on
    a wiki, as inctructed by command objects received from
    the XMPP component"""
    def __init__(self, config, commands):
        @param commands: an output command queue
        self.commands = commands
        self.config = config
    def run(self):
        """Starts the server / thread"""

class XMLRPCServer(Thread):
    """XMLRPC Server
    It waits for notifications requests coming from wiki,
    creates command objects and puts them on a queue for
    later processing by the XMPP component
    @param commands: an input command queue
    def __init__(self, config, commands):
        self.commands = commands
        self.verbose = config.verbose
        self.secret = config.secret
        self.server = SimpleXMLRPCServer((config.xmlrpc_host, config.xmlrpc_port))
    def run(self):
        """Starts the server / thread"""
    def log(self, message):
        """Logs a message and its timestamp"""
        t = time.localtime( time.time() )
        print time.strftime("%H:%M:%S", t), message

    def send_notification(self, secret, jid, text):
        """Instructs the XMPP component to send a notification"""
        if secret != self.secret:
            raise xmlrpclib.Fault(1, "You are not allowed to use this bot!")
        n = NotificationCommand(jid, text)
        return True