Using cache for kiss/cuddle commands

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

@ -17,7 +17,6 @@
import datetime
import random
import asyncpg
from discord import Embed, Member
from discord.ext.commands import cooldown, command, BucketType, bot_has_permissions, Cog
@ -63,23 +62,10 @@ class Interactive(Cog):
kiss = True
title = f":kissing_heart: :kissing_heart: | **{ctx.author.display_name}** kissed **{member.display_name}**"
# Setup pool connection
pool = self.bot.db
async with pool.acquire() as conn:
# Get author record from cache/database
result = await self.bot.check_cache(ctx.author.id, guild.id)
# Get the author's row from the members table
try:
select_query = """SELECT * FROM members WHERE member_id = $1 and guild_id = $2"""
result = await conn.fetchrow(select_query, ctx.author.id, guild.id)
# Catch errors
except asyncpg.PostgresError as e:
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
@ -87,10 +73,6 @@ class Interactive(Cog):
await ctx.send("Σ(‘◉⌓◉’) You can only kiss your partner! Baka!")
return
# Release connection back to pool
finally:
await pool.release(conn)
try:
# Open the file containing the kissing gifs
with open('images/FunCommands/kissing.txt') as file:
@ -131,23 +113,10 @@ class Interactive(Cog):
cuddle = True
title = f":blush: :blush: | **{ctx.author.display_name}** cuddled **{member.display_name}**"
# Setup pool connection
pool = self.bot.db
async with pool.acquire() as conn:
# Get author record from cache/database
result = await self.bot.check_cache(ctx.author.id, guild.id)
# Get the author's row from the members table
try:
select_query = """SELECT * FROM members WHERE member_id = $1 and guild_id = $2"""
result = await conn.fetchrow(select_query, ctx.author.id, guild.id)
# Catch errors
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

Loading…
Cancel
Save