Handle an error where the OSU api literally doesn't return anything
This commit is contained in:
parent
edb0f8ac2c
commit
c8da4839a8
11
cogs/osu.py
11
cogs/osu.py
|
@ -27,6 +27,9 @@ class Osu(commands.Cog):
|
||||||
if user is not None:
|
if user is not None:
|
||||||
self.osu_users[member.id] = user
|
self.osu_users[member.id] = user
|
||||||
return user
|
return user
|
||||||
|
# Just return False for the "osu API does not work correctly" issue
|
||||||
|
elif user is False:
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
if user.username.lower() == username.lower():
|
if user.username.lower() == username.lower():
|
||||||
return user
|
return user
|
||||||
|
@ -43,6 +46,9 @@ class Osu(commands.Cog):
|
||||||
return user[0]
|
return user[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
# So we can send a specific message for this error
|
||||||
|
except TypeError:
|
||||||
|
return False
|
||||||
|
|
||||||
async def get_users(self):
|
async def get_users(self):
|
||||||
"""A task used to 'cache' all member's and their Osu profile's"""
|
"""A task used to 'cache' all member's and their Osu profile's"""
|
||||||
|
@ -53,7 +59,7 @@ class Osu(commands.Cog):
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
user = await self.get_user_from_api(row['osu'])
|
user = await self.get_user_from_api(row['osu'])
|
||||||
if user:
|
if user is not None:
|
||||||
self.osu_users[row['id']] = user
|
self.osu_users[row['id']] = user
|
||||||
|
|
||||||
@commands.group(invoke_without_command=True)
|
@commands.group(invoke_without_command=True)
|
||||||
|
@ -101,6 +107,9 @@ class Osu(commands.Cog):
|
||||||
if user is None:
|
if user is None:
|
||||||
await ctx.send("I couldn't find an osu user that matches {}".format(username))
|
await ctx.send("I couldn't find an osu user that matches {}".format(username))
|
||||||
return
|
return
|
||||||
|
elif user is False:
|
||||||
|
await ctx.send("Unfortunately OSU's API is a 'beta', and for some users they do not return **any** data."
|
||||||
|
"In this case, that's you! Congrats?")
|
||||||
|
|
||||||
await ctx.send("I have just saved your Osu user {}".format(author.display_name))
|
await ctx.send("I have just saved your Osu user {}".format(author.display_name))
|
||||||
update = {
|
update = {
|
||||||
|
|
Loading…
Reference in a new issue