From d868427fc6d07c12c6fffb0d1e694298841fba3a Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Tue, 31 Dec 2024 18:09:58 -0500 Subject: [PATCH] add short helpers for getting/changing user settings --- nomen/main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nomen/main.py b/nomen/main.py index cd480bc..548daa1 100644 --- a/nomen/main.py +++ b/nomen/main.py @@ -90,11 +90,11 @@ class Nomen(Bot): await super().close() await self.db.close() - async def user_toggle(self, user_id, item): - await self.db.execute( - "REPLACE INTO users (user_id, {item}) VALUES(:user_id, iff((SELECT {item} FROM users WHERE user_id=:user_id)), 0, 1)", - {"user_id": user_id}, - ) + async def get_setting(self, user_id, setting): + return await self.db.fetch_singleton(f"SELECT {setting} FROM users WHERE user_id=?", (user_id,)) + + async def set_setting(self, user_id, setting, value: bool): + await self.db.execute(f"REPLACE INTO users (user_id, {setting}) VALUES(?, ?)", (user_id, value)) await self.db.commit()