Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update imgur.py #304

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions modules/imgur.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,33 @@ def imgur(self, event):
event["stdout"].write(result)
else:
raise utils.EventResultsError()

@utils.hook("received.command.rehost", channel_only=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is channel_only necessary here?

@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
Comment on lines +173 to +175
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If success is not true, then why are we saying that the upload was successful?


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")