From 11ff68f7e7d1bc58ed985571b590d7823a75d3c5 Mon Sep 17 00:00:00 2001 From: Dan Hess Date: Sat, 23 Nov 2019 20:41:37 -0600 Subject: [PATCH] Fix database call --- cogs/osu.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cogs/osu.py b/cogs/osu.py index 2e76ddd..f765148 100644 --- a/cogs/osu.py +++ b/cogs/osu.py @@ -4,6 +4,7 @@ from discord.ext import commands import discord from osuapi import OsuApi, AHConnector +from asyncpg import UniqueViolationError # https://github.com/ppy/osu-api/wiki BASE_URL = 'https://osu.ppy.sh/api/' @@ -111,12 +112,11 @@ class Osu(commands.Cog): 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?") + try: + await ctx.bot.db.execute("INSERT INTO users (id, osu) VALUES ($1, $2)", ctx.author.id, user.username) + except UniqueViolationError: + await ctx.bot.db.execute("UPDATE users SET osu = $1 WHERE id = $2", user.username, ctx.author.id) await ctx.send("I have just saved your Osu user {}".format(author.display_name)) - update = { - "id": author.id, - "osu": user.username - } - await ctx.bot.db.upsert("users", update) @osu.command(name='score', aliases=['scores']) @utils.can_run(send_messages=True)