Some fixes

This commit is contained in:
Némunaire 2012-05-18 11:38:50 +02:00
parent 5004752660
commit 31be5808e5
6 changed files with 119 additions and 67 deletions

View File

@ -344,6 +344,7 @@ class Message:
for im in mods.keys(): for im in mods.keys():
self.send_snd(" - !help %s: %s" % (im, mods[im].help_tiny ())) self.send_snd(" - !help %s: %s" % (im, mods[im].help_tiny ()))
else:
for im in mods.keys(): for im in mods.keys():
if im == "alias": if im == "alias":
continue continue

69
qd.py
View File

@ -13,7 +13,7 @@ from xml.dom.minidom import parseString
from xml.dom.minidom import getDOMImplementation from xml.dom.minidom import getDOMImplementation
filename = "" filename = ""
channels = "#nemutest #42sh #epitagueule" channels = "#nemutest #42sh #ykar #epitagueule"
MANCHE = None MANCHE = None
QUESTIONS = list() QUESTIONS = list()
SCORES = dict () SCORES = dict ()
@ -96,16 +96,21 @@ class Score:
if self.canPlay(): if self.canPlay():
self.bad += 1 self.bad += 1
def playTriche(self): def playTriche(self):
self.changed = True
self.bad += 5 self.bad += 5
def oupsTriche(self): def oupsTriche(self):
self.changed = True
self.bad -= 5 self.bad -= 5
def bonusQuestion(self):
self.changed = True
def toTuple(self): def toTuple(self):
return (self.ftt, self.twt, self.pi, self.notfound, self.tententen, self.leet, self.great, self.bad) return (self.ftt, self.twt, self.pi, self.notfound, self.tententen, self.leet, self.great, self.bad)
def canPlay(self): def canPlay(self):
self.changed = True ret = self.last == None or self.last.minute != datetime.now().minute or self.last.hour != datetime.now().hour or self.last.day != datetime.now().day
return self.last == None or self.last.minute != datetime.now().minute or self.last.hour != datetime.now().hour or self.last.day != datetime.now().day self.changed = self.changed or ret
return ret
def hasChanged(self): def hasChanged(self):
if self.changed: if self.changed:
@ -282,13 +287,13 @@ def getUser(name):
def parselisten (msg): def parselisten (msg):
# if msg.channel == "#nemutest" and msg.sender not in DELAYED: if len(DELAYED) > 0 and msg.sender in DELAYED and DELAYED[msg.sender].good(msg.content):
if msg.channel != "#nemutest" and msg.sender not in DELAYED:
if len(DELAYED) > 0:
if msg.sender in DELAYED and not DELAYED[msg.sender].triche(msg.content):
msg.send_chn("%s: n'oublie pas le nemubot: devant ta réponse pour qu'elle soit prise en compte !" % msg.sender) msg.send_chn("%s: n'oublie pas le nemubot: devant ta réponse pour qu'elle soit prise en compte !" % msg.sender)
if (msg.content.strip().startswith("42") and len (msg.content) < 5) or ((msg.content.strip().lower().startswith("quarante-deux") or msg.content.strip().lower().startswith("quarante deux")) and len (msg.content) < 17): # if msg.channel == "#nemutest" and msg.sender not in DELAYED:
if msg.channel != "#nemutest" and msg.sender not in 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: if msg.time.minute == 10 and msg.time.second == 10 and msg.time.hour == 10:
getUser(msg.sender).playTen() getUser(msg.sender).playTen()
getUser(msg.sender).playGreat() getUser(msg.sender).playGreat()
@ -299,7 +304,7 @@ def parselisten (msg):
else: else:
getUser(msg.sender).playBad() getUser(msg.sender).playBad()
if (msg.content.strip().startswith("23") and len (msg.content) < 5) or ((msg.content.strip().lower().startswith("vingt-trois") or msg.content.strip().lower().startswith("vingt trois")) and len (msg.content) < 14): if re.match("(23|vingt[ -]?trois).{,2}", msg.content.strip().lower()):
if msg.time.minute == 23: if msg.time.minute == 23:
if msg.time.second == 0: if msg.time.second == 0:
getUser(msg.sender).playGreat() getUser(msg.sender).playGreat()
@ -307,7 +312,7 @@ def parselisten (msg):
else: else:
getUser(msg.sender).playBad() getUser(msg.sender).playBad()
if (msg.content.strip().startswith("101010") and len (msg.content) < 9): if re.match("(10){3}.{,2}", msg.content.strip().lower()):
if msg.time.minute == 10 and msg.time.hour == 10: if msg.time.minute == 10 and msg.time.hour == 10:
if msg.time.second == 10: if msg.time.second == 10:
getUser(msg.sender).playGreat() getUser(msg.sender).playGreat()
@ -315,13 +320,13 @@ def parselisten (msg):
else: else:
getUser(msg.sender).playBad() getUser(msg.sender).playBad()
if (msg.content.strip().startswith("12345") and len (msg.content) < 8) or (msg.content.strip().startswith("012345") and len (msg.content) < 9): 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)): 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.sender).playSuite()
else: else:
getUser(msg.sender).playBad() getUser(msg.sender).playBad()
if len (msg.content) < 12 and (msg.content.strip().lower().startswith("leet time") or msg.content.strip().lower().startswith("leettime") or msg.content.strip().lower().startswith("leetime") or msg.content.strip().lower().startswith("l33t time") or msg.content.strip().lower().startswith("1337")): if re.match("[1l][e3]{2}[t7] ?time.{,2}", msg.content.strip().lower()):
if msg.time.hour == 13 and msg.time.minute == 37: if msg.time.hour == 13 and msg.time.minute == 37:
if msg.time.second == 0: if msg.time.second == 0:
getUser(msg.sender).playGreat() getUser(msg.sender).playGreat()
@ -329,7 +334,7 @@ def parselisten (msg):
else: else:
getUser(msg.sender).playBad() getUser(msg.sender).playBad()
if len (msg.content) < 11 and (msg.content.strip().lower().startswith("pi time") or msg.content.strip().lower().startswith("pitime") or msg.content.strip().lower().startswith("3.14 time")): 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.hour == 3 and msg.time.minute == 14:
if msg.time.second == 15 or msg.time.second == 16: if msg.time.second == 15 or msg.time.second == 16:
getUser(msg.sender).playGreat() getUser(msg.sender).playGreat()
@ -337,7 +342,7 @@ def parselisten (msg):
else: else:
getUser(msg.sender).playBad() getUser(msg.sender).playBad()
if len (msg.content) < 16 and (msg.content.strip().lower().startswith("time not found") or msg.content.strip().lower().startswith("timenotfound") or msg.content.strip().lower().startswith("404 time")) or (len (msg.content) < 6 and msg.content.strip().lower().startswith("404")): 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.hour == 4 and msg.time.minute == 4:
if msg.time.second == 0 or msg.time.second == 4: if msg.time.second == 0 or msg.time.second == 4:
getUser(msg.sender).playGreat() getUser(msg.sender).playGreat()
@ -358,10 +363,11 @@ def parselisten (msg):
DELAYED = dict() DELAYED = dict()
class DelayedTuple: class DelayedTuple:
def __init__(self, regexp): def __init__(self, regexp, great):
self.delayEvnt = threading.Event() self.delayEvnt = threading.Event()
self.msg = None self.msg = None
self.regexp = regexp self.regexp = regexp
self.great = great
def triche(self, res): def triche(self, res):
if res is not None: if res is not None:
@ -369,38 +375,53 @@ class DelayedTuple:
else: else:
return True return True
#<question question="Quel avion commercial est l'un des seuls a avoir volé à Mach 2 ?" regexp="(tu.[0-9]{3}|concorde|boeing|airbus)"/> def perfect(self, res):
#<question question="Quelle célébre barre est produite par Mars Incorporated ?" regexp="(mars|kite?kat|balisto|bounty|milky way|snickers|twix|skittles|freedent)"/> if res is not None:
#<question question="Quel fleuve traverse Paris ?" regexp="(seine|fion|loire|garonn?e|rhin)"/> return re.match(".*" + self.great + ".*", res.lower() + " ") is not None
#<question question="Du roman et du gothique, lequel de ces arts est le plus récent ?" regexp="(roman|gothique)"/> else:
#<question question="Quel célébre roi des éléphants, créé par Jean de Brunhoff, a épousé Céleste ?" regexp="babar"/> return False
#<question question=" ?" regexp="microprocesseur"/>
#<question question=" ?" regexp=""/> #<question question=" ?" regexp=""/>
def wait(self, timeout): def wait(self, timeout):
self.delayEvnt.wait(timeout) self.delayEvnt.wait(timeout)
LASTQUESTION = 99999
class GameUpdater(threading.Thread): class GameUpdater(threading.Thread):
def __init__(self, msg): def __init__(self, msg):
self.msg = msg self.msg = msg
threading.Thread.__init__(self) threading.Thread.__init__(self)
def run(self): def run(self):
global DELAYED, QUESTIONS global DELAYED, QUESTIONS, LASTQUESTION
quest = random.randint(0, len(QUESTIONS) * 2) rnd = random.randint(0, 3)
print (rnd)
if rnd != 2:
if self.msg.channel == "#nemutest": if self.msg.channel == "#nemutest":
quest = 9 quest = 9
else:
if LASTQUESTION >= len(QUESTIONS):
random.shuffle(QUESTIONS)
LASTQUESTION = 0
quest = LASTQUESTION
LASTQUESTION += 1
if quest < len(QUESTIONS):
(question, regexp, great) = QUESTIONS[quest] (question, regexp, great) = QUESTIONS[quest]
self.msg.send_chn("%s: %s" % (self.msg.sender, question)) self.msg.send_chn("%s: %s" % (self.msg.sender, question))
DELAYED[self.msg.sender] = DelayedTuple(regexp) DELAYED[self.msg.sender] = DelayedTuple(regexp, great)
DELAYED[self.msg.sender].wait(20) DELAYED[self.msg.sender].wait(20)
if DELAYED[self.msg.sender].triche(DELAYED[self.msg.sender].msg): if DELAYED[self.msg.sender].triche(DELAYED[self.msg.sender].msg):
getUser(self.msg.sender).playTriche() getUser(self.msg.sender).playTriche()
self.msg.send_chn("%s: Tricheur !" % self.msg.sender) self.msg.send_chn("%s: Tricheur !" % self.msg.sender)
elif DELAYED[self.msg.sender].perfect(DELAYED[self.msg.sender].msg):
if random.randint(0, 10) == 1:
getUser(self.msg.sender).bonusQuestion()
self.msg.send_chn("%s: Correct !" % self.msg.sender)
del DELAYED[self.msg.sender] del DELAYED[self.msg.sender]
save_module () save_module ()

View File

@ -99,7 +99,7 @@ class SiteSoutenances:
def findLast(self): def findLast(self):
close = None close = None
for s in self.souts: for s in self.souts:
if (s.state != "En attente" and s.start is not None and (close is None or close.rank < s.rank or close.hour.day > s.hour.day)) and (close is None or s.hour - close.hour < timedelta(seconds=1499)): if (s.state != "En attente" and s.start is not None and (close is None or close.rank < s.rank or close.hour.day > s.hour.day)) and (close is None or s.hour - close.hour < timedelta(seconds=2499)):
close = s close = s
return close return close

View File

@ -44,6 +44,10 @@ class Site:
for channel in item.getElementsByTagName('channel'): for channel in item.getElementsByTagName('channel'):
self.channels.append(channel.getAttribute("name")) self.channels.append(channel.getAttribute("name"))
self.categories = dict()
for category in item.getElementsByTagName('category'):
self.categories[category.getAttribute("term")] = category.getAttribute("part")
def start (self): def start (self):
self.thread = _thread.start_new_thread (startThread, (self,)) self.thread = _thread.start_new_thread (startThread, (self,))
@ -65,27 +69,20 @@ class Site:
diff = self.lastpage.diff (f) diff = self.lastpage.diff (f)
if len(diff) > 0: if len(diff) > 0:
print ("[%s] Page differ!"%self.server) print ("[%s] Page differ!"%self.server)
if f.id == "http://public.nbr23.com/rss.php": diff.reverse()
for d in diff: for d in diff:
if d.category == None: if self.message.count("%s") == 2 and len(self.categories) > 0:
messageI = self.message % ("quel est ce nouveau fichier", "%s") if d.category is None or d.category not in self.categories:
elif d.category == "Music": messageI = self.message % (self.categories[""], "%s")
messageI = self.message % ("quelles sont ces nouvelles musiques", "%s")
elif d.category == "TV_Shows":
messageI = self.message % ("quelle est cette nouvelle série", "%s")
elif d.category == "Movies":
messageI = self.message % ("quel est ce nouveau film", "%s")
elif d.category == "Books":
messageI = self.message % ("quel est ce nouveau livre", "%s")
else: else:
messageI = self.message % ("quel est ce nouveau fichier", "%s") messageI = self.message % (self.categories[d.category], "%s")
self.send_message (messageI % unquote (d.link)) self.send_message (messageI % unquote (d.link))
elif f.id == "http://musik.p0m.fr/atom.php?nemubot": elif self.message.count("%s") == 2:
for d in diff: if f.id == youtube.idAtom:
youtube.send_global (d.link2, self.message % (d.title, unquote (d.link))) youtube.send_global (d.link2, self.message % (d.title, unquote (d.link)))
elif self.message.find ("%s") >= 0: else:
print ("[%s] Send message!"%self.server) self.send_message (self.message % (d.title, unquote (d.link)))
for d in diff: elif self.message.count("%s") == 1:
self.send_message(self.message % unquote (d.title)) self.send_message(self.message % unquote (d.title))
else: else:
self.send_message(self.message) self.send_message(self.message)
@ -173,6 +170,9 @@ def save_module():
if len(site.channels) > 0: if len(site.channels) > 0:
for chan in site.channels: for chan in site.channels:
item.appendChild(parseString ('<channel name="%s" />' % (chan)).documentElement); item.appendChild(parseString ('<channel name="%s" />' % (chan)).documentElement);
if len(site.categories) > 0:
for categ in site.categories.keys():
item.appendChild(parseString ('<category term="%s" part="%s"/>' % (categ, site.categories[categ])).documentElement);
#print (site.server) #print (site.server)
top.appendChild(item); top.appendChild(item);

View File

@ -68,25 +68,51 @@ class User(object):
return 'cisco' return 'cisco'
elif self.ip.startswith('10.41.'): elif self.ip.startswith('10.41.'):
return 'wifi' return 'wifi'
elif self.ip.startswith('10.223.3.'):
return 'épimac'
elif self.ip.startswith('10.223.4.'):
return 'wcube'
elif self.ip.startswith('10.223.5.'):
return 'cycom'
elif self.ip.startswith('10.223.6.'):
return 'epitv'
elif self.ip.startswith('10.223.7.'):
return 'prologin'
elif self.ip.startswith('10.223'):
return 'assos'
elif self.ip.startswith('10.226.7.'):
return 'gistre'
elif self.ip.startswith('10.224.1.'):
return 'astek'
elif self.ip.startswith('10.224.2.'):
return 'acu'
elif self.ip.startswith('10.224.4.'):
return 'lse'
elif self.ip.startswith('10.224.8.'):
return 'eip'
elif self.ip.startswith('10.224.16.'):
return 'evolutek'
elif self.ip.startswith('10.224.18.'):
return 'mslab'
elif self.ip.startswith('10.2.'):
return 'adm'
elif self.ip.startswith('10.10.'):
return 'vpn'
else: else:
return None return None
@property @property
def poste(self): def poste(self):
if self.sm is None: if self.sm is None:
if self.ip.startswith('10'): if self.ip.startswith('10.'):
return 'quelque part sur le PIE (%s)'%self.ip return 'quelque part sur le PIE (%s)'%self.ip
else: else:
return "chez lui" return "chez lui"
else: else:
if self.ip.startswith('10.200'): if self.ip.startswith('10.247') or self.ip.startswith('10.248') or self.ip.startswith('10.249') or self.ip.startswith('10.250'):
sm = self.sm
if sm == "SM02":
return "en " + sm
else:
return "en " + sm + " poste " + self.ip.split('.')[3]
else:
return "en " + self.sm + " rangée " + self.ip.split('.')[2] + " poste " + self.ip.split('.')[3] return "en " + self.sm + " rangée " + self.ip.split('.')[2] + " poste " + self.ip.split('.')[3]
else:
return "en " + self.sm
def __cmp__(self, other): def __cmp__(self, other):
return cmp(self.login, other.login) return cmp(self.login, other.login)
@ -145,7 +171,7 @@ def startWhereis(msg):
if msg.cmd[0] == "peoplein": if msg.cmd[0] == "peoplein":
peoplein(msg) peoplein(msg)
elif msg.cmd[0] == "whoison": elif msg.cmd[0] == "whoison" or msg.cmd[0] == "whoisin":
whoison(msg) whoison(msg)
else: else:
whereis_msg(msg) whereis_msg(msg)
@ -177,17 +203,20 @@ def whoison(msg):
if len(msg.cmd) > 1: if len(msg.cmd) > 1:
for pb in msg.cmd: for pb in msg.cmd:
pc = pb.lower() pc = pb.lower()
if pc == "whoison": if pc == "whoison" or pc == "whoisin":
continue continue
else: else:
found = list() found = list()
print (len(datas.users)) print (len(datas.users))
for userC in datas.users: for userC in datas.users:
for user in datas.users[userC]: for user in datas.users[userC]:
if user.ip[:len(pc)] == pc or user.location.lower() == pc: if (msg.cmd[0] == "whoison" and (user.ip[:len(pc)] == pc or user.location.lower() == pc)) or (msg.cmd[0] == "whoisin" and user.sm == pc):
found.append(user.login) found.append(user.login)
if len(found) > 0: if len(found) > 0:
if len(found) <= 15: if len(found) <= 15:
if pc == "whoisin":
msg.send_chn ("En %s, il y a %s" % (pb, ", ".join(found)))
else:
msg.send_chn ("%s correspond à %s" % (pb, ", ".join(found))) msg.send_chn ("%s correspond à %s" % (pb, ", ".join(found)))
else: else:
msg.send_chn ("%s: %d personnes" % (pb, len(found))) msg.send_chn ("%s: %d personnes" % (pb, len(found)))
@ -274,7 +303,7 @@ def whereis(msg, names):
def parseanswer (msg): def parseanswer (msg):
global datas, THREAD, search global datas, THREAD, search
if msg.cmd[0] == "whereis" or msg.cmd[0] == "whereare" or msg.cmd[0] == "ouest" or msg.cmd[0] == "ousont" or msg.cmd[0] == "ip" or msg.cmd[0] == "peoplein" or msg.cmd[0] == "whoison": if msg.cmd[0] == "whereis" or msg.cmd[0] == "whereare" or msg.cmd[0] == "ouest" or msg.cmd[0] == "ousont" or msg.cmd[0] == "ip" or msg.cmd[0] == "peoplein" or msg.cmd[0] == "whoison" or msg.cmd[0] == "whoisin":
if len(msg.cmd) > 10: if len(msg.cmd) > 10:
msg.send_snd ("Demande moi moins de personnes à la fois dans ton !%s" % msg.cmd[0]) msg.send_snd ("Demande moi moins de personnes à la fois dans ton !%s" % msg.cmd[0])
return True return True

View File

@ -3,6 +3,7 @@
import re import re
import http.client import http.client
idAtom = "http://musik.p0m.fr/atom.php?nemubot"
URLS = dict () URLS = dict ()
def load_module(datas_path): def load_module(datas_path):