[Otfbot-svn] r592 - in trunk: . lib plugins/ircClient plugins/ircServer services

cato at mail.berlios.de cato
So Aug 30 23:00:00 CEST 2009


Author: cato
Date: 2009-08-30 22:59:58 +0200 (Sun, 30 Aug 2009)
New Revision: 592

Modified:
   trunk/lib/pluginSupport.py
   trunk/otfbot.tac
   trunk/plugins/ircClient/auth.py
   trunk/plugins/ircClient/controlIRC.py
   trunk/plugins/ircClient/controlServer.py
   trunk/plugins/ircClient/feed.py
   trunk/plugins/ircClient/human.py
   trunk/plugins/ircClient/ki.py
   trunk/plugins/ircClient/mirror.py
   trunk/plugins/ircClient/reminder.py
   trunk/plugins/ircClient/svn.py
   trunk/plugins/ircClient/tv.py
   trunk/plugins/ircServer/controlServer.py
   trunk/plugins/ircServer/human.py
   trunk/services/auth.py
   trunk/services/ircClient.py
   trunk/services/ircServer.py
   trunk/services/remoteCliServer.py
   trunk/services/webServer.py
Log:
 * fixed access to root-level services

Modified: trunk/lib/pluginSupport.py
===================================================================
--- trunk/lib/pluginSupport.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/lib/pluginSupport.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -10,7 +10,7 @@
         self.classes=[]
         self.plugins={}
         #XXX: the dependency should be more explicit?
-        self.config = root.getNamedServices()['config']
+        self.config = root.getServiceNamed('config')
         
     def register_pluginsupport_commands(self):
         # Make sure to have this method!
@@ -29,7 +29,7 @@
         except ImportError:
             raise self.ModuleMissing(dependency)
     def depends_on_service(self, dependency):
-        if not self.root.getNamedService(dependency):
+        if not self.root.getServiceNamed(dependency):
             raise self.ServiceMissing(dependency)
     def depends_on_plugin(dependency):
         if not self.plugins.has_key(dependency):

Modified: trunk/otfbot.tac
===================================================================
--- trunk/otfbot.tac	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/otfbot.tac	2009-08-30 20:59:58 UTC (rev 592)
@@ -40,7 +40,7 @@
 errfile="otfbot.err"
 stdout=True
 
-formatter = logging.Formatter('%(asctime)s %(name)-18s %(module)-18s %(levelname)-8s %(message)s')
+formatter = logging.Formatter('%(asctime)s %(name)-10s %(module)-14s %(funcName)-20s %(levelname)-8s %(message)s')
 
 filelogger = logging.handlers.RotatingFileHandler(logfile,'a',1048576,5)
 filelogger.setFormatter(formatter)        
@@ -89,14 +89,7 @@
 configfilename="otfbot.yaml"
 
 application=service.Application("otfbot")
-application.getServices=lambda: service.IServiceCollection(application).services
-application.getNamedServices=lambda: service.IServiceCollection(application).namedServices
-def getNamedService(name):
-    try:
-        return application.getNamedServices()[name]
-    except KeyError:
-        return None
-application.getNamedService=getNamedService
+application.getServiceNamed=service.IServiceCollection(application).getServiceNamed
 
 configS=configService.loadConfig(configfilename, "plugins/*/*.yaml")
 if not configS:

Modified: trunk/plugins/ircClient/auth.py
===================================================================
--- trunk/plugins/ircClient/auth.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/plugins/ircClient/auth.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -20,6 +20,8 @@
 
 import random, re
 from lib import chatMod
+from lib.User import IrcUser
+
 from twisted.cred.credentials import UsernamePassword
 from twisted.words.iwords import IUser
 
@@ -37,7 +39,7 @@
         nick=user.split("!")[0]
         #print nick
         if msg[0:9] == "identify ":
-            portal=self.bot.root.getNamedService("auth")
+            portal=self.bot.root.getServiceNamed("auth")
             if not portal:
                 return
             msgs=msg.split(" ")
@@ -46,8 +48,11 @@
             elif len(msgs) == 3:
                 cred=UsernamePassword(msgs[1],msgs[2])
             else:
-                 self.bot.sendmsg(nick, "Usage: identify [user] pass")
-                 return
+                self.bot.sendmsg(nick, "Usage: identify [user] pass")
+                return
+            if not nick in self.bot.userlist:
+                u=IrcUser(user)
+                self.bot.userlist[u.name]=u
             d=portal.login(cred, self.bot.userlist[nick], IUser)
             d.addCallback(lambda args: self.bot.sendmsg(nick, "Successfully logged in as "+str(args[1].name)))
             d.addErrback(lambda failure: self.bot.sendmsg(nick, "Login failed: "+str(failure.getErrorMessage())))

Modified: trunk/plugins/ircClient/controlIRC.py
===================================================================
--- trunk/plugins/ircClient/controlIRC.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/plugins/ircClient/controlIRC.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -30,7 +30,7 @@
         if self.control.has_key(user) and msg == "endcontrol":
             del self.control[user]
         if msg == "control" and self.bot.auth(user) > 0:
-            self.control[user]=self.bot.root.getNamedService("control")
+            self.control[user]=self.bot.root.getServiceNamed("control")
             self.bot.sendmsg(nick,"Entered configuration modus. type 'endcontrol' to exit")
         elif self.control.has_key(user):
             output=self.control[user].handle_command(msg)
@@ -44,11 +44,11 @@
             cmd.append(command)
             if options and options != "":
                 cmd.append(options)
-            r=self.bot.root.getNamedService("control").handle_command(" ".join(cmd))
+            r=self.bot.root.getServiceNamed("control").handle_command(" ".join(cmd))
             if r is None:
                 cmd.insert(0,self.bot.parent.parent.name)
                 cmd.insert(0,self.network)
-                r=self.bot.root.getNamedService("control").handle_command(" ".join(cmd))
+                r=self.bot.root.getServiceNamed("control").handle_command(" ".join(cmd))
             if r is not None:
                 self.bot.sendmsg(channel, r)
         elif command == "reload" and len(options) > 0:

Modified: trunk/plugins/ircClient/controlServer.py
===================================================================
--- trunk/plugins/ircClient/controlServer.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/plugins/ircClient/controlServer.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -22,7 +22,7 @@
 class Plugin(chatMod.chatMod):
     def __init__(self, bot):
         self.bot=bot
-        self.getServers=lambda : [connection.kwargs['factory'].protocol for connection in bot.root.getNamedServices()['ircServer'].services]
+        self.getServers=lambda : [connection.kwargs['factory'].protocol for connection in bot.root.getServiceNamed('ircServer').services]
     def irc_unknown(self, prefix, command, params):
         if command=="PONG":
                 for server in self.getServers():

Modified: trunk/plugins/ircClient/feed.py
===================================================================
--- trunk/plugins/ircClient/feed.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/plugins/ircClient/feed.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -34,7 +34,7 @@
         self.logger = logging.getLogger("feedMod")
         if not feedparser_available:
             self.bot.depends("feedparser module")
-        if not self.bot.root.getNamedService('scheduler'):
+        if not self.bot.root.getServiceNamed('scheduler'):
             self.bot.depends("scheduler service")
         
         self.feedHeadlines={} #map url -> [(url, headline), ...]
@@ -56,7 +56,7 @@
         if factor==0:
             self.logger.warning(url+" has a waitFactor of 0. Skipping feed.")
             return
-        self.callIDs[url]=self.bot.root.getNamedService('scheduler').callLater(minWait*60, self.postNewsLoop, channel, url, minWait, minWait, maxWait, factor, postMax)
+        self.callIDs[url]=self.bot.root.getServiceNamed('scheduler').callLater(minWait*60, self.postNewsLoop, channel, url, minWait, minWait, maxWait, factor, postMax)
 
         self.readUrls[channel]=[]
         self.feedLastLoaded[url]=0
@@ -144,7 +144,7 @@
         had_new=self.postNews(channel, url, feedPostMax)    
 
         newWait=self.getWaitTime(curWait, minWait, maxWait, factor, had_new)
-        self.callIDs[url]=self.bot.root.getNamedService('scheduler').callLater(newWait*60, self.postNewsLoop, channel, url, newWait, minWait, maxWait, factor, feedPostMax) #recurse
+        self.callIDs[url]=self.bot.root.getServiceNamed('scheduler').callLater(newWait*60, self.postNewsLoop, channel, url, newWait, minWait, maxWait, factor, feedPostMax) #recurse
 
     def connectionLost(self, reason):
         self.stop()

Modified: trunk/plugins/ircClient/human.py
===================================================================
--- trunk/plugins/ircClient/human.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/plugins/ircClient/human.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -21,10 +21,10 @@
 
 #same as in serverpart!
 def sendNames(server, network, channel):
-    getClient=lambda network: server.root.getNamedServices()['ircClient'].namedServices[network].kwargs['factory'].protocol
+    getClient=lambda network: server.root.getServiceNamed('ircClient').getServiceNamed(network).protocol
 
-    if network in server.root.getNamedServices()['ircClient'].namedServices.keys():
-        names=[server.root.getNamedServices()['ircClient'].namedServices[network].kwargs['factory'].protocol.users[channel][nickname]['modchar'].strip()+nickname for nickname in getClient(network).users[channel].keys()]
+    if network in server.root.getServiceNamed('ircClient').namedServices.keys():
+        names=[server.root.getServiceNamed('ircClient').namedServices[network].protocol.users[channel][nickname]['modchar'].strip()+nickname for nickname in getClient(network).users[channel].keys()]
         server.names(server.name, "#"+network+"-"+channel, names)
 
 class Plugin(chatMod.chatMod):
@@ -33,7 +33,7 @@
         self.bot.depends_on_service("ircServerService")
         
     def msg(self, user, channel, msg):
-        for server in self.bot.root.getNamedServices()['ircServer'].services:
+        for server in self.bot.root.getServiceNamed('ircServer').services:
             #print user, channel, msg,  server.kwargs['factory'].protocol.connected
             server=server.kwargs['factory'].protocol
             if server.connected:
@@ -41,7 +41,7 @@
     def query(self, user, channel, msg):
         #TODO FIXME: this is a workaround. the external irc client does not recognize own messages from queries (xchat)
         #or are just the parameters wrong? so it will show the foreign nick, but prefix the message with <botnick>
-        for server in self.bot.root.getNamedServices()['ircServer'].services:
+        for server in self.bot.root.getServiceNamed('ircServer').services:
             server=server.kwargs['factory'].protocol
             if not server.connected:
                 return
@@ -51,7 +51,7 @@
                 #server.sendmsg(self.network+"-"+user, self.bot.server.name, msg)
                 server.sendmsg(self.network+"-"+user, server.name, "< %s> "%user.split("!")[0]+msg)
     def irc_RPL_ENDOFNAMES(self, prefix, params):
-        for server in self.bot.root.getNamedServices()['ircServer'].services:
+        for server in self.bot.root.getServiceNamed('ircServer').services:
             server=server.kwargs['factory'].protocol
             if server.connected:
                 sendNames(server, self.network, params[1])

Modified: trunk/plugins/ircClient/ki.py
===================================================================
--- trunk/plugins/ircClient/ki.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/plugins/ircClient/ki.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -255,7 +255,7 @@
         delay=len(reply)*0.3*float(self.bot.config.get("wait", "2", "kiMod", self.bot.network)) #a normal user does not type that fast
         if number < chance:
             #self.bot.sendmsg(user, reply, "UTF-8")
-            self.bot.root.getNamedService('scheduler').callLater(delay, self.bot.sendmsg, user, reply, "UTF-8")
+            self.bot.root.getServiceNamed('scheduler').callLater(delay, self.bot.sendmsg, user, reply, "UTF-8")
     def msg(self, user, channel, msg):
         user=user.split("!")[0]
         if not user in self.nicklist:
@@ -312,10 +312,10 @@
             chance=int(self.bot.config.get("answerPercent", "50", "kiMod", self.bot.network, channel))*10
             if israndom:
                 #self.bot.sendmsg(channel, reply, "UTF-8")
-                self.bot.root.getNamedService('scheduler').callLater(delay, self.bot.sendmsg, channel, reply, "UTF-8")
+                self.bot.root.getServiceNamed('scheduler').callLater(delay, self.bot.sendmsg, channel, reply, "UTF-8")
             elif number < chance: #apply answerPercent only on answers
                 #self.bot.sendmsg(channel, user+": "+reply, "UTF-8")
-                self.bot.root.getNamedService('scheduler').callLater(delay, self.bot.sendmsg, channel, user+": "+reply, "UTF-8")
+                self.bot.root.getServiceNamed('scheduler').callLater(delay, self.bot.sendmsg, channel, user+": "+reply, "UTF-8")
 
     def connectionMade(self):
         self.lnickname=string.lower(self.bot.nickname)

Modified: trunk/plugins/ircClient/mirror.py
===================================================================
--- trunk/plugins/ircClient/mirror.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/plugins/ircClient/mirror.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -23,7 +23,7 @@
 class Plugin(chatMod.chatMod):
     def __init__(self, bot):
         self.bot=bot
-        self.getbot=lambda network: bot.root.getNamedServices()['ircClient'].namedServices[network].kwargs['factory'].protocol
+        self.getbot=lambda network: bot.root.getServiceNamed('ircClient').getServiceNamed(network).protocol
         #x034 (red) is the bot
         self.colors=["\x032", "\x033", "\x035", "\x0311", "\x0310", "\x0312", "\x0315", "\x0314", "\x0316", "\x0313", "\x036"]
 

Modified: trunk/plugins/ircClient/reminder.py
===================================================================
--- trunk/plugins/ircClient/reminder.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/plugins/ircClient/reminder.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -52,4 +52,4 @@
                 self.messages[when].append([channel, user, text])
             else:
                 self.messages[when]=[[channel, user, text]]
-            self.bot.root.getNamedServices()['scheduler'].callLater(wait*60, self.remind)
+            self.bot.root.getServiceNamed('scheduler').callLater(wait*60, self.remind)

Modified: trunk/plugins/ircClient/svn.py
===================================================================
--- trunk/plugins/ircClient/svn.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/plugins/ircClient/svn.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -60,7 +60,7 @@
                 except:
                     lastrev = 0
                 try:
-                    self.callIds[i + "-" + channel] = self.bot.getNamedServices()['scheduler'].callLater(1, self.svncheck, self.svnconfig[i]['url'],self.svnconfig[i]['checkinterval'],channel,i)
+                    self.callIds[i + "-" + channel] = self.bot.getServiceNamed('scheduler').callLater(1, self.svncheck, self.svnconfig[i]['url'],self.svnconfig[i]['checkinterval'],channel,i)
                 except KeyError:
                     self.logger.error("Repository " + i + " doen't exist!")
         
@@ -92,4 +92,4 @@
             lastrevision = rev
             self.bot.msg(channel,chr(2) + "[" + str(name) + "]" + chr(2) + " Revision " + str(rev) + " by " + data['author'].encode() + ": " + data['message'].encode().replace("\n","").replace("\r",""))
             open(datadir + "/revision_" + channel + "_" + name,"w").writelines(str(lastrevision))
-        self.callIds[name + "-" + channel] = self.bot.getNamedServices()['scheduler'].callLater(int(interval)*60, self.svncheck, url, interval, channels, name, lastrevision)
+        self.callIds[name + "-" + channel] = self.bot.getServiceNamed('scheduler').callLater(int(interval)*60, self.svncheck, url, interval, channels, name, lastrevision)

Modified: trunk/plugins/ircClient/tv.py
===================================================================
--- trunk/plugins/ircClient/tv.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/plugins/ircClient/tv.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -43,7 +43,7 @@
         #standardsender = self.bot.getConfig("standardsender","ard,zdf,rtl,sat.1,n24,pro7,vox","tvMod")
         standardsender = self.bot.config.get("standardsender","ard,zdf,rtl,sat.1,n24,pro7,vox","tvMod")
         dataurl = "http://static.xmltv.info/tv.xml.txt"
-        self.bot.getNamedServices()['scheduler'].callLater(1, self.update_data, dataurl)
+        self.bot.getServiceNamed('scheduler').callLater(1, self.update_data, dataurl)
         self.standardsender = []
         for i in standardsender.split(","):
             self.standardsender.append(i.lower().replace(" ",""))
@@ -170,7 +170,7 @@
             except:
                 self.logger.info("xmltv-file is not loaded completely yet. TV-Plugin will be aviable as it's loading is done.")
             time.sleep(30)
-        self.bot.getNamedServices()['scheduler'].callLater(86400, self.update_data, dataurl)
+        self.bot.getServiceNamed('scheduler').callLater(86400, self.update_data, dataurl)
     
 class tv:
     def __init__(self,xmltvfile):

Modified: trunk/plugins/ircServer/controlServer.py
===================================================================
--- trunk/plugins/ircServer/controlServer.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/plugins/ircServer/controlServer.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -26,7 +26,7 @@
     def __init__(self, server):
         self.server=server
         self.first=True
-        self.control=controlInterface.controlInterface(self.server.root.getNamedServices()["control"])
+        self.control=controlInterface.controlInterface(self.server.root.getServiceNamed("control"))
     def irc_NICK(self, prefix, params):
         if self.first:
             self.server.join(self.server.getHostmask(), "#control")

Modified: trunk/plugins/ircServer/human.py
===================================================================
--- trunk/plugins/ircServer/human.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/plugins/ircServer/human.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -25,10 +25,10 @@
 from twisted.protocols import basic
 
 def sendNames(server, network, channel):
-    getClient=lambda network: server.root.getNamedServices()['ircClient'].namedServices[network].kwargs['factory'].protocol
+    getClient=lambda network: server.root.getServiceNamed('ircClient').namedServices[network].kwargs['factory'].protocol
 
-    if network in server.root.getNamedServices()['ircClient'].namedServices.keys():
-        names=[server.root.getNamedServices()['ircClient'].namedServices[network].kwargs['factory'].protocol.users[channel][nickname]['modchar'].strip()+nickname for nickname in getClient(network).users[channel].keys()]
+    if network in server.root.getServiceNamed('ircClient').namedServices.keys():
+        names=[server.root.getServiceNamed('ircClient').namedServices[network].kwargs['factory'].protocol.users[channel][nickname]['modchar'].strip()+nickname for nickname in getClient(network).users[channel].keys()]
         server.names(server.name, "#"+network+"-"+channel, names)
 
 class Plugin(chatMod.chatMod):
@@ -36,8 +36,8 @@
         self.server=server
         self.mychannels=[]
         self.first=True
-        self.getClient=lambda network: server.root.getNamedServices()['ircClient'].namedServices[network].kwargs['factory'].protocol
-        self.getClientNames=lambda : [connection.name for connection in self.server.root.getNamedServices()['ircClient'].services]
+        self.getClient=lambda network: server.root.getServiceNamed('ircClient').getServiceNamed(network).protocol
+        self.getClientNames=lambda : [connection.name for connection in self.server.root.getServiceNamed('ircClient').services]
 
         self.server.registerCallback(self, "irc_NICK")
         self.server.registerCallback(self, "irc_PRIVMSG")
@@ -67,7 +67,7 @@
             (network, channel)=params[0][1:].split("-", 1) #[1:] and (a,b) can raise ValueErrors
             if network in self.getClientNames():
                 if len(params)>=2: #password given
-                    self.server.root.getNamedServices()['config'].set("password",params[1], "main", network, channel)
+                    self.server.root.getServiceNamed('config').set("password",params[1], "main", network, channel)
                     self.getClient(network).join(channel, params[1])
                 else:
                     self.getClient(network).join(channel)

Modified: trunk/services/auth.py
===================================================================
--- trunk/services/auth.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/services/auth.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -96,7 +96,7 @@
 
     def startService(self):
         print "auth service started"
-        self.config=self.root.getNamedServices()['config']
+        self.config=self.root.getServiceNamed('config')
         self.realm = YamlWordsRealm("userdb",self.config.get("datadir","data")+"/userdb.yaml")
         portal.Portal.__init__(self, self.realm)
         # checker hinzufuegen

Modified: trunk/services/ircClient.py
===================================================================
--- trunk/services/ircClient.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/services/ircClient.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -36,7 +36,7 @@
         self.root=root
         self.parent=parent
         service.MultiService.__init__(self)
-        self.controlservice=self.root.getNamedService('control')
+        self.controlservice=self.root.getServiceNamed('control')
         self.logger=logging.getLogger(self.name)
         if not self.controlservice:
             logger.warning("cannot register control-commands as no control-service is available")
@@ -46,9 +46,10 @@
             self.register_ctl_command(lambda : self.namedServices.keys(), name="list")
     
     def startService(self):
-        self.config=self.root.getNamedServices()['config']
+        self.config=self.root.getServiceNamed('config')
         for network in self.config.getNetworks():
-            self.connect(network)
+            if self.config.getBool('enabled', 'True', 'main', network):
+                self.connect(network)
         service.MultiService.startService(self)
 
     def connect(self, network):
@@ -82,7 +83,46 @@
                 namespace = [namespace,]
             namespace.insert(0, self.name)
             self.controlservice.register_command(f, namespace, name)
-            
+
+class BotFactory(protocol.ClientFactory):
+    """The Factory for the Bot"""
+
+    def __init__(self, root, parent, network):
+        self.root=root
+        self.parent=parent
+        self.protocol=Bot
+        self.network=network
+        self.config=root.getServiceNamed('config')
+        self.logger=logging.getLogger(network)
+
+    def __repr__(self):
+        return "<BotFactory for network %s>"%self.network
+
+    def clientConnectionLost(self, connector, reason):
+        self.protocol=None
+        self.service.protocol=None
+        if not reason.check(error.ConnectionDone):
+            self.logger.warn("Got disconnected from "+connector.host+": "+str(reason.getErrorMessage()))
+            #protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
+        
+    def clientConnectionFailed(self, connector, reason):
+        self.logger.warn("Connection to "+connector.host+" failed: "+str(reason.getErrorMessage()))
+        #protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
+    
+    def buildProtocol(self,addr):
+        proto=self.protocol(self.root, self)
+        self.protocol=proto
+        self.service.protocol=proto
+        return proto
+    
+#    def stopFactory(self):
+#        #import inspect
+#        #for o in inspect.stack():
+#        #    self.logger.debug(str(o))
+#        self.logger.info("Got Signal to stop factory, stopping service as well")
+#        self.service.disownServiceParent()
+#        self.service.stopService()
+    
 class Bot(pluginSupport, irc.IRCClient):
     """ The Protocol of our IRC-Bot
         @ivar plugins: contains references to all plugins, which are loaded
@@ -106,7 +146,7 @@
 
     def __init__(self, root, parent):
         pluginSupport.__init__(self, root, parent)
-        self.config=root.getNamedServices()['config']
+        self.config=root.getServiceNamed('config')
         self.network=self.parent.network
         self.ircClient=self.parent.parent
         self.logger = logging.getLogger(self.network)
@@ -115,11 +155,6 @@
             self.versionNum="svn "+"$Revision: 177 $".split(" ")[1]
             self.versionEnv=''
 
-        self.delConfig=lambda *args, **kwargs: self.warn_and_execute(config.delConfig, *args, **kwargs)
-        self.getConfig=lambda *args, **kwargs: self.warn_and_execute(config.getConfig, *args, **kwargs)
-        self.hasConfig=lambda *args, **kwargs: self.warn_and_execute(config.hasConfig, *args, **kwargs)
-        self.setConfig=lambda *args, **kwargs: self.warn_and_execute(config.setConfig, *args, **kwargs)
-
         self.channels=[]
         self.realname=self.config.get("realname", "A Bot", "main", self.network)
         self.password=self.config.get('password', None, 'main', self.network)
@@ -133,11 +168,12 @@
         
         self.lineRate = 1.0/float(self.config.get("linesPerSecond","2","main",self.network))
 
-        # all users known to the bot, Hostmask => IrcUser
+        # all users known to the bot, nick => IrcUser
         self.userlist    = {}
         # usertracking, channel=>{User => level}
         self.users       = {}
 
+        self.serversupports  = {}
         self.modchars        = {16: 'a', 8: 'o', 4: 'h', 2: 'v', 0: ' '}
         self.rev_modchars    = dict([(v, k) for (k, v) in self.modchars.iteritems()])
 
@@ -329,10 +365,12 @@
         self.channels.remove(channel)
         self.config.set("enabled", "False", "main", self.network, channel) #disable the channel for the next start of the bot
 
-    #def isupport(self, options):
-        #self.logger.debug("isupport"+str(options))
-    #def bounce(self, info):
-        #self.logger.debug("bounce:"+str(info))
+    def isupport(self, options):
+        for o in options:
+            kv = o.split('=',1)
+            if len(kv) == 1:
+                kv.append(True)
+            self.serversupports[kv[0]] = kv[1]
     #def myInfo(self, servername, version, umodes, cmodes):
         #self.logger.debug("myinfo: servername="+str(servername)+" version="+str(version)+" umodes="+str(umodes)+" cmodes="+str(cmodes))
     def command(self, user, channel, command, options):
@@ -543,7 +581,16 @@
             else:
                 u = IrcUser(nick+"!user at host")
                 self.userlist[nick] = u
+            self.sendLine("USERHOST "+nick)
             self.users[params[2]][u] = self.rev_modcharvals[s]
+            
+    def irc_RPL_USERHOST(self, prefix, params):
+        for rpl in params[1].strip().split(" "):
+            (nick, hostmask)=rpl.split('=',1)
+            hm=hostmask.split('@',1)
+            self.userlist[nick].user=hm[0][1:]
+            self.userlist[nick].host=hm[1]
+    
     def irc_INVITE(self, prefix, params):
         """ called by twisted,
             if the bot was invited
@@ -554,6 +601,9 @@
         self.config.set("enabled", True, "main", self.network, channel)
         self.join(channel)
 
+    def irc_RPL_BOUNCE(self, prefix, params):
+        self.isupport(params[1:-1])
+
     def lineReceived(self, line):
         """ called by twisted
             for every line which was received from the IRC-Server
@@ -581,34 +631,4 @@
     def disconnect(self):
         """disconnects cleanly from the current network"""
         self._apirunner("stop")
-        self.quit('Bye')
-        
-class BotFactory(protocol.ReconnectingClientFactory):
-    """The Factory for the Bot"""
-
-    def __init__(self, root, parent, network):
-        self.root=root
-        self.parent=parent
-        self.protocol=Bot
-        self.network=network
-        self.config=root.getNamedServices()['config']
-        self.logger=logging.getLogger(network)
-    def __repr__(self):
-        return "<BotFactory for network %s>"%self.network
-
-    def clientConnectionLost(self, connector, reason):
-        self.protocol=None
-        self.service.protocol=None
-        if not reason.check(error.ConnectionDone):
-            self.logger.warn("Got disconnected from "+connector.host+": "+str(reason.getErrorMessage()))
-            protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
-        
-    def clientConnectionFailed(self, connector, reason):
-        self.logger.warn("Connection to "+connector.host+" failed: "+str(reason.getErrorMessage()))
-        #protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
-    
-    def buildProtocol(self,addr):
-        proto=self.protocol(self.root, self)
-        self.protocol=proto
-        self.parent.getServiceNamed(self.network).protocol=proto
-        return proto
+        self.quit('Bye')
\ No newline at end of file

Modified: trunk/services/ircServer.py
===================================================================
--- trunk/services/ircServer.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/services/ircServer.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -35,7 +35,7 @@
         self.parent=parent
         service.MultiService.__init__(self)
     def startService(self):
-        self.config=self.root.getNamedServices()['config']
+        self.config=self.root.getServiceNamed('config')
         port=int(self.config.get("port", "6667", "server"))
         interface=interface=self.config.get("interface", "127.0.0.1", "server")
         factory=ircServerFactory(self.root, self)
@@ -55,7 +55,7 @@
         self.firstnick=True
         self.logger=logging.getLogger("server")
         self.classes=[]
-        self.config=root.getNamedServices()['config']
+        self.config=root.getServiceNamed('config')
 
         self.startPlugins()
 
@@ -101,7 +101,7 @@
     def __init__(self, root, parent):
         self.root=root
         self.parent=parent
-        self.config=root.getNamedServices()['config']
+        self.config=root.getServiceNamed('config')
 
         self.protocol=Server
     def buildProtocol(self, addr):

Modified: trunk/services/remoteCliServer.py
===================================================================
--- trunk/services/remoteCliServer.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/services/remoteCliServer.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -65,7 +65,7 @@
         f.privateKeys = {'ssh-rsa' : keys.Key.fromString(privateKey) }
         del privateKey
         try:
-            f.portal.checkers = self.root.getNamedServices()["auth"].getCheckers()
+            f.portal.checkers = self.root.getServiceNamed("auth").getCheckers()
         except KeyError:
             pass
         serv=internet.TCPServer(
@@ -119,7 +119,7 @@
 
     def openShell(self, protocol):
         #serverProtocol = insults.ServerProtocol(remoteCLI, self)
-        serverProtocol = insults.ServerProtocol(manhole.ColoredManhole, {'app':self.service.root})
+        serverProtocol = insults.ServerProtocol(manhole.ColoredManhole, {'app':self.service.root, 'stop':reactor.stop})
         serverProtocol.makeConnection(protocol)
         protocol.makeConnection(session.wrapProtocol(serverProtocol))
 

Modified: trunk/services/webServer.py
===================================================================
--- trunk/services/webServer.py	2009-08-30 13:08:15 UTC (rev 591)
+++ trunk/services/webServer.py	2009-08-30 20:59:58 UTC (rev 592)
@@ -11,7 +11,7 @@
         self.parent=parent
         service.MultiService.__init__(self)
     def startService(self):
-        self.config=self.root.getNamedServices()['config']
+        self.config=self.root.getServiceNamed('config')
         self.server=myHTTPServer(("0.0.0.0", 8080), myHTTPRequestHandler, self.root, self)
         self.thread=thread.start_new_thread(self.server.serve_forever, ())
         service.MultiService.startService(self)  




Mehr Informationen über die Mailingliste Otfbot-dev