Reddit module: Show url in response

This commit is contained in:
nemunaire 2014-05-02 00:27:42 +02:00
parent 818d8b754c
commit a0fca91d06

View File

@ -32,8 +32,8 @@ def cmd_subreddit(msg):
subs = msg.cmds[1:] subs = msg.cmds[1:]
all_res = list() all_res = list()
for sub in subs: for osub in subs:
sub = re.match(r"^/?(?:(\w)/)?(\w+)/?$", sub) sub = re.match(r"^/?(?:(\w)/)?(\w+)/?$", osub)
if sub is not None: if sub is not None:
if sub.group(1) is not None and sub.group(1) != "": if sub.group(1) is not None and sub.group(1) != "":
where = sub.group(1) where = sub.group(1)
@ -48,12 +48,14 @@ def cmd_subreddit(msg):
if "title" in sbr["data"]: if "title" in sbr["data"]:
res = Response(msg.sender, channel=msg.channel, nomore="No more information") res = Response(msg.sender, channel=msg.channel, nomore="No more information")
res.append_message(("[NSFW] " if sbr["data"]["over18"] else "") + sbr["data"]["title"] + ": " + sbr["data"]["public_description" if sbr["data"]["public_description"] != "" else "description"].replace("\n", " ") + " %s subscriber(s)" % sbr["data"]["subscribers"]) res.append_message(("[NSFW] " if sbr["data"]["over18"] else "") + sbr["data"]["url"] + " " + sbr["data"]["title"] + ": " + sbr["data"]["public_description" if sbr["data"]["public_description"] != "" else "description"].replace("\n", " ") + " %s subscriber(s)" % sbr["data"]["subscribers"])
if sbr["data"]["public_description"] != "": if sbr["data"]["public_description"] != "":
res.append_message(sbr["data"]["description"].replace("\n", " ")) res.append_message(sbr["data"]["description"].replace("\n", " "))
all_res.append(res) all_res.append(res)
else: else:
all_res.append(Response(msg.sender, "/%s/%s doesn't exist" % (where, sub.group(2)), channel=msg.channel)) all_res.append(Response(msg.sender, "/%s/%s doesn't exist" % (where, sub.group(2)), channel=msg.channel))
else:
all_res.append(Response(msg.sender, "%s is not a valid subreddit" % osub, channel=msg.channel, nick=msg.nick))
return all_res return all_res