Made database connections Asynchronous

Added random hex code generator
pull/8/head
sgoudham 4 years ago
parent 6db25d32a3
commit eb75dbeefc

@ -53,32 +53,36 @@ colour_list = [c for c in colors.values()]
def rndColour(): def rndColour():
"""Generate a random hex colour""" """Generate a random hex colour"""
return "#{:06x}".format(random.randint(0, 0xFFFFFF)) return Colour(random.randint(0, 0xFFFFFF))
# Store guildID's and modlog channel within a cached dictionary # Store guildID's and modlog channel within a cached dictionary
modlogs = {} modlogs = {}
# Updating the prefix within the dict and database when the method is called # Updating the modlog within the dict and database when the method is called
async def storage_modlog_for_guild(ctx, channelID, setup): async def storage_modlog_for_guild(ctx, channelID, setup):
modlogs[str(ctx.guild.id)] = channelID modlogs[str(ctx.guild.id)] = channelID
with db.connection() as connection: # Setup pool
# Update the existing prefix within the database pool = await db.connection2(db.loop)
update_query = """UPDATE guilds SET modlogs = (?) WHERE guildID = (?)"""
update_vals = channelID, ctx.guild.id, # Setup up pool connection and cursor
async with pool.acquire() as conn:
async with conn.cursor() as cur:
# Update the existing prefix within the database
update_query = """UPDATE guilds SET modlogs = (%s) WHERE guildID = (%s)"""
update_vals = channelID, ctx.guild.id,
# Using the connection cursor
with closing(connection.cursor()) as cur:
# Execute the query # Execute the query
cur.execute(update_query, update_vals) await cur.execute(update_query, update_vals)
await conn.commit()
# Send custom confirmation messages to log based on the command update or setup # Send custom confirmation messages to log based on the command update or setup
if setup: if setup:
print(cur.rowcount, f"Modlog channel for guild {ctx.guild.name} has been Setup") print(cur.rowcount, f"Modlog channel for guild {ctx.guild.name} has been Setup")
else: else:
print(cur.rowcount, f"Modlog channel for guild {ctx.guild.name} has been Updated") print(cur.rowcount, f"Modlog channel for guild {ctx.guild.name} has been Updated")
if setup: if setup:
# Send confirmation that modmail channel has been setup # Send confirmation that modmail channel has been setup

Loading…
Cancel
Save