]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/modpython.py
Couple of srvx updates.
[irc/evilnet/x3.git] / src / modpython.py
index 75e0a58d46725e348a7951fe24cd0fcd452141fd..1f7c83c97606e2004651ab08fa4a69e68803eb5c 100644 (file)
@@ -11,7 +11,8 @@
 # - provide helper functions for scripts to do common things like msg a person or a channel,
 #   reply, etc.
 
-import svc
+import _svc
+import plugins
 
 import math
 
@@ -33,11 +34,11 @@ class irc:
         self.target = target   #the channel message was in (if public)
 
     def send_target_privmsg(self, source, target, message):
-        svc.send_target_privmsg(source, target,  "%s "%(message))
+        _svc.send_target_privmsg(source, target,  "%s "%(message))
 
     def reply(self, message):
         """ Send a private reply to the user using convenience values"""
-        print "DEBUG: sending a message from %s to %s: %s"%(self.service, self.caller, message)
+        #print "DEBUG: sending a message from %s to %s: %s"%(self.service, self.caller, message)
         if(len(self.target)):
             self.send_target_privmsg(self.service, self.target, "%s: %s"%(self.caller, message))
         else:
@@ -47,26 +48,52 @@ class handler:
     """ Main hub of python system. Handle callbacks from c. """
 
     def __init__(self):
-        print "DEBUG: constructor for handler initing"
-        self.plugins = plugins(self)
+        #print "DEBUG: constructor for handler initing"
+        self.plugins = plugins_(self)
         if(not self.plugins):
             print "DEBUG: unable to make self.plugins!?!"
+        self.newplugins = plugins.load()
 
     def init(self, irc): # not to be confused with __init__!
         """ This gets called once all the objects are up and running. Otherwise,
         were not done initing this own instance to be able to start calling it """
-        print "DEBUG: in handler.init()"
+        #print "DEBUG: in handler.init()"
         self.plugins.init()
         return 0
 
     def join(self, irc, channel, nick):
-        user = svc.get_user(nick)
-        print "DEBUG: handler.join()"
-        self.plugins.callhandler("join", irc, [channel, nick], [channel, nick])
+        #user = _svc.get_user(nick)
+        #print "DEBUG: handler.join()"
+        return self.plugins.callhandler("join", irc, [channel, nick], [channel, nick])
+
+    def server_link(self, server):
+        for plugin in self.newplugins:
+            if plugin.server_link(server):
+                return 1
         return 0
-        
+
+    def new_user(self, user):
+        for plugin in self.newplugins:
+            if plugin.new_user(user):
+                return 1
+        return 0
+
+    def nick_change(self, user, oldnick):
+        for plugin in self.newplugins:
+            plugin.nick_change(user, oldnick)
+
+    def del_user(self, user, killer, why):
+        for plugin in self.newplugins:
+            plugin.del_user(user, killer, why)
+
+    def topic(self, who, chan, old_topic):
+        for plugin in self.newplugins:
+            if plugin.topic(who, chan, old_topic):
+                return 1
+        return 0
+
     def cmd_run(self, irc, cmd):
-        print "DEBUG: handler.cmd_run: %s"%cmd
+        #print "DEBUG: handler.cmd_run: %s"%cmd
         eval(cmd)
         return 0
 
@@ -78,11 +105,13 @@ class handler:
         self.addhook("command", method, [plugin, command])
 
     def cmd_command(self, irc, plugin, cmd, args):
-        print "DEBUG: handlec.cmd_command; %s %s; args= %s"%(plugin, cmd, args)
-        self.plugins.callhandler("command", irc, [plugin, cmd], [args])
-        return 0
+        #print "DEBUG: handel.cmd_command; %s %s; args= %s"%(plugin, cmd, args)
+        return self.plugins.callhandler("command", irc, [plugin, cmd], [args])
 
-class plugins:
+    def load(self, irc, plugin):
+        return self.plugins.load(plugin)
+
+class plugins_:
     """Class to handle loading/unloading of plugins"""
     loaded_plugins = {}
     hooks = []
@@ -105,48 +134,51 @@ class plugins:
                 for i in range(len(self.filter)):
                     if( self.filter[i] != None 
                       and self.filter[i] != evdata[i]): # should be case insensitive? or how to compare?
-                        print "DEBUG: rejecting event, %s is not %s"%(self.filter[i], evdata[i])
+                        #print "DEBUG: rejecting event, %s is not %s"%(self.filter[i], evdata[i])
                         return False
                 return True
             else:
                 return False
 
         def trigger(self, irc, args):
-            print "DEBUG: Triggering %s event. with '%s' arguments."%(self.event, args)
+            #print "DEBUG: Triggering %s event. with '%s' arguments."%(self.event, args)
             self.method(irc, *args)
 
     def __init__(self, handler):
         """ Constructor """
-        print "DEBUG: constructor for plugins initing"
+        #print "DEBUG: constructor for plugins initing"
         self.handler = handler
 
     def init(self):
-        print "DEBUG: in plugins.init()"
+        #print "DEBUG: in plugins.init()"
         self.load("annoy")
+        self.load("hangman")
 
     def addhook(self, event, method, filter=[None], data=None):
-        print "DEBUG: Adding hook for %s."%event
+        #print "DEBUG: Adding hook for %s."%event
         self.hooks.append(self.hook(event, method, filter, data))
 
     def findhooksforevent(self, event, data):
         ret = []
-        print "DEBUG: findhooksforevent() looking..."
+        #print "DEBUG: findhooksforevent() looking..."
         for hook in self.hooks:
-            print "DEBUG: looking at a %s hook..."%hook.event
+            #print "DEBUG: looking at a %s hook..."%hook.event
             if(hook.event_is(event, data)):
                 ret.append(hook)
         return ret
 
     def callhandler(self, event, irc, filter, args):
         for hook in self.findhooksforevent(event, filter):
-            hook.trigger(irc, args)
+            if(hook.trigger(irc, args)):
+                return 1
+        return 0
 
     def load(self, name):
         """ Loads a plugin by name """
         mod_name = "plugins.%s"%name
         need_reload = False
         if(sys.modules.has_key(mod_name)):
-            need_reload = true
+            need_reload = True
         #TODO: try to catch compile errors etc.
 
         if(need_reload == False):
@@ -157,4 +189,5 @@ class plugins:
         Class = module.Class
         pluginObj = Class(self.handler, irc())
         self.loaded_plugins[mod_name] = pluginObj
+        return True