implement settings command

This commit is contained in:
Infinidoge 2024-12-31 18:18:42 -05:00
parent 2bdf4f3e25
commit f3b40986be
Signed by: Infinidoge
SSH key fingerprint: SHA256:GT2StvPQMMfFHyiiFJymQxfTG/z6EWLJ6NWItf5K5sA

View file

@ -1,5 +1,7 @@
import logging import logging
from typing import Literal
import disnake
from disnake.ext.commands import Cog, group, guild_only from disnake.ext.commands import Cog, group, guild_only
from .utils import confirm from .utils import confirm
@ -108,3 +110,42 @@ You may want to `{ctx.clean_prefix}nomen export` first"""
await self.bot.db.execute("REPLACE INTO users (user_id, disabled) VALUES(?, 0)", (ctx.author.id,)) await self.bot.db.execute("REPLACE INTO users (user_id, disabled) VALUES(?, 0)", (ctx.author.id,))
await self.bot.db.commit() await self.bot.db.commit()
@group(invoke_without_command=True)
async def settings(
self,
ctx,
setting: Literal["use-embed", "notify-self", "bots-notify"],
value: bool,
):
"""
Change settings for Nomen
Valid settings are:
- `use-embed`
- `notify-self`
- `bots-notify`
"""
setting_db = setting.replace("-", "_")
await ctx.bot.set_setting(ctx.author.id, setting_db, value)
await self.settings_list(ctx)
@settings.command(name="list")
async def settings_list(self, ctx):
"""
Print all of your current settings
"""
settings = await ctx.bot.db.execute_fetchall(
"SELECT use_embed, notify_self, bots_notify FROM users WHERE user_id=?", (ctx.author.id,)
)
settings = ["Yes" if v else "No" for v in settings[0]]
embed = disnake.Embed(title="Current Settings")
embed.add_field("Use Embeds in Notifications (`use-embed`)", settings[0], inline=False)
embed.add_field("Notify Self (`notify-self`)", settings[1], inline=False)
embed.add_field("Notifications from Bots (`bots-notify`)", settings[2], inline=False)
await ctx.send(embed=embed)