Remove bold title, set NSFW_TEXT variable, fix bold spacing, fix PEP8 line breaks between definitions. Remove _imgur def and hook straight into code.
This commit is contained in:
parent
0444f9c0b9
commit
4daba2b1ac
1 changed files with 8 additions and 12 deletions
|
@ -10,6 +10,8 @@ REGEX_GALLERY = re.compile("https?://imgur.com/gallery/(\w+)")
|
||||||
URL_IMAGE = "https://api.imgur.com/3/image/%s"
|
URL_IMAGE = "https://api.imgur.com/3/image/%s"
|
||||||
URL_GALLERY = "https://api.imgur.com/3/gallery/%s"
|
URL_GALLERY = "https://api.imgur.com/3/gallery/%s"
|
||||||
|
|
||||||
|
NSFW_TEXT = "(NSFW)"
|
||||||
|
|
||||||
@utils.export("channelset", {"setting": "auto-imgur",
|
@utils.export("channelset", {"setting": "auto-imgur",
|
||||||
"help": "Disable/Enable automatically getting info from Imgur URLs",
|
"help": "Disable/Enable automatically getting info from Imgur URLs",
|
||||||
"validate": utils.bool_or_none})
|
"validate": utils.bool_or_none})
|
||||||
|
@ -28,9 +30,6 @@ class Module(ModuleManager.BaseModule):
|
||||||
if not event["channel"].get_setting("auto-imgur", False):
|
if not event["channel"].get_setting("auto-imgur", False):
|
||||||
return
|
return
|
||||||
|
|
||||||
self._imgur(event)
|
|
||||||
|
|
||||||
def _imgur(self, event):
|
|
||||||
msg = event["message"]
|
msg = event["message"]
|
||||||
reply = ""
|
reply = ""
|
||||||
match_gallery = REGEX_GALLERY.match(msg)
|
match_gallery = REGEX_GALLERY.match(msg)
|
||||||
|
@ -47,8 +46,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
event.eat()
|
event.eat()
|
||||||
|
|
||||||
self.events.on("send.stdout").call(target=event[
|
self.events.on("send.stdout").call(target=event["channel"], module_name="Imgur", server=event["server"],
|
||||||
"channel"], module_name="Imgur", server=event["server"],
|
|
||||||
message=reply)
|
message=reply)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -62,15 +60,15 @@ class Module(ModuleManager.BaseModule):
|
||||||
data = result.data["data"]
|
data = result.data["data"]
|
||||||
text = ""
|
text = ""
|
||||||
|
|
||||||
nsfw = utils.irc.bold("[NSFW] ") if data["nsfw"] else ""
|
nsfw = utils.irc.bold(NSFW_TEXT) + " " if data["nsfw"] else ""
|
||||||
title = utils.irc.bold(data["title"]) + " " if data["title"] else ""
|
title = data["title"] + " " if data["title"] else ""
|
||||||
views = data["views"]
|
views = data["views"]
|
||||||
time = datetime.utcfromtimestamp(data["datetime"]). \
|
time = datetime.utcfromtimestamp(data["datetime"]). \
|
||||||
strftime("%e %b, %Y at %H:%M")
|
strftime("%e %b, %Y at %H:%M")
|
||||||
ups = utils.irc.color(str(data["ups"]) + "▲", utils.consts.GREEN)
|
ups = utils.irc.color(str(data["ups"]) + "▲", utils.consts.GREEN)
|
||||||
downs = utils.irc.color("▼" + str(data["downs"]), utils.consts.RED)
|
downs = utils.irc.color("▼" + str(data["downs"]), utils.consts.RED)
|
||||||
images = data["images_count"]
|
images = data["images_count"]
|
||||||
image_plural = "" if images is 1 else "s"
|
image_plural = "" if images == 1 else "s"
|
||||||
|
|
||||||
bracket_left = "(" if title or nsfw else ""
|
bracket_left = "(" if title or nsfw else ""
|
||||||
bracket_right = ")" if title or nsfw else ""
|
bracket_right = ")" if title or nsfw else ""
|
||||||
|
@ -91,8 +89,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
data = result.data["data"]
|
data = result.data["data"]
|
||||||
text = ""
|
text = ""
|
||||||
|
|
||||||
nsfw = utils.irc.bold("[NSFW] ") if data["nsfw"] else ""
|
nsfw = utils.irc.bold(NSFW_TEXT) + " " if data["nsfw"] else ""
|
||||||
title = utils.irc.bold(data["title"]) + " " if data["title"] else ""
|
title = data["title"] + " " if data["title"] else ""
|
||||||
type = data["type"].split("/")[-1]
|
type = data["type"].split("/")[-1]
|
||||||
width = data["width"]
|
width = data["width"]
|
||||||
height = data["height"]
|
height = data["height"]
|
||||||
|
@ -109,8 +107,6 @@ class Module(ModuleManager.BaseModule):
|
||||||
(nsfw, title, bracket_left, type, width, height, views, time,
|
(nsfw, title, bracket_left, type, width, height, views, time,
|
||||||
bracket_right)
|
bracket_right)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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"]
|
||||||
result = utils.http.request(URL_IMAGE % hash,
|
result = utils.http.request(URL_IMAGE % hash,
|
||||||
|
|
Loading…
Reference in a new issue