|
|
|
import random
|
|
|
|
from contextlib import closing
|
|
|
|
|
|
|
|
from discord import Colour
|
|
|
|
|
|
|
|
# Defining a list of colours
|
|
|
|
import db
|
|
|
|
|
|
|
|
colors = {
|
|
|
|
'DEFAULT': 0x000000,
|
|
|
|
'WHITE': 0xFFFFFF,
|
|
|
|
'AQUA': 0x1ABC9C,
|
|
|
|
'GREEN': 0x2ECC71,
|
|
|
|
'BLUE': 0x3498DB,
|
|
|
|
'PURPLE': 0x9B59B6,
|
|
|
|
'LUMINOUS_VIVID_PINK': 0xE91E63,
|
|
|
|
'GOLD': 0xF1C40F,
|
|
|
|
'ORANGE': 0xE67E22,
|
|
|
|
'RED': 0xE74C3C,
|
|
|
|
'GREY': 0x95A5A6,
|
|
|
|
'NAVY': 0x34495E,
|
|
|
|
'DARK_AQUA': 0x11806A,
|
|
|
|
'DARK_GREEN': 0x1F8B4C,
|
|
|
|
'DARK_BLUE': 0x206694,
|
|
|
|
'DARK_PURPLE': 0x71368A,
|
|
|
|
'DARK_VIVID_PINK': 0xAD1457,
|
|
|
|
'DARK_GOLD': 0xC27C0E,
|
|
|
|
'DARK_ORANGE': 0xA84300,
|
|
|
|
'DARK_RED': 0x992D22,
|
|
|
|
'DARK_GREY': 0x979C9F,
|
|
|
|
'DARKER_GREY': 0x7F8C8D,
|
|
|
|
'LIGHT_GREY': 0xBCC0C0,
|
|
|
|
'DARK_NAVY': 0x2C3E50,
|
|
|
|
'BLURPLE': 0x7289DA,
|
|
|
|
'GREYPLE': 0x99AAB5,
|
|
|
|
'DARK_BUT_NOT_BLACK': 0x2C2F33,
|
|
|
|
'NOT_QUITE_BLACK': 0x23272A,
|
|
|
|
'CRIMSON': 0xDC143C,
|
|
|
|
'HOT_PINK': 0xFF69B4,
|
|
|
|
'DEEP_PINK': 0xFF69B4,
|
|
|
|
'MAGENTA': 0xFF00FF,
|
|
|
|
'VIOLET': 0xEE82EE,
|
|
|
|
'TEAL': 0x008080,
|
|
|
|
'MIDNIGHT_BLUE': 0x191970,
|
|
|
|
'MISTY_ROSE': 0xFFE4E1,
|
|
|
|
'SEA_GREEN': 0x2E8B57,
|
|
|
|
'MEDIUM_VIOLET_RED': 0xC71585,
|
|
|
|
}
|
|
|
|
|
|
|
|
# Grabbing the list of colours
|
|
|
|
colour_list = [c for c in colors.values()]
|
|
|
|
|
|
|
|
|
|
|
|
def rndColour():
|
|
|
|
"""Generate a random hex colour"""
|
|
|
|
return Colour(random.randint(0, 0xFFFFFF))
|
|
|
|
|
|
|
|
|
|
|
|
# Store guildID's and modlog channel within a cached dictionary
|
|
|
|
modlogs = {}
|
|
|
|
|
|
|
|
|
|
|
|
# Updating the modlog within the dict and database when the method is called
|
|
|
|
async def storage_modlog_for_guild(ctx, channelID, setup):
|
|
|
|
modlogs[str(ctx.guild.id)] = channelID
|
|
|
|
|
|
|
|
# Setup pool
|
|
|
|
pool = await db.connection2(db.loop)
|
|
|
|
|
|
|
|
# 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,
|
|
|
|
|
|
|
|
# Execute the query
|
|
|
|
await cur.execute(update_query, update_vals)
|
|
|
|
await conn.commit()
|
|
|
|
|
|
|
|
# Send custom confirmation messages to log based on the command update or setup
|
|
|
|
if setup:
|
|
|
|
print(cur.rowcount, f"Modlog channel for guild {ctx.guild.name} has been Setup")
|
|
|
|
else:
|
|
|
|
print(cur.rowcount, f"Modlog channel for guild {ctx.guild.name} has been Updated")
|
|
|
|
|
|
|
|
if setup:
|
|
|
|
# Send confirmation that modmail channel has been setup
|
|
|
|
await ctx.send("Your **Modlogs Channel** is now successfully set up!" +
|
|
|
|
f"\nPlease refer to **{ctx.prefix}help** for any information")
|
|
|
|
else:
|
|
|
|
# Let the user know that the guild modlogs channel has been updated
|
|
|
|
channel = ctx.guild.get_channel(channelID)
|
|
|
|
await ctx.send(f"Modlog Channel for **{ctx.guild.name}** has been updated to {channel.mention}")
|
|
|
|
|
|
|
|
|
|
|
|
# Method to store the cached modlog channels
|
|
|
|
def cache_modlogs(guildid, channel):
|
|
|
|
modlogs[guildid] = channel
|
|
|
|
|
|
|
|
|
|
|
|
# Deleting the key - value pair for guild/modlogs
|
|
|
|
def del_modlog_channel(guildid):
|
|
|
|
if modlogs[guildid] is not None:
|
|
|
|
del modlogs[guildid]
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
# Remove the value of modlog for the guild specified
|
|
|
|
def remove_modlog_channel(guildid):
|
|
|
|
modlogs[guildid] = None
|
|
|
|
|
|
|
|
|
|
|
|
# Get the modlog channel of the guild that the user is in
|
|
|
|
def get_modlog_for_guild(guildid):
|
|
|
|
channel = modlogs[guildid]
|
|
|
|
return channel
|
|
|
|
|
|
|
|
|
|
|
|
# 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 modlog channels
|
|
|
|
for row in results:
|
|
|
|
cache_modlogs(row[0], row[2])
|
|
|
|
|
|
|
|
# Storing the prefixes and guildID's in the cache
|
|
|
|
cached_prefixes = {}
|
|
|
|
|
|
|
|
|
|
|
|
# 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])
|
|
|
|
|
|
|
|
# Define repeated variables
|
|
|
|
hammyMention = '<@154840866496839680>'
|
|
|
|
hammyID = 154840866496839680
|
|
|
|
ensoMention = '<@716701699145728094>'
|
|
|
|
|
|
|
|
blank_space = "\u200b"
|
|
|
|
enso_embedmod_colours = Colour(0x62167a)
|
|
|
|
|
|
|
|
enso_ensochancommands_Mention = "<#721449922838134876>"
|
|
|
|
|
|
|
|
enso_ensochancommands_ID = 721449922838134876
|
|
|
|
enso_verification_ID = 728034083678060594
|
|
|
|
enso_selfroles_ID = 722347423913213992
|
|
|
|
enso_guild_ID = 663651584399507476
|
|
|
|
enso_newpeople_ID = 669771571337887765
|
|
|
|
enso_modmail_ID = 728083016290926623
|
|
|
|
|
|
|
|
|
|
|
|
# Returns a list of all the cogs
|
|
|
|
def extensions():
|
|
|
|
ext = ['cogs.interactive', 'cogs.anime', 'cogs.relationship',
|
|
|
|
'cogs.info', 'cogs.fun', 'cogs.enso',
|
|
|
|
'cogs.modmail', 'cogs.moderation']
|
|
|
|
|
|
|
|
return ext
|