add short helpers for getting/changing user settings

This commit is contained in:
Infinidoge 2024-12-31 18:09:58 -05:00
parent 1573d0b046
commit d868427fc6
Signed by: Infinidoge
SSH key fingerprint: SHA256:GT2StvPQMMfFHyiiFJymQxfTG/z6EWLJ6NWItf5K5sA

View file

@ -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()