Remove Message.receivers, long time deprecated
This commit is contained in:
parent
ea9829b341
commit
de2e1d6216
|
@ -80,13 +80,13 @@ def gen_response(res, msg, srv):
|
||||||
LAST_URLS = dict()
|
LAST_URLS = dict()
|
||||||
|
|
||||||
|
|
||||||
@hook("msg_default")
|
@hook.message()
|
||||||
def parselisten(msg):
|
def parselisten(msg):
|
||||||
parseresponse(msg)
|
parseresponse(msg)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@hook("all_post")
|
@hook.post()
|
||||||
def parseresponse(msg):
|
def parseresponse(msg):
|
||||||
global LAST_URLS
|
global LAST_URLS
|
||||||
if hasattr(msg, "text") and msg.text:
|
if hasattr(msg, "text") and msg.text:
|
||||||
|
@ -99,7 +99,7 @@ def parseresponse(msg):
|
||||||
len(o.netloc) + len(o.path) < 17):
|
len(o.netloc) + len(o.path) < 17):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for recv in msg.receivers:
|
for recv in msg.to:
|
||||||
if recv not in LAST_URLS:
|
if recv not in LAST_URLS:
|
||||||
LAST_URLS[recv] = list()
|
LAST_URLS[recv] = list()
|
||||||
LAST_URLS[recv].append(url)
|
LAST_URLS[recv].append(url)
|
||||||
|
@ -108,7 +108,7 @@ def parseresponse(msg):
|
||||||
|
|
||||||
# MODULE INTERFACE ####################################################
|
# MODULE INTERFACE ####################################################
|
||||||
|
|
||||||
@hook("cmd_hook", "framalink",
|
@hook.command("framalink",
|
||||||
help="Reduce any long URL",
|
help="Reduce any long URL",
|
||||||
help_usage={
|
help_usage={
|
||||||
None: "Reduce the last URL said on the channel",
|
None: "Reduce the last URL said on the channel",
|
||||||
|
|
|
@ -151,7 +151,7 @@ def get_page(site, term, ssl=False, subpart=None):
|
||||||
|
|
||||||
# NEMUBOT #############################################################
|
# NEMUBOT #############################################################
|
||||||
|
|
||||||
def mediawiki_response(site, term, receivers):
|
def mediawiki_response(site, term, to):
|
||||||
ns = get_namespaces(site)
|
ns = get_namespaces(site)
|
||||||
|
|
||||||
terms = term.split("#", 1)
|
terms = term.split("#", 1)
|
||||||
|
@ -160,7 +160,7 @@ def mediawiki_response(site, term, receivers):
|
||||||
# Print the article if it exists
|
# Print the article if it exists
|
||||||
return Response(get_page(site, terms[0], subpart=terms[1] if len(terms) > 1 else None),
|
return Response(get_page(site, terms[0], subpart=terms[1] if len(terms) > 1 else None),
|
||||||
line_treat=lambda line: irc_format(parse_wikitext(site, line, ns)),
|
line_treat=lambda line: irc_format(parse_wikitext(site, line, ns)),
|
||||||
channel=receivers)
|
channel=to)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -171,11 +171,11 @@ def mediawiki_response(site, term, receivers):
|
||||||
if not len(os):
|
if not len(os):
|
||||||
os = [x for x, _ in search(site, terms[0]) if x is not None and x != ""]
|
os = [x for x, _ in search(site, terms[0]) if x is not None and x != ""]
|
||||||
return Response(os,
|
return Response(os,
|
||||||
channel=receivers,
|
channel=to,
|
||||||
title="Article not found, would you mean")
|
title="Article not found, would you mean")
|
||||||
|
|
||||||
|
|
||||||
@hook("cmd_hook", "mediawiki")
|
@hook.command("mediawiki")
|
||||||
def cmd_mediawiki(msg):
|
def cmd_mediawiki(msg):
|
||||||
"""Read an article on a MediaWiki"""
|
"""Read an article on a MediaWiki"""
|
||||||
if len(msg.args) < 2:
|
if len(msg.args) < 2:
|
||||||
|
@ -183,16 +183,16 @@ def cmd_mediawiki(msg):
|
||||||
|
|
||||||
return mediawiki_response(msg.args[0],
|
return mediawiki_response(msg.args[0],
|
||||||
" ".join(msg.args[1:]),
|
" ".join(msg.args[1:]),
|
||||||
msg.receivers)
|
msg.to_response)
|
||||||
|
|
||||||
|
|
||||||
@hook("cmd_hook", "search_mediawiki")
|
@hook.command("search_mediawiki")
|
||||||
def cmd_srchmediawiki(msg):
|
def cmd_srchmediawiki(msg):
|
||||||
"""Search an article on a MediaWiki"""
|
"""Search an article on a MediaWiki"""
|
||||||
if len(msg.args) < 2:
|
if len(msg.args) < 2:
|
||||||
raise IMException("indicate a domain and a term to search")
|
raise IMException("indicate a domain and a term to search")
|
||||||
|
|
||||||
res = Response(channel=msg.receivers, nomore="No more results", count=" (%d more results)")
|
res = Response(channel=msg.to_response, nomore="No more results", count=" (%d more results)")
|
||||||
|
|
||||||
for r in search(msg.args[0], " ".join(msg.args[1:])):
|
for r in search(msg.args[0], " ".join(msg.args[1:])):
|
||||||
res.append_message("%s: %s" % r)
|
res.append_message("%s: %s" % r)
|
||||||
|
@ -200,11 +200,11 @@ def cmd_srchmediawiki(msg):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
@hook("cmd_hook", "wikipedia")
|
@hook.command("wikipedia")
|
||||||
def cmd_wikipedia(msg):
|
def cmd_wikipedia(msg):
|
||||||
if len(msg.args) < 2:
|
if len(msg.args) < 2:
|
||||||
raise IMException("indicate a lang and a term to search")
|
raise IMException("indicate a lang and a term to search")
|
||||||
|
|
||||||
return mediawiki_response(msg.args[0] + ".wikipedia.org",
|
return mediawiki_response(msg.args[0] + ".wikipedia.org",
|
||||||
" ".join(msg.args[1:]),
|
" ".join(msg.args[1:]),
|
||||||
msg.receivers)
|
msg.to_response)
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Response:
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def receivers(self):
|
def to(self):
|
||||||
if self.channel is None:
|
if self.channel is None:
|
||||||
if self.nick is not None:
|
if self.nick is not None:
|
||||||
return [self.nick]
|
return [self.nick]
|
||||||
|
@ -60,6 +60,7 @@ class Response:
|
||||||
else:
|
else:
|
||||||
return [self.channel]
|
return [self.channel]
|
||||||
|
|
||||||
|
|
||||||
def append_message(self, message, title=None, shown_first_count=-1):
|
def append_message(self, message, title=None, shown_first_count=-1):
|
||||||
if type(message) is str:
|
if type(message) is str:
|
||||||
message = message.split('\n')
|
message = message.split('\n')
|
||||||
|
@ -140,10 +141,10 @@ class Response:
|
||||||
if self.nick:
|
if self.nick:
|
||||||
return DirectAsk(self.nick,
|
return DirectAsk(self.nick,
|
||||||
self.get_message(maxlen - len(self.nick) - 2),
|
self.get_message(maxlen - len(self.nick) - 2),
|
||||||
server=None, to=self.receivers)
|
server=None, to=self.to)
|
||||||
else:
|
else:
|
||||||
return Text(self.get_message(maxlen),
|
return Text(self.get_message(maxlen),
|
||||||
server=None, to=self.receivers)
|
server=None, to=self.to)
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -245,7 +246,7 @@ def parseresponse(res):
|
||||||
if isinstance(res, Response):
|
if isinstance(res, Response):
|
||||||
if res.server not in SERVERS:
|
if res.server not in SERVERS:
|
||||||
SERVERS[res.server] = dict()
|
SERVERS[res.server] = dict()
|
||||||
for receiver in res.receivers:
|
for receiver in res.to:
|
||||||
if receiver in SERVERS[res.server]:
|
if receiver in SERVERS[res.server]:
|
||||||
nw, bk = SERVERS[res.server][receiver]
|
nw, bk = SERVERS[res.server][receiver]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -19,7 +19,7 @@ def help_full():
|
||||||
LAST_SUBS = dict()
|
LAST_SUBS = dict()
|
||||||
|
|
||||||
|
|
||||||
@hook("cmd_hook", "subreddit")
|
@hook.command("subreddit")
|
||||||
def cmd_subreddit(msg):
|
def cmd_subreddit(msg):
|
||||||
global LAST_SUBS
|
global LAST_SUBS
|
||||||
if not len(msg.args):
|
if not len(msg.args):
|
||||||
|
@ -69,20 +69,20 @@ def cmd_subreddit(msg):
|
||||||
return all_res
|
return all_res
|
||||||
|
|
||||||
|
|
||||||
@hook("msg_default")
|
@hook.message()
|
||||||
def parselisten(msg):
|
def parselisten(msg):
|
||||||
parseresponse(msg)
|
parseresponse(msg)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@hook("all_post")
|
@hook.post()
|
||||||
def parseresponse(msg):
|
def parseresponse(msg):
|
||||||
global LAST_SUBS
|
global LAST_SUBS
|
||||||
|
|
||||||
if hasattr(msg, "text") and msg.text:
|
if hasattr(msg, "text") and msg.text:
|
||||||
urls = re.findall("www.reddit.com(/\w/\w+/?)", msg.text)
|
urls = re.findall("www.reddit.com(/\w/\w+/?)", msg.text)
|
||||||
for url in urls:
|
for url in urls:
|
||||||
for recv in msg.receivers:
|
for recv in msg.to:
|
||||||
if recv not in LAST_SUBS:
|
if recv not in LAST_SUBS:
|
||||||
LAST_SUBS[recv] = list()
|
LAST_SUBS[recv] = list()
|
||||||
LAST_SUBS[recv].append(url)
|
LAST_SUBS[recv].append(url)
|
||||||
|
|
|
@ -52,7 +52,7 @@ def _get_ytdl(links):
|
||||||
LAST_URLS = dict()
|
LAST_URLS = dict()
|
||||||
|
|
||||||
|
|
||||||
@hook("cmd_hook", "yt")
|
@hook.command("yt")
|
||||||
def get_info_yt(msg):
|
def get_info_yt(msg):
|
||||||
links = list()
|
links = list()
|
||||||
|
|
||||||
|
@ -73,13 +73,13 @@ def get_info_yt(msg):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
@hook("msg_default")
|
@hook.message()
|
||||||
def parselisten(msg):
|
def parselisten(msg):
|
||||||
parseresponse(msg)
|
parseresponse(msg)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@hook("all_post")
|
@hook.post()
|
||||||
def parseresponse(msg):
|
def parseresponse(msg):
|
||||||
global LAST_URLS
|
global LAST_URLS
|
||||||
if hasattr(msg, "text") and msg.text:
|
if hasattr(msg, "text") and msg.text:
|
||||||
|
@ -89,7 +89,7 @@ def parseresponse(msg):
|
||||||
if o.scheme != "":
|
if o.scheme != "":
|
||||||
if o.netloc == "" and len(o.path) < 10:
|
if o.netloc == "" and len(o.path) < 10:
|
||||||
continue
|
continue
|
||||||
for recv in msg.receivers:
|
for recv in msg.to:
|
||||||
if recv not in LAST_URLS:
|
if recv not in LAST_URLS:
|
||||||
LAST_URLS[recv] = list()
|
LAST_URLS[recv] = list()
|
||||||
LAST_URLS[recv].append(url)
|
LAST_URLS[recv].append(url)
|
||||||
|
|
|
@ -51,11 +51,6 @@ class Abstract:
|
||||||
return self.to
|
return self.to
|
||||||
|
|
||||||
|
|
||||||
@property
|
|
||||||
def receivers(self):
|
|
||||||
# TODO: this is for legacy modules
|
|
||||||
return self.to_response
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def channel(self):
|
def channel(self):
|
||||||
# TODO: this is for legacy modules
|
# TODO: this is for legacy modules
|
||||||
|
|
Loading…
Reference in New Issue
Block a user