From 94d1aacd5e7a24fffa8b5a4d2bcc0f930c3dff85 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Tue, 21 Jul 2020 21:27:13 +0100 Subject: [PATCH] Database connections are now more efficient --- cogs/modmail/modmail.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cogs/modmail/modmail.py b/cogs/modmail/modmail.py index 9fd99485..00766a18 100644 --- a/cogs/modmail/modmail.py +++ b/cogs/modmail/modmail.py @@ -2,6 +2,7 @@ import asyncio import datetime import os import random +from contextlib import closing import discord from discord import Embed @@ -167,21 +168,20 @@ class Modmail(commands.Cog, command_attrs=dict(hidden=True)): # Get the author's row from the Members Table select_query = """SELECT * FROM moderatormail WHERE guildID = (?)""" val = guildid, - cursor = conn.cursor() + with closing(conn.cursor()) as cursor: + # Execute the SQL Query + cursor.execute(select_query, val) + result = cursor.fetchone() - # Execute the SQL Query - cursor.execute(select_query, val) - result = cursor.fetchone() - - # Adding error handling - if result is None: - return + # Adding error handlingpip3 install + if result is None: + return - # Define variables - guild_id = int(result[0]) - channel_id = int(result[1]) - message_id = int(result[2]) - modmail_channel_id = int(result[3]) + # Define variables + guild_id = int(result[0]) + channel_id = int(result[1]) + message_id = int(result[2]) + modmail_channel_id = int(result[3]) # Bunch of checks to make sure it has the right guild, channel, message and reaction if payload.guild_id == guild_id and payload.channel_id == channel_id and payload.message_id == message_id and payload.emoji.name == "✅":