Using cache for kiss/cuddle commands

pull/8/head
sgoudham 4 years ago
parent 9dc6ede0c9
commit 9aedb34069

@ -17,7 +17,6 @@
import datetime import datetime
import random import random
import asyncpg
from discord import Embed, Member from discord import Embed, Member
from discord.ext.commands import cooldown, command, BucketType, bot_has_permissions, Cog from discord.ext.commands import cooldown, command, BucketType, bot_has_permissions, Cog
@ -63,33 +62,16 @@ class Interactive(Cog):
kiss = True kiss = True
title = f":kissing_heart: :kissing_heart: | **{ctx.author.display_name}** kissed **{member.display_name}**" title = f":kissing_heart: :kissing_heart: | **{ctx.author.display_name}** kissed **{member.display_name}**"
# Setup pool connection # Get author record from cache/database
pool = self.bot.db result = await self.bot.check_cache(ctx.author.id, guild.id)
async with pool.acquire() as conn:
# Get the author's row from the members table married_user = result["married"]
try: if married_user is None and kiss:
select_query = """SELECT * FROM members WHERE member_id = $1 and guild_id = $2""" await ctx.send("Σ(‘◉⌓◉’) You need to be married in order to use this command! Baka!")
result = await conn.fetchrow(select_query, ctx.author.id, guild.id) return
elif not member.id == married_user and kiss:
# Catch errors await ctx.send("Σ(‘◉⌓◉’) You can only kiss your partner! Baka!")
except asyncpg.PostgresError as e: return
print("PostGres Error: Member Record Could Not Be Retrieved For Kiss Command", e)
# Checking conditions to make sure user is married/kissing their partner
else:
married_user = result["married"]
if married_user is None and kiss:
await ctx.send("Σ(‘◉⌓◉’) You need to be married in order to use this command! Baka!")
return
elif not member.id == married_user and kiss:
await ctx.send("Σ(‘◉⌓◉’) You can only kiss your partner! Baka!")
return
# Release connection back to pool
finally:
await pool.release(conn)
try: try:
# Open the file containing the kissing gifs # Open the file containing the kissing gifs
@ -131,29 +113,16 @@ class Interactive(Cog):
cuddle = True cuddle = True
title = f":blush: :blush: | **{ctx.author.display_name}** cuddled **{member.display_name}**" title = f":blush: :blush: | **{ctx.author.display_name}** cuddled **{member.display_name}**"
# Setup pool connection # Get author record from cache/database
pool = self.bot.db result = await self.bot.check_cache(ctx.author.id, guild.id)
async with pool.acquire() as conn:
married_user = result["married"]
# Get the author's row from the members table if married_user is None and cuddle:
try: await ctx.send("Σ(‘◉⌓◉’) You need to be married in order to use this command! Baka!")
select_query = """SELECT * FROM members WHERE member_id = $1 and guild_id = $2""" return
result = await conn.fetchrow(select_query, ctx.author.id, guild.id) elif not member.id == married_user and cuddle:
await ctx.send("Σ(‘◉⌓◉’) You can only cuddle your partner! Baka!")
# Catch errors return
except asyncpg.PostgresError as e:
print("PostGres Error: Member Record Could Not Be Retrieved For Cuddle Command", e)
# Checking conditions to make sure user is married/cuddling their partner
else:
married_user = result["married"]
if married_user is None and cuddle:
await ctx.send("Σ(‘◉⌓◉’) You need to be married in order to use this command! Baka!")
return
elif not member.id == married_user and cuddle:
await ctx.send("Σ(‘◉⌓◉’) You can only cuddle your partner! Baka!")
return
try: try:

Loading…
Cancel
Save