From 1b05b965ed76d3e7e9b802689cc645cad08e4c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=A9munaire?= Date: Wed, 2 Jan 2013 15:48:42 +0100 Subject: [PATCH] Spell module: remember correct and bad spelling by people --- modules/spell/__init__.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/modules/spell/__init__.py b/modules/spell/__init__.py index 966f006..c4c344e 100644 --- a/modules/spell/__init__.py +++ b/modules/spell/__init__.py @@ -15,9 +15,13 @@ def help_full (): return "!spell [] : give the correct spelling of in ." def load(context): + global DATAS + DATAS.setIndex("name", "score") + from hooks import Hook add_hook("cmd_hook", Hook(cmd_spell, "spell")) add_hook("cmd_hook", Hook(cmd_spell, "orthographe")) + add_hook("cmd_hook", Hook(cmd_score, "spellscore")) def cmd_spell(msg): @@ -35,13 +39,46 @@ def cmd_spell(msg): except AspellError: return Response(msg.sender, "Je n'ai pas le dictionnaire `%s' :(" % lang, msg.channel) if r == True: + add_score(msg.nick, "correct") strRes.append("l'orthographe de `%s' est correcte" % word) elif len(r) > 0: + add_score(msg.nick, "bad") strRes.append("suggestions pour `%s' : %s" % (word, ", ".join(r))) else: + add_score(msg.nick, "bad") strRes.append("aucune suggestion pour `%s'" % word) return Response(msg.sender, strRes, channel=msg.channel) +def add_score(nick, t): + global DATAS + if nick not in DATAS.index: + st = ModuleState("score") + st["name"] = nick + DATAS.addChild(st) + + if DATAS.index[nick].hasAttribute(t): + DATAS.index[nick][t] = DATAS.index[nick].getInt(t) + 1 + else: + DATAS.index[nick][t] = 1 + save() + +def cmd_score(msg): + global DATAS + res = list() + unknown = list() + if len(msg.cmds) > 1: + for cmd in msg.cmds[1:]: + if cmd in DATAS.index: + res.append(Response(msg.sender, "%s: %s" % (cmd, " ; ".join(["%s: %d" % (a, DATAS.index[cmd].getInt(a)) for a in DATAS.index[cmd].attributes.keys() if a != "name"])), channel=msg.channel)) + else: + unknown.append(cmd) + else: + return Response(msg.sender, "De qui veux-tu voir les scores ?", channel=msg.channel, nick=msg.nick) + if len(unknown) > 0: + res.append(Response(msg.sender, "%s inconnus" % ", ".join(unknown), channel=msg.channel)) + + return res + def check_spell(word, lang='fr'): a = Aspell(("lang", lang)) if a.check(word):