|
|
@ -56,6 +56,10 @@ def rndColour():
|
|
|
|
return Colour(random.randint(0, 0xFFFFFF))
|
|
|
|
return Colour(random.randint(0, 0xFFFFFF))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Setup Dict To Store Values
|
|
|
|
|
|
|
|
enso_cache = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def startup_cache_log():
|
|
|
|
async def startup_cache_log():
|
|
|
|
"""Store the modlogs/prefixes in cache from the database on startup"""
|
|
|
|
"""Store the modlogs/prefixes in cache from the database on startup"""
|
|
|
|
|
|
|
|
|
|
|
@ -72,21 +76,32 @@ async def startup_cache_log():
|
|
|
|
await cur.execute(select_query)
|
|
|
|
await cur.execute(select_query)
|
|
|
|
results = await cur.fetchall()
|
|
|
|
results = await cur.fetchall()
|
|
|
|
|
|
|
|
|
|
|
|
# Store the guildids and modlog channels
|
|
|
|
# Store the guildID's, modlog channels and prefixes within cache
|
|
|
|
for row in results:
|
|
|
|
for row in results:
|
|
|
|
cache_modlogs(row[0], row[2])
|
|
|
|
cache(guildid=row[0], channel=row[2], prefix=row[1])
|
|
|
|
cache_prefix(row[0], row[1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------!ModLogs Section!---------------------------------------------------------
|
|
|
|
# Method to store the guildID, channel
|
|
|
|
|
|
|
|
def cache(guildid, channel, prefix):
|
|
|
|
|
|
|
|
"""Storing GuildID, Modlogs Channel and Prefix in Cache"""
|
|
|
|
|
|
|
|
enso_cache[guildid] = {"Modlogs": channel, "Prefix": prefix}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_cache(guildid):
|
|
|
|
|
|
|
|
"""Returning the cache"""
|
|
|
|
|
|
|
|
return enso_cache[guildid]
|
|
|
|
|
|
|
|
|
|
|
|
# Store guildID's and modlog channel within a cached dictionary
|
|
|
|
|
|
|
|
modlogs = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def del_cache(guildid):
|
|
|
|
|
|
|
|
"""Deleting the entry of the guild within the cache"""
|
|
|
|
|
|
|
|
del enso_cache[guildid]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------!ModLogs Section!---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
# Updating the modlog 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
|
|
|
|
enso_cache[str(ctx.guild.id)]["Modlogs"] = channelID
|
|
|
|
|
|
|
|
|
|
|
|
# Setup pool
|
|
|
|
# Setup pool
|
|
|
|
pool = await db.connection(db.loop)
|
|
|
|
pool = await db.connection(db.loop)
|
|
|
@ -120,25 +135,25 @@ async def storage_modlog_for_guild(ctx, channelID, setup):
|
|
|
|
|
|
|
|
|
|
|
|
# Method to store the cached modlog channels
|
|
|
|
# Method to store the cached modlog channels
|
|
|
|
def cache_modlogs(guildid, channel):
|
|
|
|
def cache_modlogs(guildid, channel):
|
|
|
|
modlogs[guildid] = channel
|
|
|
|
enso_cache[guildid]["Modlogs"] = channel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Deleting the key - value pair for guild/modlogs
|
|
|
|
# Deleting the key - value pair for guild/modlogs
|
|
|
|
def del_modlog_channel(guildid):
|
|
|
|
def del_modlog_channel(guildid):
|
|
|
|
if modlogs[guildid] is not None:
|
|
|
|
if enso_cache[guildid]["Modlogs"] is not None:
|
|
|
|
del modlogs[guildid]
|
|
|
|
del enso_cache[guildid]["Modlogs"]
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Remove the value of modlog for the guild specified
|
|
|
|
# Remove the value of modlog for the guild specified
|
|
|
|
def remove_modlog_channel(guildid):
|
|
|
|
def remove_modlog_channel(guildid):
|
|
|
|
modlogs[guildid] = None
|
|
|
|
enso_cache[guildid]["Modlogs"] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get the modlog channel of the guild that the user is in
|
|
|
|
# Get the modlog channel of the guild that the user is in
|
|
|
|
def get_modlog_for_guild(guildid):
|
|
|
|
def get_modlog_for_guild(guildid):
|
|
|
|
channel = modlogs[guildid]
|
|
|
|
channel = enso_cache[guildid]["Modlogs"]
|
|
|
|
return channel
|
|
|
|
return channel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -146,13 +161,9 @@ def get_modlog_for_guild(guildid):
|
|
|
|
|
|
|
|
|
|
|
|
# --------------------------------------------!Prefixes Section!--------------------------------------------------------
|
|
|
|
# --------------------------------------------!Prefixes Section!--------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
# Storing the prefixes and guildID's in the cache
|
|
|
|
|
|
|
|
cached_prefixes = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Updating the prefix within the dict and database when the method is called
|
|
|
|
# Updating the prefix within the dict and database when the method is called
|
|
|
|
async def storage_prefix_for_guild(ctx, prefix):
|
|
|
|
async def storage_prefix_for_guild(ctx, prefix):
|
|
|
|
cached_prefixes[str(ctx.guild.id)] = prefix
|
|
|
|
enso_cache[str(ctx.guild.id)]["Prefix"] = prefix
|
|
|
|
|
|
|
|
|
|
|
|
# Setup pool
|
|
|
|
# Setup pool
|
|
|
|
pool = await db.connection(db.loop)
|
|
|
|
pool = await db.connection(db.loop)
|
|
|
@ -175,17 +186,17 @@ async def storage_prefix_for_guild(ctx, prefix):
|
|
|
|
|
|
|
|
|
|
|
|
# Method to store the cached prefixes
|
|
|
|
# Method to store the cached prefixes
|
|
|
|
def cache_prefix(guildid, prefix):
|
|
|
|
def cache_prefix(guildid, prefix):
|
|
|
|
cached_prefixes[guildid] = prefix
|
|
|
|
enso_cache[guildid]["Prefix"] = prefix
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Deleting the key - value pair for guild
|
|
|
|
# Deleting the key - value pair for guild
|
|
|
|
def del_cache_prefix(guildid):
|
|
|
|
def del_cache_prefix(guildid):
|
|
|
|
del cached_prefixes[guildid]
|
|
|
|
del enso_cache[guildid]["Prefix"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get the prefix of the guild that the user is in
|
|
|
|
# Get the prefix of the guild that the user is in
|
|
|
|
def get_prefix_for_guild(guildid):
|
|
|
|
def get_prefix_for_guild(guildid):
|
|
|
|
prefix = cached_prefixes[guildid]
|
|
|
|
prefix = enso_cache[guildid]["Prefix"]
|
|
|
|
if prefix is not None:
|
|
|
|
if prefix is not None:
|
|
|
|
return prefix
|
|
|
|
return prefix
|
|
|
|
return "defaultPrefix"
|
|
|
|
return "defaultPrefix"
|
|
|
|