From f3b40986becb282b2ff1899ba45914ecd0f94a3b Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Tue, 31 Dec 2024 18:18:42 -0500 Subject: [PATCH] implement settings command --- nomen/settings.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/nomen/settings.py b/nomen/settings.py index ce6c5fa..dca39af 100644 --- a/nomen/settings.py +++ b/nomen/settings.py @@ -1,5 +1,7 @@ import logging +from typing import Literal +import disnake from disnake.ext.commands import Cog, group, guild_only 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.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)