|
|
|
@ -14,63 +14,11 @@ from discord.ext.commands import when_mentioned_or, is_owner, guild_only, has_pe
|
|
|
|
|
import db
|
|
|
|
|
import settings
|
|
|
|
|
from cogs.help import HelpPaginator
|
|
|
|
|
from settings import blank_space, enso_embedmod_colours, enso_guild_ID, enso_newpeople_ID
|
|
|
|
|
from settings import blank_space, enso_embedmod_colours, enso_guild_ID, enso_newpeople_ID, get_prefix_for_guild, \
|
|
|
|
|
storage_prefix_for_guild, cache_prefix, del_cache_prefix
|
|
|
|
|
|
|
|
|
|
# Storing the prefixes and guildID's in the cache
|
|
|
|
|
cached_prefixes = {}
|
|
|
|
|
counter = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Updating the prefix within the dict and database when the method is called
|
|
|
|
|
async def storage_prefix_for_guild(ctx, prefix):
|
|
|
|
|
cached_prefixes[str(ctx.guild.id)] = prefix
|
|
|
|
|
|
|
|
|
|
with db.connection() as connection:
|
|
|
|
|
# Update the existing prefix within the database
|
|
|
|
|
update_query = """UPDATE guilds SET prefix = (?) WHERE guildID = (?)"""
|
|
|
|
|
update_vals = prefix, ctx.guild.id,
|
|
|
|
|
|
|
|
|
|
# Using the connection cursor
|
|
|
|
|
with closing(connection.cursor()) as cur:
|
|
|
|
|
# Execute the query
|
|
|
|
|
cur.execute(update_query, update_vals)
|
|
|
|
|
print(cur.rowcount, f"Guild prefix has been updated for guild {ctx.guild.name}")
|
|
|
|
|
|
|
|
|
|
# Let the user know that the guild prefix has been updated
|
|
|
|
|
await ctx.send(f"**Guild prefix has been updated to `{prefix}`**")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Method to store the cached prefixes
|
|
|
|
|
def cache_prefix(guildid, prefix):
|
|
|
|
|
cached_prefixes[guildid] = prefix
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Deleting the key - value pair for guild
|
|
|
|
|
def del_cache_prefix(guildid):
|
|
|
|
|
del cached_prefixes[guildid]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Get the prefix of the guild that the user is in
|
|
|
|
|
def get_prefix_for_guild(guildid):
|
|
|
|
|
prefix = cached_prefixes[guildid]
|
|
|
|
|
if prefix is not None:
|
|
|
|
|
return prefix
|
|
|
|
|
return "defaultPrefix"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Before initialising the cache. Store the prefixes from the database within the cache
|
|
|
|
|
with db.connection() as conn:
|
|
|
|
|
# Grab the prefix of the server from the database
|
|
|
|
|
select_query = """SELECT * FROM guilds"""
|
|
|
|
|
with closing(conn.cursor()) as cursor:
|
|
|
|
|
# Execute the query
|
|
|
|
|
cursor.execute(select_query)
|
|
|
|
|
results = cursor.fetchall()
|
|
|
|
|
|
|
|
|
|
# Store the guildids and prefixes within
|
|
|
|
|
for row in results:
|
|
|
|
|
cache_prefix(row[0], row[1])
|
|
|
|
|
|
|
|
|
|
# Getting the Bot token from Environment Variables
|
|
|
|
|
API_TOKEN = config('DISCORD_TOKEN')
|
|
|
|
|
|
|
|
|
|