Making on marry command asynchronous

pull/8/head
sgoudham 4 years ago
parent 3bf36caefa
commit d7dda002db

@ -8,8 +8,12 @@ from discord.ext import commands
from discord.ext.commands import BucketType, command, cooldown, bot_has_permissions from discord.ext.commands import BucketType, command, cooldown, bot_has_permissions
import db import db
from db import connection2
from settings import colour_list from settings import colour_list
loop = asyncio.get_event_loop()
loop.run_until_complete(connection2(loop))
# Sets up the embed for the marriage info # Sets up the embed for the marriage info
def marriageInfo(target, marriedUser, marriedDate, currentDate, married): def marriageInfo(target, marriedUser, marriedDate, currentDate, married):
@ -62,21 +66,18 @@ class Relationship(commands.Cog):
# Getting the guild of the user # Getting the guild of the user
guild = ctx.author.guild guild = ctx.author.guild
pool = await connection2(loop)
# Use database connection async with pool.acquire() as conn:
with db.connection() as conn: async with conn.cursor() as author_cursor:
# Get the author's/members row from the Members Table # Get the author's/members row from the Members Table
select_query = """SELECT * FROM members WHERE discordID = (?) and guildID = (?)""" select_query = """SELECT * FROM members WHERE discordID = %s and guildID = %s"""
author_val = ctx.author.id, guild.id, author_val = ctx.author.id, guild.id,
member_val = member.id, guild.id, member_val = member.id, guild.id,
# Define two cursors
with closing(conn.cursor()) as author_cursor:
# Execute the Author SQL Query # Execute the Author SQL Query
author_cursor.execute(select_query, author_val) await author_cursor.execute(select_query, author_val)
author_result = author_cursor.fetchone() author_result = await author_cursor.fetchone()
married_user = author_result[2] married_user = author_result[2]
# Make sure that the user cannot marry themselves # Make sure that the user cannot marry themselves
@ -90,10 +91,10 @@ class Relationship(commands.Cog):
return return
# Set up new cursor for member row # Set up new cursor for member row
with closing(conn.cursor()) as member_cursor: async with conn.cursor() as member_cursor:
# Execute the Member SQL Query # Execute the Member SQL Query
member_cursor.execute(select_query, member_val) await member_cursor.execute(select_query, member_val)
member_result = member_cursor.fetchone() member_result = await member_cursor.fetchone()
target_user = member_result[2] target_user = member_result[2]
if target_user is not None: if target_user is not None:

Loading…
Cancel
Save