More work on settings, WIP
This commit is contained in:
parent
e59e566f30
commit
32841b230a
1 changed files with 23 additions and 24 deletions
|
@ -1,9 +1,16 @@
|
||||||
"""J.A.R.V.I.S. Settings Management Cog."""
|
"""J.A.R.V.I.S. Settings Management Cog."""
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from dis_snek import InteractionContext, Scale, Snake
|
||||||
|
from dis_snek.models.discord.channel import GuildText
|
||||||
|
from dis_snek.models.discord.enums import Permissions
|
||||||
|
from dis_snek.models.snek.application_commands import (
|
||||||
|
OptionTypes,
|
||||||
|
slash_command,
|
||||||
|
slash_option,
|
||||||
|
)
|
||||||
from dis_snek.models.snek.command import check
|
from dis_snek.models.snek.command import check
|
||||||
from discord import Role, TextChannel
|
from discord import Role, TextChannel
|
||||||
from discord.ext import commands
|
|
||||||
from discord.utils import find
|
from discord.utils import find
|
||||||
from discord_slash import SlashContext, cog_ext
|
from discord_slash import SlashContext, cog_ext
|
||||||
from discord_slash.utils.manage_commands import create_option
|
from discord_slash.utils.manage_commands import create_option
|
||||||
|
@ -15,12 +22,9 @@ from jarvis.utils.field import Field
|
||||||
from jarvis.utils.permissions import admin_or_permissions
|
from jarvis.utils.permissions import admin_or_permissions
|
||||||
|
|
||||||
|
|
||||||
class SettingsCog(commands.Cog):
|
class SettingsCog(Scale):
|
||||||
"""J.A.R.V.I.S. Settings Management Cog."""
|
"""J.A.R.V.I.S. Settings Management Cog."""
|
||||||
|
|
||||||
def __init__(self, bot: commands.Bot):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
async def update_settings(self, setting: str, value: Any, guild: int) -> bool:
|
async def update_settings(self, setting: str, value: Any, guild: int) -> bool:
|
||||||
"""Update a guild setting."""
|
"""Update a guild setting."""
|
||||||
existing = await Setting.find_one(q(setting=setting, guild=guild))
|
existing = await Setting.find_one(q(setting=setting, guild=guild))
|
||||||
|
@ -38,24 +42,19 @@ class SettingsCog(commands.Cog):
|
||||||
return await existing.delete()
|
return await existing.delete()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@cog_ext.cog_subcommand(
|
@slash_command(
|
||||||
base="settings",
|
name="settings",
|
||||||
subcommand_group="set",
|
description="Control bot settings",
|
||||||
name="modlog",
|
sub_cmd_name="modlog",
|
||||||
description="Set modlog channel",
|
sub_cmd_description="Set ActivityLog channel",
|
||||||
choices=[
|
|
||||||
create_option(
|
|
||||||
name="channel",
|
|
||||||
description="Modlog channel",
|
|
||||||
opt_type=7,
|
|
||||||
required=True,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
@check(admin_or_permissions(manage_guild=True))
|
@slash_option(
|
||||||
async def _set_modlog(self, ctx: SlashContext, channel: TextChannel) -> None:
|
name="channel", description="ModLog Channel", opt_type=OptionTypes.CHANNEL, required=True
|
||||||
if not isinstance(channel, TextChannel):
|
)
|
||||||
await ctx.send("Channel must be a TextChannel", ephemeral=True)
|
@check(admin_or_permissions(Permissions.MANAGE_GUILD))
|
||||||
|
async def _set_modlog(self, ctx: InteractionContext(), channel: GuildText) -> None:
|
||||||
|
if not isinstance(channel, GuildText):
|
||||||
|
await ctx.send("Channel must be a GuildText", ephemeral=True)
|
||||||
return
|
return
|
||||||
self.update_settings("modlog", channel.id, ctx.guild.id)
|
self.update_settings("modlog", channel.id, ctx.guild.id)
|
||||||
await ctx.send(f"Settings applied. New modlog channel is {channel.mention}")
|
await ctx.send(f"Settings applied. New modlog channel is {channel.mention}")
|
||||||
|
@ -74,7 +73,7 @@ class SettingsCog(commands.Cog):
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@check(admin_or_permissions(manage_guild=True))
|
@check(admin_or_permissions(Permissions.MANAGE_GUILD))
|
||||||
async def _set_activitylog(self, ctx: SlashContext, channel: TextChannel) -> None:
|
async def _set_activitylog(self, ctx: SlashContext, channel: TextChannel) -> None:
|
||||||
if not isinstance(channel, TextChannel):
|
if not isinstance(channel, TextChannel):
|
||||||
await ctx.send("Channel must be a TextChannel", ephemeral=True)
|
await ctx.send("Channel must be a TextChannel", ephemeral=True)
|
||||||
|
@ -261,6 +260,6 @@ class SettingsCog(commands.Cog):
|
||||||
await ctx.send(f"Guild settings cleared: `{deleted is not None}`")
|
await ctx.send(f"Guild settings cleared: `{deleted is not None}`")
|
||||||
|
|
||||||
|
|
||||||
def setup(bot: commands.Bot) -> None:
|
def setup(bot: Snake) -> None:
|
||||||
"""Add SettingsCog to J.A.R.V.I.S."""
|
"""Add SettingsCog to J.A.R.V.I.S."""
|
||||||
SettingsCog(bot)
|
SettingsCog(bot)
|
||||||
|
|
Loading…
Add table
Reference in a new issue