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,23 +62,10 @@ 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
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"] married_user = result["married"]
if married_user is None and kiss: if married_user is None and kiss:
await ctx.send("Σ(‘◉⌓◉’) You need to be married in order to use this command! Baka!") await ctx.send("Σ(‘◉⌓◉’) You need to be married in order to use this command! Baka!")
return return
@ -87,10 +73,6 @@ class Interactive(Cog):
await ctx.send("Σ(‘◉⌓◉’) You can only kiss your partner! Baka!") await ctx.send("Σ(‘◉⌓◉’) You can only kiss your partner! Baka!")
return 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
with open('images/FunCommands/kissing.txt') as file: with open('images/FunCommands/kissing.txt') as file:
@ -131,23 +113,10 @@ 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:
# 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"] married_user = result["married"]
if married_user is None and cuddle: if married_user is None and cuddle:
await ctx.send("Σ(‘◉⌓◉’) You need to be married in order to use this command! Baka!") await ctx.send("Σ(‘◉⌓◉’) You need to be married in order to use this command! Baka!")
return return

Loading…
Cancel
Save