Database connections are now more efficient

pull/8/head
sgoudham 4 years ago
parent 80a1efbb2b
commit 94d1aacd5e

@ -2,6 +2,7 @@ import asyncio
import datetime import datetime
import os import os
import random import random
from contextlib import closing
import discord import discord
from discord import Embed 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 # Get the author's row from the Members Table
select_query = """SELECT * FROM moderatormail WHERE guildID = (?)""" select_query = """SELECT * FROM moderatormail WHERE guildID = (?)"""
val = 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 # Adding error handlingpip3 install
cursor.execute(select_query, val) if result is None:
result = cursor.fetchone() return
# Adding error handling
if result is None:
return
# Define variables # Define variables
guild_id = int(result[0]) guild_id = int(result[0])
channel_id = int(result[1]) channel_id = int(result[1])
message_id = int(result[2]) message_id = int(result[2])
modmail_channel_id = int(result[3]) modmail_channel_id = int(result[3])
# Bunch of checks to make sure it has the right guild, channel, message and reaction # 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 == "": if payload.guild_id == guild_id and payload.channel_id == channel_id and payload.message_id == message_id and payload.emoji.name == "":

Loading…
Cancel
Save