Check if a url is a gallery first, 'event' -> 'data' typo, actually return from

_prefix
This commit is contained in:
jesopo 2018-10-31 17:54:44 +00:00
parent 04e369a92d
commit 18d055bb9e

View file

@ -16,6 +16,7 @@ class Module(ModuleManager.BaseModule):
text += "[NSFW] " text += "[NSFW] "
if data["account_url"]: if data["account_url"]:
text += "%s " % data["account_url"] text += "%s " % data["account_url"]
return text
def _image_info(self, hash): def _image_info(self, hash):
api_key = self.bot.config["imgur-api-key"] api_key = self.bot.config["imgur-api-key"]
@ -30,7 +31,7 @@ class Module(ModuleManager.BaseModule):
text += "(%s %dx%d, %d views)" % (data["type"], data["width"], text += "(%s %dx%d, %d views)" % (data["type"], data["width"],
data["height"], data["views"]) data["height"], data["views"])
if data["title"]: if data["title"]:
text += data["title"] text += " %s" % data["title"]
return text return text
else: else:
raise utils.EventsResultsError() raise utils.EventsResultsError()
@ -44,10 +45,10 @@ class Module(ModuleManager.BaseModule):
if result and result["success"]: if result and result["success"]:
data = result["data"] data = result["data"]
text = self._prefix(data) text = self._prefix(data)
text += "(%d views, %d▲▼%d)" % (event["views"], text += "(%d views, %d▲▼%d)" % (data["views"],
event["ups"], event["downs"]) data["ups"], data["downs"])
if data["title"]: if data["title"]:
text += data["title"] text += " %s" % data["title"]
return text return text
else: else:
raise utils.EventsResultsError() raise utils.EventsResultsError()
@ -58,9 +59,11 @@ class Module(ModuleManager.BaseModule):
:help: Get information about a given imgur image URL :help: Get information about a given imgur image URL
:usage: <url> :usage: <url>
""" """
match = REGEX_IMAGE.match(event["args_split"][0])
if match:
event["stdout"].write(self._image_info(match.group(1)))
match = REGEX_GALLERY.match(event["args_split"][0]) match = REGEX_GALLERY.match(event["args_split"][0])
if match: if match:
event["stdout"].write(self._gallery_info(match.group(1))) event["stdout"].write(self._gallery_info(match.group(1)))
return
match = REGEX_IMAGE.match(event["args_split"][0])
if match:
event["stdout"].write(self._image_info(match.group(1)))
return