PEP8 clean

This commit is contained in:
nemunaire 2014-11-13 02:51:49 +01:00
commit 2dfe1f0e9a
15 changed files with 338 additions and 168 deletions

View file

@ -11,11 +11,13 @@ nemubotversion = 3.4
from hooks import hook
from more import Response
def help_full():
return "!subreddit /subreddit/: Display information on the subreddit."
LAST_SUBS = dict()
@hook("cmd_hook", "subreddit")
def cmd_subreddit(msg):
global LAST_SUBS
@ -23,7 +25,8 @@ def cmd_subreddit(msg):
if msg.channel in LAST_SUBS and len(LAST_SUBS[msg.channel]) > 0:
subs = [LAST_SUBS[msg.channel].pop()]
else:
raise IRCException("Which subreddit? Need inspiration? type !horny or !bored")
raise IRCException("Which subreddit? Need inspiration? "
"type !horny or !bored")
else:
subs = msg.cmds[1:]
@ -36,30 +39,45 @@ def cmd_subreddit(msg):
else:
where = "r"
try:
req = urllib.request.Request("http://www.reddit.com/%s/%s/about.json" % (where, sub.group(2)), headers={ 'User-Agent' : "nemubot v3" })
req = urllib.request.Request(
"http://www.reddit.com/%s/%s/about.json" %
(where, sub.group(2)),
headers={'User-Agent': "nemubot v3"})
raw = urllib.request.urlopen(req, timeout=10)
except urllib.error.HTTPError as e:
raise IRCException("HTTP error occurs: %s %s" % (e.code, e.reason))
raise IRCException("HTTP error occurs: %s %s" %
(e.code, e.reason))
sbr = json.loads(raw.read().decode())
if "title" in sbr["data"]:
res = Response(channel=msg.channel, nomore="No more information")
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"])
res = Response(channel=msg.channel,
nomore="No more information")
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"] != "":
res.append_message(sbr["data"]["description"].replace("\n", " "))
res.append_message(
sbr["data"]["description"].replace("\n", " "))
all_res.append(res)
else:
all_res.append(Response("/%s/%s doesn't exist" % (where, sub.group(2)), channel=msg.channel))
all_res.append(Response("/%s/%s doesn't exist" %
(where, sub.group(2)),
channel=msg.channel))
else:
all_res.append(Response("%s is not a valid subreddit" % osub, channel=msg.channel, nick=msg.nick))
all_res.append(Response("%s is not a valid subreddit" % osub,
channel=msg.channel, nick=msg.nick))
return all_res
@hook("msg_default")
def parselisten(msg):
parseresponse(msg)
return None
@hook("all_post")
def parseresponse(msg):
global LAST_SUBS