[Otfbot-svn] r128 - trunk/modules

allo at BerliOS allo
Fr Jun 29 13:20:10 CEST 2007


Author: allo
Date: 2007-06-29 13:20:09 +0200 (Fri, 29 Jun 2007)
New Revision: 128

Modified:
   trunk/modules/nobodyisperfectMod.py
Log:
updated nipMod for command callback


Modified: trunk/modules/nobodyisperfectMod.py
===================================================================
--- trunk/modules/nobodyisperfectMod.py	2007-06-29 11:12:51 UTC (rev 127)
+++ trunk/modules/nobodyisperfectMod.py	2007-06-29 11:20:09 UTC (rev 128)
@@ -114,41 +114,12 @@
 					self.allscore[user]=self.score[user]
 
 
-	def msg(self, user, channel, msg):
+	def command(self, user, channel, command, options):
 		user=string.lower(user.split("!")[0])
-		if channel == self.bot.nickname:
-			if self.phase==WAITING_FOR_QUESTION and user==self.gamemaster:
-				self.timer.cancel()
-				self.question=msg
-				self.bot.sendmsg(user, "Und jetzt die richtige Antwort")
-				self.phase=WAITING_FOR_QUIZMASTER_ANSWER
-				self.timer=self.bot.scheduler.callLater(TIMEOUT, self.end_of_quiz)
-
-			elif self.phase==WAITING_FOR_QUIZMASTER_ANSWER and user==self.gamemaster:
-				self.timer.cancel()
-				self.answers[user]=msg
-				self.bot.sendmsg(self.gamechannel, "Die Frage ist: "+self.question, self.bot.getConfig("encoding", "UTF-8"))
-				self.bot.sendmsg(self.gamechannel, "/msg mir eure Antworten.", self.bot.getConfig("encoding", "UTF-8"))
-				self.phase=WAITING_FOR_ANSWERS
-				self.timer=self.bot.scheduler.callLater(ANSWER_TIME, self.end_of_answertime) #TIMEOUT
-
-				#remove gamemaster from game, because he knows the answer
-				self.players.remove(self.gamemaster)
-				self.bot.sendmsg(self.gamemaster, "Zusatzinformation fuer nach dem Quiz(wenn nicht gewuenscht, einfach freilassen):")
-
-			elif (self.phase==WAITING_FOR_ANSWERS or self.phase==QUIZ) and user==self.gamemaster and not self.additional_info:
-				self.additional_info=msg
-
-			elif self.phase==WAITING_FOR_ANSWERS and not user in self.answers and user in self.players:
-				self.answers[user]=msg
-				if len(self.answers) == len(self.players)+1: #+gamemaster
-					if self.timer and self.timer.active():
-						self.timer.cancel()
-					self.end_of_answertime()
-		else:
-			if msg[:7]=="!remove":
+		if channel!=self.bot.nickname:
+			if command=="remove":
 				if self.phase==NO_GAME:
-					if len(msg)>8 and user==self.gameadmin: #8 because of the whitespace after !remove
+					if len(msg)>7 and user==self.gameadmin: #XXX: 7 because command has no trailing whitespace? - 8 because of the whitespace after !remove
 						player=string.lower(msg[8:])
 					else:
 						player=user
@@ -160,7 +131,7 @@
 				else:
 					self.bot.sendmsg(channel, "Spieler koennen nur zwischen 2 Runden entfernt werden")
 
-			if msg[:4]=="!add":
+			elif command=="add":
 				if self.phase==NO_GAME:
 					self.players.append(user)
 					self.bot.sendmsg(channel, user+" spielt jetzt mit.")
@@ -168,15 +139,15 @@
 				else:
 					self.bot.sendmsg(channel, "Spieler koennen nur zwischen 2 Runden hinzugefuegt werden")
 
-			if msg[:12]=="!restartgame":
+			elif command=="restartgame":
 				if self.phase==NO_GAME and user==self.gameadmin:
 					self.bot.sendmsg(channel, "Eine neue Runde startet, Spieler bleiben gleich!")
 					self.init_vars_for_restart()
 					self.phase=WAITING_FOR_QUESTION
-					self.bot.sendmsg(channel, self.gamemaster+": /msg mir die Frage.", self.bot.getConfig("encoding", "UTF-8"))
+					self.bot.sendmsg(channel, user+": /msg mir die Frage.", self.bot.getConfig("encoding", "UTF-8"))
 					self.timer=self.bot.scheduler.callLater(TIMEOUT, self.end_of_quiz)
 					
-			if msg[:10]=="!startgame":
+			elif command=="startgame":
 				if self.phase==NO_GAME:
 					self.init_vars()
 					self.gameadmin=user
@@ -186,7 +157,8 @@
 					self.gamechannel=channel #needed for queries which result in a public answer
 					self.timer=self.bot.scheduler.callLater(TIMEOUT, self.end_of_quiz)
 				elif self.phase==WAITING_FOR_PLAYERS and user==self.gameadmin:
-					self.timer.cancel()
+					if self.timer:
+						self.timer.cancel()
 					if len(self.players) >2:
 						self.phase=WAITING_FOR_QUESTION
 						random.shuffle(self.players)
@@ -194,11 +166,11 @@
 						self.bot.sendmsg(channel, self.gamemaster+": /msg mir die Frage.", self.bot.getConfig("encoding", "UTF-8"))
 						self.timer=self.bot.scheduler.callLater(TIMEOUT, self.end_of_quiz)
 					else:
-						self.bot.sendmsg(channel, self.gamemaster+" zu wenig Spieler!", self.bot.getConfig("encoding", "UTF-8"))
-			elif msg[:10]=="!abortgame":
+						self.bot.sendmsg(channel, self.gameadmin+": zu wenig Spieler!", self.bot.getConfig("encoding", "UTF-8"))
+			elif command=="abortgame":
 				self.end_of_quiz()
 
-			elif msg[:6]=="!score":
+			elif command=="score":
 				if len(self.allscore):
 					self.bot.sendmsg(channel, "=== Punkte ===", self.bot.getConfig("encoding", "UTF-8"))
 					points=self.allscore.values()
@@ -212,7 +184,40 @@
 								players.remove(player)
 								break;
 
-			elif string.lower(msg)[:3]=="ich" and self.phase==WAITING_FOR_PLAYERS:
+
+	def msg(self, user, channel, msg):
+		user=string.lower(user.split("!")[0])
+		if channel == self.bot.nickname:
+			if self.phase==WAITING_FOR_QUESTION and user==self.gamemaster:
+				self.timer.cancel()
+				self.question=msg
+				self.bot.sendmsg(user, "Und jetzt die richtige Antwort")
+				self.phase=WAITING_FOR_QUIZMASTER_ANSWER
+				self.timer=self.bot.scheduler.callLater(TIMEOUT, self.end_of_quiz)
+
+			elif self.phase==WAITING_FOR_QUIZMASTER_ANSWER and user==self.gamemaster:
+				self.timer.cancel()
+				self.answers[user]=msg
+				self.bot.sendmsg(self.gamechannel, "Die Frage ist: "+self.question, self.bot.getConfig("encoding", "UTF-8"))
+				self.bot.sendmsg(self.gamechannel, "/msg mir eure Antworten.", self.bot.getConfig("encoding", "UTF-8"))
+				self.phase=WAITING_FOR_ANSWERS
+				self.timer=self.bot.scheduler.callLater(ANSWER_TIME, self.end_of_answertime) #TIMEOUT
+
+				#remove gamemaster from game, because he knows the answer
+				self.players.remove(self.gamemaster)
+				self.bot.sendmsg(self.gamemaster, "Zusatzinformation fuer nach dem Quiz(wenn nicht gewuenscht, einfach freilassen):")
+
+			elif (self.phase==WAITING_FOR_ANSWERS or self.phase==QUIZ) and user==self.gamemaster and not self.additional_info:
+				self.additional_info=msg
+
+			elif self.phase==WAITING_FOR_ANSWERS and not user in self.answers and user in self.players:
+				self.answers[user]=msg
+				if len(self.answers) == len(self.players)+1: #+gamemaster
+					if self.timer and self.timer.active():
+						self.timer.cancel()
+					self.end_of_answertime()
+		else:
+			if string.lower(msg)[:3]=="ich" and self.phase==WAITING_FOR_PLAYERS:
 				if not (user in self.players or user==self.gamemaster):
 					self.players.append(user)
 					text=""




Mehr Informationen über die Mailingliste Otfbot-dev