Changing sender to nick in modules

This commit is contained in:
Némunaire 2012-07-23 12:07:26 +02:00
parent 93d623e241
commit 14a963871f
12 changed files with 103 additions and 101 deletions

View File

@ -48,6 +48,8 @@ def parseanswer (msg):
if res is not None:
if res.group(2) == "sender":
cnt[i] = msg.sender
elif res.group(2) == "nick":
cnt[i] = msg.nick
elif res.group(2) == "chan" or res.group(2) == "channel":
cnt[i] = msg.channel
elif res.group(2) == "date":
@ -75,7 +77,7 @@ def parseask (msg):
alias = ModuleState("alias")
alias["alias"] = result.group(1)
alias["origin"] = result.group(3)
alias["creator"] = msg.sender
alias["creator"] = msg.nick
DATAS.getNode("aliases").addChild(alias)
msg.send_snd("Nouvel alias %s défini avec succès." % result.group(1))
save()

View File

@ -25,7 +25,7 @@ def help_full ():
def findName(msg):
if len(msg.cmd) < 2 or msg.cmd[1].lower() == "moi" or msg.cmd[1].lower() == "me":
name = msg.sender.lower()
name = msg.nick.lower()
else:
name = msg.cmd[1].lower()
@ -56,7 +56,7 @@ def parseanswer(msg):
msg.send_chn (msg.countdown_format (tyd, "Il reste %s avant l'anniversaire de %s !" % ("%s", name), ""))
else:
msg.send_chn ("%s: désolé, je ne connais pas la date d'anniversaire de %s. Quand est-il né ?"%(msg.sender, name))
msg.send_chn ("%s: désolé, je ne connais pas la date d'anniversaire de %s. Quand est-il né ?"%(msg.nick, name))
return True
elif msg.cmd[0] == "age":
(matches, name) = findName(msg)
@ -66,7 +66,7 @@ def parseanswer(msg):
msg.send_chn (msg.countdown_format (d, "", "%s a %s." % (n, "%s")))
else:
msg.send_chn ("%s: désolé, je ne connais pas l'âge de %s. Quand est-il né ?"%(msg.sender, name))
msg.send_chn ("%s: désolé, je ne connais pas l'âge de %s. Quand est-il né ?"%(msg.nick, name))
return True
else:
return False
@ -77,19 +77,19 @@ def parseask(msg):
try:
extDate = msg.extractDate ()
if extDate is None:
msg.send_chn ("%s: ta date de naissance ne paraît pas valide..." % (msg.sender))
msg.send_chn ("%s: ta date de naissance ne paraît pas valide..." % (msg.nick))
else:
if msg.sender.lower() in DATAS.index:
DATAS.index[msg.sender.lower()] = extDate
if msg.nick.lower() in DATAS.index:
DATAS.index[msg.nick.lower()] = extDate
else:
ms = ModuleState("birthday")
ms.setAttribute("name", msg.sender.lower())
ms.setAttribute("name", msg.nick.lower())
ms.setAttribute("born", extDate)
DATAS.addChild(ms)
msg.send_chn ("%s: ok, c'est noté, ta date de naissance est le %s" % (msg.sender, extDate.strftime("%A %d %B %Y à %H:%M")))
msg.send_chn ("%s: ok, c'est noté, ta date de naissance est le %s" % (msg.nick, extDate.strftime("%A %d %B %Y à %H:%M")))
save()
except:
msg.send_chn ("%s: ta date de naissance ne paraît pas valide..." % (msg.sender))
msg.send_chn ("%s: ta date de naissance ne paraît pas valide..." % (msg.nick))
return True
return False

View File

@ -70,7 +70,7 @@ def parseanswer(msg):
strnd = ModuleState("strend")
strnd["server"] = msg.srv.id
strnd["channel"] = msg.channel
strnd["proprio"] = msg.sender
strnd["proprio"] = msg.nick
strnd["start"] = datetime.now()
strnd["name"] = msg.cmd[1]
DATAS.addChild(strnd)
@ -101,7 +101,7 @@ def parseanswer(msg):
elif (msg.cmd[0] == "end" or msg.cmd[0] == "forceend") and len(msg.cmd) > 1:
if msg.cmd[1] in DATAS.index:
msg.send_chn ("%s a duré %s." % (msg.cmd[1], msg.just_countdown(datetime.now () - DATAS.index[msg.cmd[1]].getDate("start"))))
if DATAS.index[msg.cmd[1]]["proprio"] == msg.sender or (msg.cmd[0] == "forceend" and msg.sender == msg.srv.owner):
if DATAS.index[msg.cmd[1]]["proprio"] == msg.nick or (msg.cmd[0] == "forceend" and msg.nick == msg.srv.owner):
DATAS.delChild(DATAS.index[msg.cmd[1]])
Manager.newStrendEvt.set()
save()
@ -148,7 +148,7 @@ def parseask(msg):
evt = ModuleState("event")
evt["server"] = msg.srv.id
evt["channel"] = msg.channel
evt["proprio"] = msg.sender
evt["proprio"] = msg.nick
evt["name"] = name.group(1)
evt["start"] = extDate
evt["msg_after"] = msg_after
@ -162,7 +162,7 @@ def parseask(msg):
evt = ModuleState("event")
evt["server"] = msg.srv.id
evt["channel"] = msg.channel
evt["proprio"] = msg.sender
evt["proprio"] = msg.nick
evt["name"] = name.group(1)
evt["msg_before"] = texts.group (2)
DATAS.addChild(evt)

View File

@ -44,8 +44,8 @@ class Session:
if nextQ is not None:
if self.channel == self.server.nick:
self.server.send_msg_final(self.sender, "%s%s" % (bfr, nextQ.question))
elif self.sender != self.channel:
self.server.send_msg_final(self.channel, "%s: %s%s" % (self.sender, bfr, nextQ.question))
elif self.sender.split("!")[0] != self.channel:
self.server.send_msg_final(self.channel, "%s: %s%s" % (self.sender.split("!")[0], bfr, nextQ.question))
else:
self.server.send_msg_final(self.channel, "%s%s" % (bfr, nextQ.question))
else:

View File

@ -73,28 +73,28 @@ def buildSession(msg, categ = None, nbQuest = 10, channel = False):
if channel:
Session.SESSIONS[msg.channel] = sess
else:
Session.SESSIONS[msg.sender] = sess
Session.SESSIONS[msg.realname] = sess
def askQuestion(msg, bfr = ""):
Session.SESSIONS[msg.sender].askNext(bfr)
Session.SESSIONS[msg.realname].askNext(bfr)
def parseanswer(msg):
global DATAS
if msg.cmd[0] == "qcm" or msg.cmd[0] == "qcmchan" or msg.cmd[0] == "simulateqcm":
if msg.sender in Session.SESSIONS:
if msg.realname in Session.SESSIONS:
if len(msg.cmd) > 1:
if msg.cmd[1] == "stop" or msg.cmd[1] == "end":
sess = Session.SESSIONS[msg.sender]
sess = Session.SESSIONS[msg.realname]
if sess.good > 1: goodS = "s"
else: goodS = ""
msg.send_chn("%s: Fini, tu as donné %d bonne%s réponse%s sur %d questions." % (msg.sender, sess.good, goodS, goodS, sess.current))
del Session.SESSIONS[msg.sender]
msg.send_chn("%s: Fini, tu as donné %d bonne%s réponse%s sur %d questions." % (msg.nick, sess.good, goodS, goodS, sess.current))
del Session.SESSIONS[msg.realname]
return True
elif msg.cmd[1] == "next" or msg.cmd[1] == "suivant" or msg.cmd[1] == "suivante":
askQuestion(msg)
return True
msg.send_chn("%s: tu as déjà une session de QCM en cours, finis-la avant d'en commencer une nouvelle." % msg.sender)
msg.send_chn("%s: tu as déjà une session de QCM en cours, finis-la avant d'en commencer une nouvelle." % msg.nick)
elif msg.channel in Session.SESSIONS:
if len(msg.cmd) > 1:
if msg.cmd[1] == "stop" or msg.cmd[1] == "end":
@ -128,19 +128,19 @@ def parseanswer(msg):
elif msg.cmd[0] == "qcmchan":
Session.SESSIONS[msg.channel].askNext()
else:
msg.send_chn("QCM de %d questions" % len(Session.SESSIONS[msg.sender].questions))
del Session.SESSIONS[msg.sender]
msg.send_chn("QCM de %d questions" % len(Session.SESSIONS[msg.realname].questions))
del Session.SESSIONS[msg.realname]
return True
elif msg.sender in Session.SESSIONS:
elif msg.realname in Session.SESSIONS:
if msg.cmd[0] == "info" or msg.cmd[0] == "infoquestion":
msg.send_chn("Cette question a été écrite par %s et validée par %s, le %s" % Session.SESSIONS[msg.sender].question.tupleInfo)
msg.send_chn("Cette question a été écrite par %s et validée par %s, le %s" % Session.SESSIONS[msg.realname].question.tupleInfo)
return True
elif msg.cmd[0] == "report" or msg.cmd[0] == "reportquestion":
if len(msg.cmd) == 1:
msg.send_chn("Veuillez indiquer une raison de report")
elif Session.SESSIONS[msg.sender].question.report(' '.join(msg.cmd[1:])):
elif Session.SESSIONS[msg.realname].question.report(' '.join(msg.cmd[1:])):
msg.send_chn("Cette question vient d'être signalée.")
Session.SESSIONS[msg.sender].askNext()
Session.SESSIONS[msg.realname].askNext()
else:
msg.send_chn("Une erreur s'est produite lors du signalement de la question, veuillez recommencer plus tard.")
return True
@ -173,8 +173,8 @@ def parseanswer(msg):
return False
def parseask(msg):
if msg.sender in Session.SESSIONS:
dest = msg.sender
if msg.realname in Session.SESSIONS:
dest = msg.realname
if Session.SESSIONS[dest].question.isCorrect(msg.content):
Session.SESSIONS[dest].good += 1
@ -184,7 +184,7 @@ def parseask(msg):
Session.SESSIONS[dest].bad += 1
if Session.SESSIONS[dest].trys == 0:
Session.SESSIONS[dest].trys = 1
msg.send_chn("%s: non, essaie encore :p" % msg.sender)
msg.send_chn("%s: non, essaie encore :p" % msg.nick)
else:
askQuestion(msg, "non, la bonne reponse était : %s ; " % Session.SESSIONS[dest].question.bestAnswer)
return True
@ -195,10 +195,10 @@ def parseask(msg):
if Session.SESSIONS[dest].question.isCorrect(msg.content):
Session.SESSIONS[dest].good += 1
Session.SESSIONS[dest].score += Session.SESSIONS[dest].question.getScore(msg.content)
msg.send_chn("%s: correct :)" % msg.sender)
msg.send_chn("%s: correct :)" % msg.nick)
Session.SESSIONS[dest].prepareNext()
else:
Session.SESSIONS[dest].bad += 1
msg.send_chn("%s: non, essaie encore :p" % msg.sender)
msg.send_chn("%s: non, essaie encore :p" % msg.nick)
return True
return False

View File

@ -39,21 +39,21 @@ class GameUpdater(threading.Thread):
question = QUESTIONS[quest]["question"]
regexp = QUESTIONS[quest]["regexp"]
great = QUESTIONS[quest]["great"]
self.msg.send_chn("%s: %s" % (self.msg.sender, question))
self.msg.send_chn("%s: %s" % (self.msg.nick, question))
DELAYED[self.msg.sender] = DelayedTuple(regexp, great)
DELAYED[self.msg.nick] = DelayedTuple(regexp, great)
DELAYED[self.msg.sender].wait(20)
DELAYED[self.msg.nick].wait(20)
if DELAYED[self.msg.sender].triche(DELAYED[self.msg.sender].msg):
getUser(self.msg.sender).playTriche()
self.msg.send_chn("%s: Tricheur !" % self.msg.sender)
elif DELAYED[self.msg.sender].perfect(DELAYED[self.msg.sender].msg):
if DELAYED[self.msg.nick].triche(DELAYED[self.msg.nick].msg):
getUser(self.msg.nick).playTriche()
self.msg.send_chn("%s: Tricheur !" % self.msg.nick)
elif DELAYED[self.msg.nick].perfect(DELAYED[self.msg.nick].msg):
if random.randint(0, 10) == 1:
getUser(self.msg.sender).bonusQuestion()
self.msg.send_chn("%s: Correct !" % self.msg.sender)
getUser(self.msg.nick).bonusQuestion()
self.msg.send_chn("%s: Correct !" % self.msg.nick)
else:
self.msg.send_chn("%s: J'accepte" % self.msg.sender)
del DELAYED[self.msg.sender]
SCORES.save(self.msg.sender)
self.msg.send_chn("%s: J'accepte" % self.msg.nick)
del DELAYED[self.msg.nick]
SCORES.save(self.msg.nick)
save()

View File

@ -86,7 +86,7 @@ def parseanswer (msg):
def win(msg):
global SCORES
who = msg.sender
who = msg.nick
manche = DATAS.getNode("manche")
@ -124,9 +124,9 @@ def win(msg):
def parseask (msg):
if len(GameUpdater.DELAYED) > 0:
if msg.sender in GameUpdater.DELAYED:
GameUpdater.DELAYED[msg.sender].msg = msg.content
GameUpdater.DELAYED[msg.sender].delayEvnt.set()
if msg.nick in GameUpdater.DELAYED:
GameUpdater.DELAYED[msg.nick].msg = msg.content
GameUpdater.DELAYED[msg.nick].delayEvnt.set()
return True
return False
@ -145,79 +145,79 @@ def getUser(name):
def parselisten (msg):
if len(GameUpdater.DELAYED) > 0 and msg.sender in GameUpdater.DELAYED and GameUpdater.DELAYED[msg.sender].good(msg.content):
msg.send_chn("%s: n'oublie pas le nemubot: devant ta réponse pour qu'elle soit prise en compte !" % msg.sender)
if len(GameUpdater.DELAYED) > 0 and msg.nick in GameUpdater.DELAYED and GameUpdater.DELAYED[msg.nick].good(msg.content):
msg.send_chn("%s: n'oublie pas le nemubot: devant ta réponse pour qu'elle soit prise en compte !" % msg.nick)
bfrseen = None
if msg.realname in LASTSEEN:
bfrseen = LASTSEEN[msg.realname]
LASTSEEN[msg.realname] = datetime.now()
# if msg.channel == "#nemutest" and msg.sender not in GameUpdater.DELAYED:
if msg.channel != "#nemutest" and msg.sender not in GameUpdater.DELAYED:
# if msg.channel == "#nemutest" and msg.nick not in GameUpdater.DELAYED:
if msg.channel != "#nemutest" and msg.nick not in GameUpdater.DELAYED:
if re.match("^(42|quarante[- ]?deux).{,2}$", msg.content.strip().lower()):
if msg.time.minute == 10 and msg.time.second == 10 and msg.time.hour == 10:
getUser(msg.sender).playTen()
getUser(msg.sender).playGreat()
getUser(msg.nick).playTen()
getUser(msg.nick).playGreat()
elif msg.time.minute == 42:
if msg.time.second == 0:
getUser(msg.sender).playGreat()
getUser(msg.sender).playFtt()
getUser(msg.nick).playGreat()
getUser(msg.nick).playFtt()
else:
getUser(msg.sender).playBad()
getUser(msg.nick).playBad()
if re.match("^(23|vingt[ -]?trois).{,2}$", msg.content.strip().lower()):
if msg.time.minute == 23:
if msg.time.second == 0:
getUser(msg.sender).playGreat()
getUser(msg.sender).playTwt()
getUser(msg.nick).playGreat()
getUser(msg.nick).playTwt()
else:
getUser(msg.sender).playBad()
getUser(msg.nick).playBad()
if re.match("^(10){3}.{,2}$", msg.content.strip().lower()):
if msg.time.minute == 10 and msg.time.hour == 10:
if msg.time.second == 10:
getUser(msg.sender).playGreat()
getUser(msg.sender).playTen()
getUser(msg.nick).playGreat()
getUser(msg.nick).playTen()
else:
getUser(msg.sender).playBad()
getUser(msg.nick).playBad()
if re.match("^0?12345.{,2}$", msg.content.strip().lower()):
if msg.time.hour == 1 and msg.time.minute == 23 and (msg.time.second == 45 or (msg.time.second == 46 and msg.time.microsecond < 330000)):
getUser(msg.sender).playSuite()
getUser(msg.nick).playSuite()
else:
getUser(msg.sender).playBad()
getUser(msg.nick).playBad()
if re.match("^[1l][e3]{2}[t7] ?t?ime.{,2}$", msg.content.strip().lower()):
if msg.time.hour == 13 and msg.time.minute == 37:
if msg.time.second == 0:
getUser(msg.sender).playGreat()
getUser(msg.sender).playLeet()
getUser(msg.nick).playGreat()
getUser(msg.nick).playLeet()
else:
getUser(msg.sender).playBad()
getUser(msg.nick).playBad()
if re.match("^(pi|3.14) ?time.{,2}$", msg.content.strip().lower()):
if msg.time.hour == 3 and msg.time.minute == 14:
if msg.time.second == 15 or msg.time.second == 16:
getUser(msg.sender).playGreat()
getUser(msg.sender).playPi()
getUser(msg.nick).playGreat()
getUser(msg.nick).playPi()
else:
getUser(msg.sender).playBad()
getUser(msg.nick).playBad()
if re.match("^(404( ?time)?|time ?not ?found).{,2}$", msg.content.strip().lower()):
if msg.time.hour == 4 and msg.time.minute == 4:
if msg.time.second == 0 or msg.time.second == 4:
getUser(msg.sender).playGreat()
getUser(msg.sender).playNotfound()
getUser(msg.nick).playGreat()
getUser(msg.nick).playNotfound()
else:
getUser(msg.sender).playBad()
getUser(msg.nick).playBad()
if getUser(msg.sender).isWinner():
if getUser(msg.nick).isWinner():
print ("Nous avons un vainqueur ! Nouvelle manche :p")
win(msg)
return True
elif getUser(msg.sender).hasChanged():
elif getUser(msg.nick).hasChanged():
gu = GameUpdater.GameUpdater(msg, bfrseen)
gu.start()
return True

View File

@ -40,7 +40,7 @@ def parseanswer(msg):
def parseask(msg):
if len(DELAYED) > 0 and msg.sender == msg.srv.partner:
if len(DELAYED) > 0 and msg.nick == msg.srv.partner:
treat = False
for part in msg.content.split(';'):
if part is None:

View File

@ -50,15 +50,15 @@ def station_status(msg, station):
free = int(free[0].childNodes[0].nodeValue)
else:
free = 0
msg.send_chn("%s: à la station %s : %d vélib et %d points d'attache disponibles." % (msg.sender, station, available, free))
msg.send_chn("%s: à la station %s : %d vélib et %d points d'attache disponibles." % (msg.nick, station, available, free))
else:
msg.send_chn("%s: station %s inconnue." % (msg.sender, station))
msg.send_chn("%s: station %s inconnue." % (msg.nick, station))
def parseanswer(msg):
global DATAS
if msg.cmd[0] == "velib":
if len(msg.cmd) > 5:
msg.send_chn("%s: Demande-moi moins de stations à la fois." % msg.sender)
msg.send_chn("%s: Demande-moi moins de stations à la fois." % msg.nick)
elif len(msg.cmd) > 1:
for station in msg.cmd[1:]:
if re.match("^[0-9]{4,5}$", station):
@ -66,9 +66,9 @@ def parseanswer(msg):
elif station in DATAS.index:
station_status(msg, DATAS.index[station]["number"])
else:
msg.send_chn("%s: numéro de station invalide." % (msg.sender))
msg.send_chn("%s: numéro de station invalide." % (msg.nick))
else:
msg.send_chn("%s: Pour quelle station ?" % msg.sender)
msg.send_chn("%s: Pour quelle station ?" % msg.nick)
return True
else:
return False

View File

@ -96,7 +96,7 @@ def whoison(msg):
else:
msg.send_chn ("%s: %d personnes" % (pb, len(found)))
else:
msg.send_chn ("%s: personne ne match ta demande :(" % (msg.sender))
msg.send_chn ("%s: personne ne match ta demande :(" % (msg.nick))
DELAYED = dict()
delayEvnt = threading.Event()
@ -108,7 +108,7 @@ def whereis_msg(msg):
if len(msg.cmd) >= 2:
continue
else:
name = msg.sender
name = msg.nick
else:
names.append(name)
pasla = whereis(msg, names)
@ -187,7 +187,7 @@ def parseanswer (msg):
return False
def parseask (msg):
if len(DELAYED) > 0 and msg.sender == msg.srv.partner:
if len(DELAYED) > 0 and msg.nick == msg.srv.partner:
treat = False
for part in msg.content.split(';'):
if part is None:

View File

@ -28,14 +28,14 @@ def parseanswer(msg):
t = Tinyfier.Tinyfier(url, msg)
t.start()
else:
msg.send_chn("%s: je n'ai pas d'autre URL reduire" % msg.sender)
msg.send_chn("%s: je n'ai pas d'autre URL reduire" % msg.nick)
else:
if len(msg.cmd) < 6:
for url in msg.cmd[1:]:
t = Tinyfier.Tinyfier(url, msg)
t.start()
else:
msg.send_chn("%s: je ne peux pas réduire autant d'URL d'un seul coup." % msg.sender)
msg.send_chn("%s: je ne peux pas réduire autant d'URL d'un seul coup." % msg.nick)
return True
else:
return False

View File

@ -94,12 +94,12 @@ def speak(endstate):
action = 0
if msg.content.find("ACTION ") == 1:
sentence += msg.sender + " "
sentence += msg.nick + " "
msg.content = msg.content.replace("ACTION ", "")
action = 1
for (txt, mood) in SMILEY:
if msg.content.find(txt) >= 0:
sentence += msg.sender + (" %s : "%mood)
sentence += msg.nick + (" %s : "%mood)
msg.content = msg.content.replace(txt, "")
action = 1
break
@ -109,7 +109,7 @@ def speak(endstate):
msg.content = (" " + msg.content + " ").replace(bad, good)
if action == 0 and (force or msg.sender != lastmsg.sender):
sentence += msg.sender + " dit : "
sentence += msg.nick + " dit : "
if re.match(".*(https?://)?(www\\.)?ycc.fr/[a-z0-9A-Z]+.*", msg.content) is not None:
msg.content = re.sub("(https?://)?(www\\.)?ycc.fr/[a-z0-9A-Z]+", " U.R.L Y.C.C ", msg.content)
@ -161,7 +161,7 @@ class Server:
_thread.start_new_thread(self.connect, ())
def authorize(self, msg):
return msg.sender != OWNER and (msg.channel == OWNER or msg.channel in self.channels)
return msg.nick != OWNER and (msg.channel == OWNER or msg.channel in self.channels)
def read(self):
global stopSpk, talkEC, g_queue
@ -186,7 +186,7 @@ class Server:
if msg.cmd == b"PING":
self.s.send(("PONG %s\r\n" % msg.content).encode ())
elif msg.cmd == b"PRIVMSG" and (self.authorize(msg) or msg.content[0] == '`'):
if msg.content[0] == '`' and msg.sender == OWNER:
if msg.content[0] == '`' and msg.nick == OWNER:
cmd = msg.content[1:].split(' ')
if cmd[0] == "speak":
_thread.start_new_thread(speak, (0,))