From ebf9333256094c54cb7d344d6b845397bd8b3b57 Mon Sep 17 00:00:00 2001 From: dongfix Date: Sat, 6 Mar 2021 21:30:48 +0000 Subject: [PATCH] Update imgur.py Add $rehost feature to rehost any image/video url (under 10mb) to imgur, anonymously. Only works if user has the "rehost" or "*" permissions. --- modules/imgur.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/modules/imgur.py b/modules/imgur.py index 35bb6329..f84baa94 100644 --- a/modules/imgur.py +++ b/modules/imgur.py @@ -150,3 +150,33 @@ def imgur(self, event): event["stdout"].write(result) else: raise utils.EventResultsError() + + @utils.hook("received.command.rehost", channel_only=True) + @utils.kwarg("permission", "rehost") + def rehost(self, event): + channel = event["target"] + args = event["args_split"] + + if len(args) is not 1: + event["stderr"].write("You must provide exactly one link to rehost.") + return + + url = args[0] + + page = utils.http.request( + URL_REHOST, + method="POST", + headers={"Authorization": "Basic %s" % self.bot.config["imgur-api-key"]}, + post_data={"image": url, "type": "url"}, + ).json() + + if page["success"] is not True: + event["stderr"].write("Image upload successful") + return + + upload = page["data"] + + if upload["link"] is not "": + event["stdout"].write("Your image was rehosted. URL: %s" % upload["link"]) + else: + event["stderr"].write("Image upload unsuccessful")