[V3 Image] Actually check if a client ID is set before making request (#1485)

* [V3 Image] actually check if a client id is set before making request

* Clarify imgurcreds docstring + drop guild_only from [p]imgur

* Fix the actual problem (bad urls)

* needs to be params not data
This commit is contained in:
palmtree5 2018-04-02 16:14:16 -08:00 committed by Will
parent f3db4b5cb0
commit e70e22d557

View File

@ -28,7 +28,6 @@ class Image:
self.session.close() self.session.close()
@commands.group(name="imgur") @commands.group(name="imgur")
@commands.guild_only()
async def _imgur(self, ctx): async def _imgur(self, ctx):
"""Retrieves pictures from imgur """Retrieves pictures from imgur
@ -40,10 +39,16 @@ class Image:
@_imgur.command(name="search") @_imgur.command(name="search")
async def imgur_search(self, ctx, *, term: str): async def imgur_search(self, ctx, *, term: str):
"""Searches Imgur for the specified term and returns up to 3 results""" """Searches Imgur for the specified term and returns up to 3 results"""
url = self.imgur_base_url + "time/all/0" url = self.imgur_base_url + "gallery/search/time/all/0"
params = {"q": term} params = {"q": term}
headers = {"Authorization": "Client-ID {}".format(await self.settings.imgur_client_id())} imgur_client_id = await self.settings.imgur_client_id()
async with self.session.get(url, headers=headers, data=params) as search_get: if not imgur_client_id:
await ctx.send(
_("A client ID has not been set! Please set one with {}").format(
"`{}imgurcreds`".format(ctx.prefix)))
return
headers = {"Authorization": "Client-ID {}".format(imgur_client_id)}
async with self.session.get(url, headers=headers, params=params) as search_get:
data = await search_get.json() data = await search_get.json()
if data["success"]: if data["success"]:
@ -81,9 +86,16 @@ class Image:
elif sort_type == "top": elif sort_type == "top":
sort = "top" sort = "top"
imgur_client_id = await self.settings.imgur_client_id()
if not imgur_client_id:
await ctx.send(
_("A client ID has not been set! Please set one with {}").format(
"`{}imgurcreds`".format(ctx.prefix)))
return
links = [] links = []
headers = {"Authorization": "Client-ID {}".format(await self.settings.imgur_client_id())} headers = {"Authorization": "Client-ID {}".format(imgur_client_id)}
url = self.imgur_base_url + "r/{}/{}/{}/0".format(subreddit, sort, window) url = self.imgur_base_url + "gallery/r/{}/{}/{}/0".format(subreddit, sort, window)
async with self.session.get(url, headers=headers) as sub_get: async with self.session.get(url, headers=headers) as sub_get:
data = await sub_get.json() data = await sub_get.json()
@ -111,6 +123,7 @@ class Image:
You can get these by visiting https://api.imgur.com/oauth2/addclient You can get these by visiting https://api.imgur.com/oauth2/addclient
and filling out the form. Enter a name for the application, select and filling out the form. Enter a name for the application, select
'Anonymous usage without user authorization' for the auth type, 'Anonymous usage without user authorization' for the auth type,
set the authorization callback url to 'https://localhost'
leave the app website blank, enter a valid email address, and leave the app website blank, enter a valid email address, and
enter a description. Check the box for the captcha, then click Next. enter a description. Check the box for the captcha, then click Next.
Your client ID will be on the page that loads""" Your client ID will be on the page that loads"""