[networking] Oops, watchWebsite wasn't working; fixed

This commit is contained in:
nemunaire 2014-12-29 07:50:27 +01:00
parent 466ec31be7
commit 17bbb000ad
2 changed files with 20 additions and 12 deletions

View File

@ -19,6 +19,7 @@ def load(context):
mod.IRCException = IRCException
mod.ModuleEvent = ModuleEvent
mod.add_event = add_event
mod.del_event = del_event
mod.save = save
mod.print = print
mod.print_debug = print_debug
@ -119,7 +120,7 @@ def cmd_watch(msg, diffType="diff"):
if len(msg.cmds) <= 1:
raise IRCException("indicate an URL to watch!")
return watchWebsite.add_site(msg.cmds[1])
return watchWebsite.add_site(msg.cmds[1], msg.frm, msg.channel, msg.server, diffType)
@hook("cmd_hook", "unwatch")
@ -127,4 +128,4 @@ def cmd_unwatch(msg):
if len(msg.cmds) <= 1:
raise IRCException("which URL should I stop watching?")
return watchWebsite.add_site(msg.cmds[1])
return watchWebsite.del_site(msg.cmds[1], msg.frm, msg.channel, msg.frm_owner)

View File

@ -6,15 +6,22 @@ from urllib.parse import urlparse
from hooks import hook
from more import Response
from tools.xmlparser.node import ModuleState
nemubotversion = 3.4
from .atom import Atom
from . import page
DATAS = None
def load(DATAS):
def load(datas):
"""Register events on watched website"""
global DATAS
DATAS = datas
DATAS.setIndex("url", "watch")
for site in DATAS.getNodes("watch"):
if site.hasNode("alert"):
@ -24,7 +31,7 @@ def load(DATAS):
#DATAS.delChild(site)
def del_site(url):
def del_site(url, nick, channel, frm_owner):
"""Remove a site from watching list
Argument:
@ -35,8 +42,8 @@ def del_site(url):
if o.scheme != "" and url in DATAS.index:
site = DATAS.index[url]
for a in site.getNodes("alert"):
if a["channel"] == msg.channel:
if not (msg.frm == a["nick"] or msg.frm_owner):
if a["channel"] == channel:
if not (nick == a["nick"] or frm_owner):
raise IRCException("you cannot unwatch this URL.")
site.delChild(a)
if not site.hasNode("alert"):
@ -44,11 +51,11 @@ def del_site(url):
DATAS.delChild(site)
save()
return Response("I don't watch this URL anymore.",
channel=msg.channel, nick=msg.nick)
channel=channel, nick=nick)
raise IRCException("I didn't watch this URL!")
def add_site(url):
def add_site(url, nick, channel, server, diffType="diff"):
"""Add a site to watching list
Argument:
@ -60,9 +67,9 @@ def add_site(url):
raise IRCException("sorry, I can't watch this URL :(")
alert = ModuleState("alert")
alert["nick"] = msg.nick
alert["server"] = msg.server
alert["channel"] = msg.channel
alert["nick"] = nick
alert["server"] = server
alert["channel"] = channel
alert["message"] = "{url} just changed!"
if url not in DATAS.index:
@ -77,7 +84,7 @@ def add_site(url):
DATAS.index[url].addChild(alert)
save()
return Response(channel=msg.channel, nick=msg.nick,
return Response(channel=channel, nick=nick,
message="this site is now under my supervision.")