Remove legacy msg.nick

This commit is contained in:
nemunaire 2017-07-18 06:32:48 +02:00
parent 694c54a6bc
commit fde459c3ff
16 changed files with 49 additions and 55 deletions

View File

@ -185,7 +185,7 @@ def cmd_listvars(msg):
def cmd_set(msg):
if len(msg.args) < 2:
raise IMException("!set take two args: the key and the value.")
set_variable(msg.args[0], " ".join(msg.args[1:]), msg.nick)
set_variable(msg.args[0], " ".join(msg.args[1:]), msg.frm)
return Response("Variable $%s successfully defined." % msg.args[0],
channel=msg.channel)
@ -222,13 +222,13 @@ def cmd_alias(msg):
if alias.cmd in context.data.getNode("aliases").index:
return Response("%s corresponds to %s" % (alias.cmd, context.data.getNode("aliases").index[alias.cmd]["origin"]),
channel=msg.channel, nick=msg.nick)
channel=msg.channel, nick=msg.frm)
elif len(msg.args) > 1:
create_alias(alias.cmd,
" ".join(msg.args[1:]),
channel=msg.channel,
creator=msg.nick)
creator=msg.frm)
return Response("New alias %s successfully registered." % alias.cmd,
channel=msg.channel)

View File

@ -27,7 +27,7 @@ def load(context):
def findName(msg):
if (not len(msg.args) or msg.args[0].lower() == "moi" or
msg.args[0].lower() == "me"):
name = msg.nick.lower()
name = msg.frm.lower()
else:
name = msg.args[0].lower()
@ -77,7 +77,7 @@ def cmd_anniv(msg):
else:
return Response("désolé, je ne connais pas la date d'anniversaire"
" de %s. Quand est-il né ?" % name,
msg.channel, msg.nick)
msg.channel, msg.frm)
@hook.command("age",
@ -98,7 +98,7 @@ def cmd_age(msg):
msg.channel)
else:
return Response("désolé, je ne connais pas l'âge de %s."
" Quand est-il né ?" % name, msg.channel, msg.nick)
" Quand est-il né ?" % name, msg.channel, msg.frm)
return True
@ -113,11 +113,11 @@ def parseask(msg):
if extDate is None or extDate.year > datetime.now().year:
return Response("la date de naissance ne paraît pas valide...",
msg.channel,
msg.nick)
msg.frm)
else:
nick = res.group(1)
if nick == "my" or nick == "I" or nick == "i" or nick == "je" or nick == "mon" or nick == "ma":
nick = msg.nick
nick = msg.frm
if nick.lower() in context.data.index:
context.data.index[nick.lower()]["born"] = extDate
else:
@ -129,6 +129,6 @@ def parseask(msg):
return Response("ok, c'est noté, %s est né le %s"
% (nick, extDate.strftime("%A %d %B %Y à %H:%M")),
msg.channel,
msg.nick)
msg.frm)
except:
raise IMException("la date de naissance ne paraît pas valide.")

View File

@ -69,7 +69,7 @@ def start_countdown(msg):
strnd = ModuleState("strend")
strnd["server"] = msg.server
strnd["channel"] = msg.channel
strnd["proprio"] = msg.nick
strnd["proprio"] = msg.frm
strnd["start"] = msg.date
strnd["name"] = msg.args[0]
context.data.addChild(strnd)
@ -145,17 +145,17 @@ def end_countdown(msg):
raise IMException("quel événement terminer ?")
if msg.args[0] in context.data.index:
if context.data.index[msg.args[0]]["proprio"] == msg.nick or (msg.cmd == "forceend" and msg.frm_owner):
if context.data.index[msg.args[0]]["proprio"] == msg.frm or (msg.cmd == "forceend" and msg.frm_owner):
duration = countdown(msg.date - context.data.index[msg.args[0]].getDate("start"))
context.del_event(context.data.index[msg.args[0]]["_id"])
context.data.delChild(context.data.index[msg.args[0]])
context.save()
return Response("%s a duré %s." % (msg.args[0], duration),
channel=msg.channel, nick=msg.nick)
channel=msg.channel, nick=msg.frm)
else:
raise IMException("Vous ne pouvez pas terminer le compteur %s, créé par %s." % (msg.args[0], context.data.index[msg.args[0]]["proprio"]))
else:
return Response("%s n'est pas un compteur connu."% (msg.args[0]), channel=msg.channel, nick=msg.nick)
return Response("%s n'est pas un compteur connu."% (msg.args[0]), channel=msg.channel, nick=msg.frm)
@hook.command("eventslist")
@ -180,7 +180,7 @@ def parseanswer(msg):
# Avoid message starting by ! which can be interpreted as command by other bots
if msg.cmd[0] == "!":
res.nick = msg.nick
res.nick = msg.frm
if context.data.index[msg.cmd].name == "strend":
if context.data.index[msg.cmd].hasAttribute("end"):
@ -223,7 +223,7 @@ def parseask(msg):
evt = ModuleState("event")
evt["server"] = msg.server
evt["channel"] = msg.channel
evt["proprio"] = msg.nick
evt["proprio"] = msg.frm
evt["name"] = name.group(1)
evt["start"] = extDate
evt["msg_after"] = msg_after
@ -237,7 +237,7 @@ def parseask(msg):
evt = ModuleState("event")
evt["server"] = msg.server
evt["channel"] = msg.channel
evt["proprio"] = msg.nick
evt["proprio"] = msg.frm
evt["name"] = name.group(1)
evt["msg_before"] = texts.group (2)
context.data.addChild(evt)

View File

@ -55,7 +55,7 @@ def cmd_geocode(msg):
if not len(msg.args):
raise IMException("indicate a name")
res = Response(channel=msg.channel, nick=msg.nick,
res = Response(channel=msg.channel, nick=msg.frm,
nomore="No more geocode", count=" (%s more geocode)")
for loc in geocode(' '.join(msg.args)):

View File

@ -64,7 +64,7 @@ def cmd_subreddit(msg):
channel=msg.channel))
else:
all_res.append(Response("%s is not a valid subreddit" % osub,
channel=msg.channel, nick=msg.nick))
channel=msg.channel, nick=msg.frm))
return all_res

View File

@ -21,7 +21,7 @@ def cmd_choice(msg):
return Response(random.choice(msg.args),
channel=msg.channel,
nick=msg.nick)
nick=msg.frm)
@hook.command("choicecmd")

View File

@ -73,9 +73,9 @@ def cmd_sms(msg):
fails.append( "%s: %s" % (u, test) )
if len(fails) > 0:
return Response("quelque chose ne s'est pas bien passé durant l'envoi du SMS : " + ", ".join(fails), msg.channel, msg.nick)
return Response("quelque chose ne s'est pas bien passé durant l'envoi du SMS : " + ", ".join(fails), msg.channel, msg.frm)
else:
return Response("le SMS a bien été envoyé", msg.channel, msg.nick)
return Response("le SMS a bien été envoyé", msg.channel, msg.frm)
apiuser_ask = re.compile(r"(utilisateur|user|numéro|numero|compte|abonne|abone|abonné|account)\s+(est|is)\s+(?P<user>[0-9]{7,})", re.IGNORECASE)
apikey_ask = re.compile(r"(clef|key|password|mot de passe?)\s+(?:est|is)?\s+(?P<key>[a-zA-Z0-9]{10,})", re.IGNORECASE)
@ -94,18 +94,18 @@ def parseask(msg):
test = send_sms("nemubot", apiuser, apikey,
"Vous avez enregistré vos codes d'authentification dans nemubot, félicitation !")
if test is not None:
return Response("je n'ai pas pu enregistrer tes identifiants : %s" % test, msg.channel, msg.nick)
return Response("je n'ai pas pu enregistrer tes identifiants : %s" % test, msg.channel, msg.frm)
if msg.nick in context.data.index:
context.data.index[msg.nick]["user"] = apiuser
context.data.index[msg.nick]["key"] = apikey
if msg.frm in context.data.index:
context.data.index[msg.frm]["user"] = apiuser
context.data.index[msg.frm]["key"] = apikey
else:
ms = ModuleState("phone")
ms.setAttribute("name", msg.nick)
ms.setAttribute("name", msg.frm)
ms.setAttribute("user", apiuser)
ms.setAttribute("key", apikey)
ms.setAttribute("lastuse", 0)
context.data.addChild(ms)
context.save()
return Response("ok, c'est noté. Je t'ai envoyé un SMS pour tester ;)",
msg.channel, msg.nick)
msg.channel, msg.frm)

View File

@ -64,15 +64,15 @@ def cmd_spell(msg):
raise IMException("Je n'ai pas le dictionnaire `%s' :(" % lang)
if r == True:
add_score(msg.nick, "correct")
add_score(msg.frm, "correct")
res.append_message("l'orthographe de `%s' est correcte" % word)
elif len(r) > 0:
add_score(msg.nick, "bad")
add_score(msg.frm, "bad")
res.append_message(r, title="suggestions pour `%s'" % word)
else:
add_score(msg.nick, "bad")
add_score(msg.frm, "bad")
res.append_message("aucune suggestion pour `%s'" % word)
return res

View File

@ -80,7 +80,7 @@ def cmd_flight(msg):
if not len(msg.args):
raise IMException("please indicate a flight")
res = Response(channel=msg.channel, nick=msg.nick,
res = Response(channel=msg.channel, nick=msg.frm,
nomore="No more flights", count=" (%s more flights)")
for param in msg.args:

View File

@ -220,4 +220,4 @@ def parseask(msg):
context.data.addChild(ms)
context.save()
return Response("ok, j'ai bien noté les coordonnées de %s" % res.group("city"),
msg.channel, msg.nick)
msg.channel, msg.frm)

View File

@ -152,7 +152,7 @@ def parseask(msg):
nick = res.group(1)
login = res.group(3)
if nick == "my" or nick == "I" or nick == "i" or nick == "je" or nick == "mon" or nick == "ma":
nick = msg.nick
nick = msg.frm
if nick in context.data.getNode("aliases").index:
context.data.getNode("aliases").index[nick]["to"] = login
else:
@ -164,4 +164,4 @@ def parseask(msg):
return Response("ok, c'est noté, %s est %s"
% (nick, login),
channel=msg.channel,
nick=msg.nick)
nick=msg.frm)

View File

@ -32,7 +32,7 @@ def start_watch(msg):
w = ModuleState("watch")
w["server"] = msg.server
w["channel"] = msg.channel
w["proprio"] = msg.nick
w["proprio"] = msg.frm
w["start"] = datetime.now(timezone.utc)
context.data.addChild(w)
context.save()

View File

@ -92,7 +92,7 @@ class Bot(threading.Thread):
def in_echo(msg):
from nemubot.message import Text
return Text(msg.nick + ": " + " ".join(msg.args), to=msg.to_response)
return Text(msg.frm + ": " + " ".join(msg.args), to=msg.to_response)
self.treater.hm.add_hook(nemubot.hooks.Command(in_echo, "echo"), "in", "Command")
def _help_msg(msg):

View File

@ -52,11 +52,11 @@ class Channel:
elif cmd == "MODE":
self.mode(msg)
elif cmd == "JOIN":
self.join(msg.nick)
self.join(msg.frm)
elif cmd == "NICK":
self.nick(msg.nick, msg.text)
self.nick(msg.frm, msg.text)
elif cmd == "PART" or cmd == "QUIT":
self.part(msg.nick)
self.part(msg.frm)
elif cmd == "TOPIC":
self.topic = self.text
@ -120,17 +120,17 @@ class Channel:
else:
self.password = msg.text[1]
elif msg.text[0] == "+o":
self.people[msg.nick] |= 4
self.people[msg.frm] |= 4
elif msg.text[0] == "-o":
self.people[msg.nick] &= ~4
self.people[msg.frm] &= ~4
elif msg.text[0] == "+h":
self.people[msg.nick] |= 2
self.people[msg.frm] |= 2
elif msg.text[0] == "-h":
self.people[msg.nick] &= ~2
self.people[msg.frm] &= ~2
elif msg.text[0] == "+v":
self.people[msg.nick] |= 1
self.people[msg.frm] |= 1
elif msg.text[0] == "-v":
self.people[msg.nick] &= ~1
self.people[msg.frm] &= ~1
def parse332(self, msg):
"""Parse RPL_TOPIC message

View File

@ -59,12 +59,6 @@ class Abstract:
else:
return None
@property
def nick(self):
# TODO: this is for legacy modules
return self.frm
def accept(self, visitor):
visitor.visit(self)

View File

@ -174,10 +174,10 @@ class _IRC:
for chname in msg.params[0].split(b","):
if chname in self.channels:
if msg.nick == self.nick:
if msg.frm == self.nick:
del self.channels[chname]
elif msg.nick in self.channels[chname].people:
del self.channels[chname].people[msg.nick]
elif msg.frm in self.channels[chname].people:
del self.channels[chname].people[msg.frm]
self.hookscmd["PART"] = _on_part
# Respond to 331/RPL_NOTOPIC,332/RPL_TOPIC,TOPIC
def _on_topic(msg):
@ -227,7 +227,7 @@ class _IRC:
else:
res = "ERRMSG Unknown or unimplemented CTCP request"
if res is not None:
self.write("NOTICE %s :\x01%s\x01" % (msg.nick, res))
self.write("NOTICE %s :\x01%s\x01" % (msg.frm, res))
self.hookscmd["PRIVMSG"] = _on_ctcp