|
|
@ -83,10 +83,11 @@ class Bot(commands.Bot):
|
|
|
|
# Instance variables for cache
|
|
|
|
# Instance variables for cache
|
|
|
|
self.enso_cache = {}
|
|
|
|
self.enso_cache = {}
|
|
|
|
self.modmail_cache = {}
|
|
|
|
self.modmail_cache = {}
|
|
|
|
self.member_cache = MyCoolCache(1000)
|
|
|
|
self.member_cache = MyCoolCache(5000)
|
|
|
|
|
|
|
|
|
|
|
|
async def create_connection():
|
|
|
|
async def create_connection():
|
|
|
|
"""Setting up connection using asyncpg"""
|
|
|
|
"""Setting up connection using asyncpg"""
|
|
|
|
|
|
|
|
|
|
|
|
self.db = await asyncpg.create_pool(
|
|
|
|
self.db = await asyncpg.create_pool(
|
|
|
|
host=host,
|
|
|
|
host=host,
|
|
|
|
port=int(port),
|
|
|
|
port=int(port),
|
|
|
@ -325,9 +326,7 @@ class Bot(commands.Bot):
|
|
|
|
# Query to update the existing prefix within the database
|
|
|
|
# Query to update the existing prefix within the database
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
update_query = """UPDATE guilds SET prefix = $1 WHERE guild_id = $2"""
|
|
|
|
update_query = """UPDATE guilds SET prefix = $1 WHERE guild_id = $2"""
|
|
|
|
|
|
|
|
|
|
|
|
rowcount = await conn.execute(update_query, prefix, ctx.guild.id)
|
|
|
|
rowcount = await conn.execute(update_query, prefix, ctx.guild.id)
|
|
|
|
print(rowcount, f"Guild prefix has been updated for guild {ctx.guild}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Catch errors
|
|
|
|
# Catch errors
|
|
|
|
except asyncpg.PostgresError as e:
|
|
|
|
except asyncpg.PostgresError as e:
|
|
|
@ -335,6 +334,7 @@ class Bot(commands.Bot):
|
|
|
|
|
|
|
|
|
|
|
|
# Let the user know that the guild prefix has been updated
|
|
|
|
# Let the user know that the guild prefix has been updated
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
print(rowcount, f"Guild prefix has been updated for guild {ctx.guild}")
|
|
|
|
await self.generate_embed(ctx, desc=f"Guild prefix has been updated to **{prefix}**")
|
|
|
|
await self.generate_embed(ctx, desc=f"Guild prefix has been updated to **{prefix}**")
|
|
|
|
|
|
|
|
|
|
|
|
# Store in cache
|
|
|
|
# Store in cache
|
|
|
@ -370,7 +370,7 @@ class Bot(commands.Bot):
|
|
|
|
|
|
|
|
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
|
|
|
|
|
|
|
async def storeRoles(self, target, ctx, member):
|
|
|
|
async def store_roles(self, target, ctx, member):
|
|
|
|
"""Storing user roles within database"""
|
|
|
|
"""Storing user roles within database"""
|
|
|
|
|
|
|
|
|
|
|
|
role_ids = ", ".join([str(r.id) for r in target.roles])
|
|
|
|
role_ids = ", ".join([str(r.id) for r in target.roles])
|
|
|
@ -383,6 +383,7 @@ class Bot(commands.Bot):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
update_query = """UPDATE members SET muted_roles = $1 WHERE guild_id = $2 AND member_id = $3"""
|
|
|
|
update_query = """UPDATE members SET muted_roles = $1 WHERE guild_id = $2 AND member_id = $3"""
|
|
|
|
rowcount = await conn.execute(update_query, role_ids, ctx.guild.id, member.id)
|
|
|
|
rowcount = await conn.execute(update_query, role_ids, ctx.guild.id, member.id)
|
|
|
|
|
|
|
|
result = await self.check_cache(member.id, member.guild.id)
|
|
|
|
|
|
|
|
|
|
|
|
# Catch errors
|
|
|
|
# Catch errors
|
|
|
|
except asyncpg.PostgresError as e:
|
|
|
|
except asyncpg.PostgresError as e:
|
|
|
@ -390,13 +391,14 @@ class Bot(commands.Bot):
|
|
|
|
|
|
|
|
|
|
|
|
# Print success
|
|
|
|
# Print success
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
result["muted_roles"] = role_ids
|
|
|
|
print(rowcount, f"Roles Added For User {member} in {ctx.guild}")
|
|
|
|
print(rowcount, f"Roles Added For User {member} in {ctx.guild}")
|
|
|
|
|
|
|
|
|
|
|
|
# Release connection back to pool
|
|
|
|
# Release connection back to pool
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
|
await pool.release(conn)
|
|
|
|
await pool.release(conn)
|
|
|
|
|
|
|
|
|
|
|
|
async def clearRoles(self, member):
|
|
|
|
async def clear_roles(self, member):
|
|
|
|
"""Clear the roles when the user has been unmuted"""
|
|
|
|
"""Clear the roles when the user has been unmuted"""
|
|
|
|
|
|
|
|
|
|
|
|
# Setup up pool connection
|
|
|
|
# Setup up pool connection
|
|
|
@ -407,6 +409,7 @@ class Bot(commands.Bot):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
update_query = """UPDATE members SET muted_roles = NULL WHERE guild_id = $1 AND member_id = $2"""
|
|
|
|
update_query = """UPDATE members SET muted_roles = NULL WHERE guild_id = $1 AND member_id = $2"""
|
|
|
|
rowcount = await conn.execute(update_query, member.guild.id, member.id)
|
|
|
|
rowcount = await conn.execute(update_query, member.guild.id, member.id)
|
|
|
|
|
|
|
|
result = await self.check_cache(member.id, member.guild.id)
|
|
|
|
|
|
|
|
|
|
|
|
# Catch error
|
|
|
|
# Catch error
|
|
|
|
except asyncpg.PostgresError as e:
|
|
|
|
except asyncpg.PostgresError as e:
|
|
|
@ -414,7 +417,9 @@ class Bot(commands.Bot):
|
|
|
|
e)
|
|
|
|
e)
|
|
|
|
|
|
|
|
|
|
|
|
# Print success
|
|
|
|
# Print success
|
|
|
|
|
|
|
|
# Update cache
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
result["muted_roles"] = None
|
|
|
|
print(rowcount, f"Roles Cleared For User {member} in {member.guild.name}")
|
|
|
|
print(rowcount, f"Roles Cleared For User {member} in {member.guild.name}")
|
|
|
|
|
|
|
|
|
|
|
|
# Release connection back to pool
|
|
|
|
# Release connection back to pool
|
|
|
@ -593,6 +598,7 @@ class Bot(commands.Bot):
|
|
|
|
print(f"PostGres Error: Clearing Member {member.id} Roles in Guild {member.guild.id}", e)
|
|
|
|
print(f"PostGres Error: Clearing Member {member.id} Roles in Guild {member.guild.id}", e)
|
|
|
|
|
|
|
|
|
|
|
|
# Print success
|
|
|
|
# Print success
|
|
|
|
|
|
|
|
# Update cache
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print(rowcount, f"Roles Cleared For {member} in {member.guild}")
|
|
|
|
print(rowcount, f"Roles Cleared For {member} in {member.guild}")
|
|
|
|
|
|
|
|
|
|
|
@ -645,13 +651,16 @@ class Bot(commands.Bot):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
update_query = """UPDATE members SET roles = $1 WHERE guild_id = $2 AND member_id = $3"""
|
|
|
|
update_query = """UPDATE members SET roles = $1 WHERE guild_id = $2 AND member_id = $3"""
|
|
|
|
rowcount = await conn.execute(update_query, role_ids, member.guild.id, member.id)
|
|
|
|
rowcount = await conn.execute(update_query, role_ids, member.guild.id, member.id)
|
|
|
|
|
|
|
|
result = await self.check_cache(member.id, member.guild.id)
|
|
|
|
|
|
|
|
|
|
|
|
# Catch Error
|
|
|
|
# Catch Error
|
|
|
|
except asyncpg.PostgresError as e:
|
|
|
|
except asyncpg.PostgresError as e:
|
|
|
|
print(f"PostGres Error: Roles Could Not Be Added To {member} When Leaving {member.guild.id}", e)
|
|
|
|
print(f"PostGres Error: Roles Could Not Be Added To {member} When Leaving {member.guild.id}", e)
|
|
|
|
|
|
|
|
|
|
|
|
# Print success
|
|
|
|
# Print success
|
|
|
|
|
|
|
|
# Update cache
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
result["roles"] = role_ids
|
|
|
|
print(rowcount, f"{member} Left {member.guild.name}, Roles stored into Members")
|
|
|
|
print(rowcount, f"{member} Left {member.guild.name}, Roles stored into Members")
|
|
|
|
|
|
|
|
|
|
|
|
finally:
|
|
|
|
finally:
|
|
|
@ -660,9 +669,6 @@ class Bot(commands.Bot):
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------!End Events Section!----------------------------------------------
|
|
|
|
# --------------------------------------------!End Events Section!----------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
async def update_cache(self, member_id, guild_id):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def check_cache(self, member_id, guild_id):
|
|
|
|
async def check_cache(self, member_id, guild_id):
|
|
|
|
"""Checks if member is in the member cache"""
|
|
|
|
"""Checks if member is in the member cache"""
|
|
|
|
|
|
|
|
|
|
|
|