2023-09-24 23:55:21 -04:00
|
|
|
import discord
|
|
|
|
from redbot.core import checks, commands, Config
|
|
|
|
|
|
|
|
class Moderation(commands.Cog):
|
2023-09-27 13:24:57 -04:00
|
|
|
"""Custom cog moderation cog, meant to copy GalacticBot.
|
2023-09-24 23:55:21 -04:00
|
|
|
Developed by SeaswimmerTheFsh."""
|
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
self.config = Config.get_conf(self, identifier=481923957134912)
|
|
|
|
self.config.register_global(
|
|
|
|
mysql_address= " ",
|
|
|
|
mysql_database = " ",
|
|
|
|
mysql_user = " ",
|
|
|
|
mysql_password = " "
|
|
|
|
)
|
|
|
|
|
|
|
|
async def connect(self):
|
|
|
|
"""Connects to the MySQL database."""
|
|
|
|
|
|
|
|
async def check_conf(self, config: list):
|
|
|
|
"""Checks if any required config options are not set."""
|
|
|
|
not_found_list = []
|
|
|
|
for item in config:
|
|
|
|
if await self.config.item() == " ":
|
|
|
|
not_found_list.append(item)
|
|
|
|
return not_found_list
|
|
|
|
|
|
|
|
@commands.group(autohelp=True)
|
2023-09-24 23:57:39 -04:00
|
|
|
@checks.admin()
|
2023-09-24 23:55:21 -04:00
|
|
|
async def moderationset(self, ctx: commands.Context):
|
|
|
|
"""Manage moderation commands."""
|
|
|
|
|
|
|
|
@moderationset.command(name="mysql")
|
2023-09-24 23:57:39 -04:00
|
|
|
@checks.is_owner()
|
2023-09-24 23:55:21 -04:00
|
|
|
async def moderationset_mysql(self, ctx: commands.Context):
|
|
|
|
"""Configure MySQL connection details."""
|
2023-09-25 00:06:13 -04:00
|
|
|
await ctx.message.add_reaction("✅")
|
|
|
|
await ctx.author.send(content="Click the button below to configure your MySQL connection details.", view=self.ConfigButtons(60))
|
2023-09-24 23:55:21 -04:00
|
|
|
|
|
|
|
class ConfigButtons(discord.ui.View):
|
|
|
|
def __init__(self, timeout):
|
|
|
|
super().__init__()
|
|
|
|
self.config = Config.get_conf(None, cog_name='Moderation', identifier=481923957134912)
|
|
|
|
|
|
|
|
@discord.ui.button(label="Edit", style=discord.ButtonStyle.success)
|
|
|
|
async def config_button(self, interaction: discord.Interaction, button: discord.ui.Button): # pylint: disable=unused-argument
|
|
|
|
await interaction.response.send_modal(Moderation.MySQLConfigModal(self.config))
|
|
|
|
|
|
|
|
class MySQLConfigModal(discord.ui.Modal, title="MySQL Database Configuration"):
|
|
|
|
def __init__(self, config):
|
|
|
|
super().__init__()
|
|
|
|
self.config = config
|
|
|
|
address = discord.ui.TextInput(
|
|
|
|
label="Address",
|
|
|
|
placeholder="Input your MySQL address here.",
|
2023-09-25 00:02:57 -04:00
|
|
|
style=discord.TextStyle.short,
|
2023-09-24 23:55:21 -04:00
|
|
|
required=False,
|
|
|
|
max_length=300
|
|
|
|
)
|
|
|
|
database = discord.ui.TextInput(
|
|
|
|
label="Database",
|
|
|
|
placeholder="Input the name of your database here.",
|
|
|
|
style=discord.TextStyle.short,
|
|
|
|
required=False,
|
|
|
|
max_length=300
|
|
|
|
)
|
|
|
|
username = discord.ui.TextInput(
|
|
|
|
label="Username",
|
|
|
|
placeholder="Input your MySQL username here.",
|
|
|
|
style=discord.TextStyle.short,
|
|
|
|
required=False,
|
|
|
|
max_length=300
|
|
|
|
)
|
|
|
|
password = discord.ui.TextInput(
|
|
|
|
label="Password",
|
|
|
|
placeholder="Input your MySQL password here.",
|
|
|
|
style=discord.TextStyle.short,
|
|
|
|
required=False,
|
|
|
|
max_length=300
|
|
|
|
)
|
|
|
|
|
|
|
|
async def on_submit(self, interaction: discord.Interaction):
|
|
|
|
message = ""
|
|
|
|
if self.address.value != "":
|
|
|
|
await self.config.mysql_address.set(self.address.value)
|
|
|
|
message += f"- Address set to\n - `{self.address.value}`\n"
|
|
|
|
if self.database.value != "":
|
|
|
|
await self.config.mysql_database.set(self.database.value)
|
|
|
|
message += f"- Database set to\n - `{self.database.value}`\n"
|
|
|
|
if self.username.value != "":
|
|
|
|
await self.config.mysql_username.set(self.username.value)
|
|
|
|
message += f"- Username set to\n - `{self.username.value}`\n"
|
|
|
|
if self.password.value != "":
|
|
|
|
await self.config.mysql_password.set(self.password.value)
|
|
|
|
trimmed_password = self.password.value[:8]
|
|
|
|
message += f"- Password set to\n - `{trimmed_password}` - Trimmed for security\n"
|
|
|
|
if message == "":
|
|
|
|
trimmed_password = str(await self.config.mysql_password())[:8]
|
2023-09-25 00:02:57 -04:00
|
|
|
send = f"No changes were made.\nCurrent configuration:\n- Address:\n - `{await self.config.mysql_address()}`\n- Database:\n - `{await self.config.mysql_database()}`\n- Username:\n - `{await self.config.mysql_username()}`\n- Password:\n - `{trimmed_password}` - Trimmed for security"
|
2023-09-24 23:55:21 -04:00
|
|
|
else:
|
|
|
|
send = f"Configuration changed:\n{message}"
|
|
|
|
await interaction.response.send_message(send, ephemeral=True)
|