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."""
|
||||
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 discord import Role, TextChannel
|
||||
from discord.ext import commands
|
||||
from discord.utils import find
|
||||
from discord_slash import SlashContext, cog_ext
|
||||
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
|
||||
|
||||
|
||||
class SettingsCog(commands.Cog):
|
||||
class SettingsCog(Scale):
|
||||
"""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:
|
||||
"""Update a guild setting."""
|
||||
existing = await Setting.find_one(q(setting=setting, guild=guild))
|
||||
|
@ -38,24 +42,19 @@ class SettingsCog(commands.Cog):
|
|||
return await existing.delete()
|
||||
return False
|
||||
|
||||
@cog_ext.cog_subcommand(
|
||||
base="settings",
|
||||
subcommand_group="set",
|
||||
name="modlog",
|
||||
description="Set modlog channel",
|
||||
choices=[
|
||||
create_option(
|
||||
name="channel",
|
||||
description="Modlog channel",
|
||||
opt_type=7,
|
||||
required=True,
|
||||
)
|
||||
],
|
||||
@slash_command(
|
||||
name="settings",
|
||||
description="Control bot settings",
|
||||
sub_cmd_name="modlog",
|
||||
sub_cmd_description="Set ActivityLog channel",
|
||||
)
|
||||
@check(admin_or_permissions(manage_guild=True))
|
||||
async def _set_modlog(self, ctx: SlashContext, channel: TextChannel) -> None:
|
||||
if not isinstance(channel, TextChannel):
|
||||
await ctx.send("Channel must be a TextChannel", ephemeral=True)
|
||||
@slash_option(
|
||||
name="channel", description="ModLog Channel", opt_type=OptionTypes.CHANNEL, required=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
|
||||
self.update_settings("modlog", channel.id, ctx.guild.id)
|
||||
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:
|
||||
if not isinstance(channel, TextChannel):
|
||||
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}`")
|
||||
|
||||
|
||||
def setup(bot: commands.Bot) -> None:
|
||||
def setup(bot: Snake) -> None:
|
||||
"""Add SettingsCog to J.A.R.V.I.S."""
|
||||
SettingsCog(bot)
|
||||
|
|
Loading…
Add table
Reference in a new issue