From d630487336fe70fd8c1b2e80d8abf6063b18c004 Mon Sep 17 00:00:00 2001 From: Loris TICHADOU <loris.tichadou@ensiie.fr> Date: Wed, 7 Aug 2019 13:40:09 +0200 Subject: [PATCH] add quizz --- nardco.py | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/nardco.py b/nardco.py index 0e7195b..eed08f3 100755 --- a/nardco.py +++ b/nardco.py @@ -60,9 +60,14 @@ global cmdCarac cmdCarac = "$" personnalizedCmd = {} + + reponse = None pas_reponse = [] a_repondu = [] +scores = {} +tour = 0 +total = 0 def isCommande(string): global cmdCarac @@ -140,6 +145,9 @@ class Boooob(ircbot.SingleServerIRCBot): global reponse global a_repondu global pas_reponse + global tour + global scores + global total canal = ev.target() @@ -209,15 +217,43 @@ class Boooob(ircbot.SingleServerIRCBot): if "Titch" in personne and "leave" in message and "nardco" in message: serv.part(canal) - if reponse is not None and fuzz.ratio(message, reponse) > 60 and personne not in a_repondu: - serv.privmsg(canal, personne + " a trouvé la reponse : {0} ! Bien joué !".format(reponse)) - reponse = None - a_repondu = [] - pas_reponse = [] - - if reponse is not None and message in pas_reponse and personne not in a_repondu : - serv.privmsg(canal, "WRONG, {0}".format(personne)) - a_repondu.append(personne) + if reponse is not None : + if fuzz.ratio(message, reponse) > 60 and personne not in a_repondu: + serv.privmsg(canal, personne + " a trouvé la reponse : {0} ! Bien joué !".format(reponse)) + reponse = None + a_repondu = [] + pas_reponse = [] + tour+=1 + if personne in scores.keys() : + scores[personne]+=1 + else : + scores[personne] = 1 + + if tour == total + 1 : + maxScore = 0 + gagnant = '' + + for pseudo in scores.keys() : + if scores[pseudo] > maxScore : + maxScore = scores[pseudo] + gagnant = pseudo + serv.privmsg(canal, "${0} a gagné avec un score de ${1}".format(gagnant, maxScore)) + scores = {} + tour = 0 + total = 0 + else : + datas = quizz() + reponse = datas['reponse'].lower() + choix = datas['choix'] + question= datas['question'] + serv.privmsg(canal, "Question : {0}".format(question.format('utf8'))) + serv.privmsg(canal, "Choix: {0}".format(', '.join(choix).format('utf8'))) + else : + for mot in pas_reponse : + if mot.lower() in message and personne not in a_repondu : + serv.privmsg(canal, "WRONG, {0}".format(personne)) + a_repondu.append(personne) + if not is_l_heure_de_manger() and should_ban(message) : serv.privmsg(canal, "PUTAIN ON A DIT NON") -- GitLab