[Otfbot-svn] r117 - in trunk: . modules

allo at BerliOS allo
Sa Jun 23 19:04:02 CEST 2007


Author: allo
Date: 2007-06-23 19:04:02 +0200 (Sat, 23 Jun 2007)
New Revision: 117

Added:
   trunk/scheduler.py
Removed:
   trunk/scheduler.py
   trunk/scheduler_ng.py
Modified:
   trunk/modules/kiMod.py
   trunk/modules/rdfMod.py
   trunk/modules/reminderMod.py
   trunk/otfbot.py
Log:
completely replaced old scheduler + new naming


Modified: trunk/modules/kiMod.py
===================================================================
--- trunk/modules/kiMod.py	2007-06-23 16:41:08 UTC (rev 116)
+++ trunk/modules/kiMod.py	2007-06-23 17:04:02 UTC (rev 117)
@@ -278,16 +278,16 @@
 				chance=int(self.bot.getConfig("kiMod_answerQueryPercent", "70"))*10
 				if number < chance:
 					#self.bot.sendmsg(user, reply, "UTF-8")
-					self.bot.getReactor().callLater(delay, self.bot.sendmsg, user, reply, "UTF-8")
+					self.bot.scheduler.callLater(delay, self.bot.sendmsg, user, reply, "UTF-8")
 			else:
 				number=random.randint(1,1000)
 				chance=int(self.bot.getConfig("kiMod_answerPercent", "50"))*10
 				if israndom:
 					#self.bot.sendmsg(channel, reply, "UTF-8")
-					self.bot.getReactor().callLater(delay, self.bot.sendmsg, channel, reply, "UTF-8")
+					self.bot.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.getReactor().callLater(delay, self.bot.sendmsg, channel, user+": "+reply, "UTF-8")
+					self.bot.scheduler.callLater(delay, self.bot.sendmsg, channel, user+": "+reply, "UTF-8")
 
 	def connectionMade(self):
 		self.lnickname=string.lower(self.bot.nickname)

Modified: trunk/modules/rdfMod.py
===================================================================
--- trunk/modules/rdfMod.py	2007-06-23 16:41:08 UTC (rev 116)
+++ trunk/modules/rdfMod.py	2007-06-23 17:04:02 UTC (rev 117)
@@ -39,7 +39,7 @@
 		self.wait=60 * float(bot.getConfig("wait", "5", "rdfMod"))
 		self.rdfUrls=[]
 		self.rdfChannels={}
-		self.bot.getReactor().callLater(10, self.run)
+		self.bot.scheduler.callLater(10, self.run)
 		self.sleeped=0
 
 				
@@ -51,7 +51,7 @@
 		if not self.end:
 			#splits the waittime, to support stop()
 			self.sleeped+=10
-			self.bot.getReactor().callLater(10, self.run)
+			self.bot.scheduler.callLater(10, self.run)
 
 	def postNews(self, rdfUrl):
 		unread =[]

Modified: trunk/modules/reminderMod.py
===================================================================
--- trunk/modules/reminderMod.py	2007-06-23 16:41:08 UTC (rev 116)
+++ trunk/modules/reminderMod.py	2007-06-23 17:04:02 UTC (rev 117)
@@ -59,4 +59,4 @@
 				self.messages[when].append([channel, user, text])
 			else:
 				self.messages[when]=[[channel, user, text]]
-			self.bot.getReactor().callLater(wait*60, self.remind)
+			self.bot.scheduler.callLater(wait*60, self.remind)

Modified: trunk/otfbot.py
===================================================================
--- trunk/otfbot.py	2007-06-23 16:41:08 UTC (rev 116)
+++ trunk/otfbot.py	2007-06-23 17:04:02 UTC (rev 117)
@@ -25,7 +25,7 @@
 
 from twisted.internet import reactor, protocol, error, ssl
 import os, random, string, re, sys, traceback, atexit
-import functions, config, scheduler, scheduler_ng
+import functions, config, scheduler
 
 
 # some constants, can be retrieved from serveranswer while connecting.
@@ -202,12 +202,8 @@
         self.logger = logging.getLogger("core")
         self.logger.info("Starting new Botinstance")
         self.startMods()
-        self.scheduler = scheduler_ng.Scheduler(self.getReactor())
-        self.scheduler.addJob(10,self.test)
+        self.scheduler = scheduler.Scheduler(self.getReactor())
     
-    def test(self):
-        self.logger.debug("hallo")
-
     def _apirunner(self,apifunction,args={}):
         """Pass all calls to modules callbacks through this method, they are checked whether they should be execeted or not"""
         for mod in self.mods:
@@ -249,11 +245,6 @@
         return loadConfig(configfile)
     def writeConfig(self):
         return writeConfig()
-    # Schedular
-    def addScheduleJob(self, time, function):
-        self.log.warn("Call to deprecated method addScheduleJob")
-        return addScheduleJob(time, function)
-    
     def getUsers(self):
         return self.users
     def getReactor(self):
@@ -524,4 +515,4 @@
                 connections[network]=reactor.connectSSL(unicode(network).encode("iso-8859-1"), int(getConfig('port','6697','main',network)), f,s);
             else:
                 connections[network]=reactor.connectTCP(unicode(network).encode("iso-8859-1"), int(getConfig('port','6667','main',network)), f)
-    reactor.run()
\ No newline at end of file
+    reactor.run()

Deleted: trunk/scheduler.py
===================================================================
--- trunk/scheduler.py	2007-06-23 16:41:08 UTC (rev 116)
+++ trunk/scheduler.py	2007-06-23 17:04:02 UTC (rev 117)
@@ -1,50 +0,0 @@
-#!/usr/bin/python
-#
-# This file is part of OtfBot.
-#
-# OtfBot is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# OtfBot is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with OtfBot; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-# 
-# (c) 2005, 2006, 2007 by Alexander Schier
-
-import threading, time
-class Schedule(threading.Thread):
-	def __init__(self):
-		threading.Thread.__init__(self)
-		self.times=[]
-		self.functions=[]
-		self.stopme=False
-
-	def stop(self):
-		self.stopme=True
-
-	def run(self):
-		self.setName("schedular")
-		while not self.stopme:
-			time.sleep(60)
-			toremove=[]
-			for i in range(len(self.times)):
-				self.times[i]=self.times[i]-1
-				if self.times[i]<=0:
-					self.functions[i]()
-					toremove.append(i)
-			toremove.reverse()
-			for i in toremove:
-				del self.times[i]
-				del self.functions[i]
-
-
-	def addScheduleJob(self, wait, function):
-		self.times.append( int(wait) )
-		self.functions.append(function)

Copied: trunk/scheduler.py (from rev 116, trunk/scheduler_ng.py)
===================================================================
--- trunk/scheduler_ng.py	2007-06-23 16:41:08 UTC (rev 116)
+++ trunk/scheduler.py	2007-06-23 17:04:02 UTC (rev 117)
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+#
+# This file is part of OtfBot.
+#
+# OtfBot is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# OtfBot is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with OtfBot; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+# 
+# (c) 2007 by Robert Weidlich
+
+class Scheduler:
+    """Wrapper class for the scheduling functions of twisted.internet.reactor.ReactorTime"""
+    def __init__(self,reactor):
+        self.reactor=reactor
+    def callLater(self,time,function,*args,**kwargs):
+        """executes the given function after time seconds with arguments (*args) and keyword arguments (**kwargs)"""
+        self.reactor.callLater(time,function,*args,**kwargs)
+
+    def callPeriodic(self,delay,function,kwargs={}):
+        """executes the given function every delay seconds with keyword arguments (**kwargs)"""
+        def func(delay,function,**kwargs):
+            args=(delay,function)
+            if function(**kwargs):
+                self.reactor.callLater(delay,func,*args,**kwargs)
+        args=(delay,function)
+        self.reactor.callLater(delay,func,*args,**kwargs)

Deleted: trunk/scheduler_ng.py
===================================================================
--- trunk/scheduler_ng.py	2007-06-23 16:41:08 UTC (rev 116)
+++ trunk/scheduler_ng.py	2007-06-23 17:04:02 UTC (rev 117)
@@ -1,36 +0,0 @@
-#!/usr/bin/python
-#
-# This file is part of OtfBot.
-#
-# OtfBot is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# OtfBot is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with OtfBot; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-# 
-# (c) 2007 by Robert Weidlich
-
-class Scheduler:
-    """Wrapper class for the scheduling functions of twisted.internet.reactor.ReactorTime"""
-    def __init__(self,reactor):
-        self.reactor=reactor
-    def addJob(self,time,function,*args,**kwargs):
-        """executes the given function after time seconds with arguments (*args) and keyword arguments (**kwargs)"""
-        self.reactor.callLater(time,function,*args,**kwargs)
-
-    def addPeriodicJob(self,delay,function,kwargs={}):
-        """executes the given function every delay seconds with keyword arguments (**kwargs)"""
-        def func(delay,function,**kwargs):
-            args=(delay,function)
-            if not function(**kwargs):
-                self.reactor.callLater(delay,func,*args,**kwargs)
-        args=(delay,function)
-        self.reactor.callLater(delay,func,*args,**kwargs)
\ No newline at end of file




Mehr Informationen über die Mailingliste Otfbot-dev