[networking] Oops, watchWebsite wasn't working; fixed
This commit is contained in:
parent
466ec31be7
commit
17bbb000ad
@ -19,6 +19,7 @@ def load(context):
|
|||||||
mod.IRCException = IRCException
|
mod.IRCException = IRCException
|
||||||
mod.ModuleEvent = ModuleEvent
|
mod.ModuleEvent = ModuleEvent
|
||||||
mod.add_event = add_event
|
mod.add_event = add_event
|
||||||
|
mod.del_event = del_event
|
||||||
mod.save = save
|
mod.save = save
|
||||||
mod.print = print
|
mod.print = print
|
||||||
mod.print_debug = print_debug
|
mod.print_debug = print_debug
|
||||||
@ -119,7 +120,7 @@ def cmd_watch(msg, diffType="diff"):
|
|||||||
if len(msg.cmds) <= 1:
|
if len(msg.cmds) <= 1:
|
||||||
raise IRCException("indicate an URL to watch!")
|
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")
|
@hook("cmd_hook", "unwatch")
|
||||||
@ -127,4 +128,4 @@ def cmd_unwatch(msg):
|
|||||||
if len(msg.cmds) <= 1:
|
if len(msg.cmds) <= 1:
|
||||||
raise IRCException("which URL should I stop watching?")
|
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)
|
||||||
|
@ -6,15 +6,22 @@ from urllib.parse import urlparse
|
|||||||
|
|
||||||
from hooks import hook
|
from hooks import hook
|
||||||
from more import Response
|
from more import Response
|
||||||
|
from tools.xmlparser.node import ModuleState
|
||||||
|
|
||||||
nemubotversion = 3.4
|
nemubotversion = 3.4
|
||||||
|
|
||||||
from .atom import Atom
|
from .atom import Atom
|
||||||
from . import page
|
from . import page
|
||||||
|
|
||||||
|
DATAS = None
|
||||||
|
|
||||||
def load(DATAS):
|
|
||||||
|
def load(datas):
|
||||||
"""Register events on watched website"""
|
"""Register events on watched website"""
|
||||||
|
|
||||||
|
global DATAS
|
||||||
|
DATAS = datas
|
||||||
|
|
||||||
DATAS.setIndex("url", "watch")
|
DATAS.setIndex("url", "watch")
|
||||||
for site in DATAS.getNodes("watch"):
|
for site in DATAS.getNodes("watch"):
|
||||||
if site.hasNode("alert"):
|
if site.hasNode("alert"):
|
||||||
@ -24,7 +31,7 @@ def load(DATAS):
|
|||||||
#DATAS.delChild(site)
|
#DATAS.delChild(site)
|
||||||
|
|
||||||
|
|
||||||
def del_site(url):
|
def del_site(url, nick, channel, frm_owner):
|
||||||
"""Remove a site from watching list
|
"""Remove a site from watching list
|
||||||
|
|
||||||
Argument:
|
Argument:
|
||||||
@ -35,8 +42,8 @@ def del_site(url):
|
|||||||
if o.scheme != "" and url in DATAS.index:
|
if o.scheme != "" and url in DATAS.index:
|
||||||
site = DATAS.index[url]
|
site = DATAS.index[url]
|
||||||
for a in site.getNodes("alert"):
|
for a in site.getNodes("alert"):
|
||||||
if a["channel"] == msg.channel:
|
if a["channel"] == channel:
|
||||||
if not (msg.frm == a["nick"] or msg.frm_owner):
|
if not (nick == a["nick"] or frm_owner):
|
||||||
raise IRCException("you cannot unwatch this URL.")
|
raise IRCException("you cannot unwatch this URL.")
|
||||||
site.delChild(a)
|
site.delChild(a)
|
||||||
if not site.hasNode("alert"):
|
if not site.hasNode("alert"):
|
||||||
@ -44,11 +51,11 @@ def del_site(url):
|
|||||||
DATAS.delChild(site)
|
DATAS.delChild(site)
|
||||||
save()
|
save()
|
||||||
return Response("I don't watch this URL anymore.",
|
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!")
|
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
|
"""Add a site to watching list
|
||||||
|
|
||||||
Argument:
|
Argument:
|
||||||
@ -60,9 +67,9 @@ def add_site(url):
|
|||||||
raise IRCException("sorry, I can't watch this URL :(")
|
raise IRCException("sorry, I can't watch this URL :(")
|
||||||
|
|
||||||
alert = ModuleState("alert")
|
alert = ModuleState("alert")
|
||||||
alert["nick"] = msg.nick
|
alert["nick"] = nick
|
||||||
alert["server"] = msg.server
|
alert["server"] = server
|
||||||
alert["channel"] = msg.channel
|
alert["channel"] = channel
|
||||||
alert["message"] = "{url} just changed!"
|
alert["message"] = "{url} just changed!"
|
||||||
|
|
||||||
if url not in DATAS.index:
|
if url not in DATAS.index:
|
||||||
@ -77,7 +84,7 @@ def add_site(url):
|
|||||||
DATAS.index[url].addChild(alert)
|
DATAS.index[url].addChild(alert)
|
||||||
|
|
||||||
save()
|
save()
|
||||||
return Response(channel=msg.channel, nick=msg.nick,
|
return Response(channel=channel, nick=nick,
|
||||||
message="this site is now under my supervision.")
|
message="this site is now under my supervision.")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user