From 3ce947bb77289b1d92ab5e7f564189c46d7963a9 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sun, 1 Dec 2019 07:05:17 +0000 Subject: [PATCH] add database.users.get_nickname, to get nickname from ID --- src/Database.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Database.py b/src/Database.py index 7e25b03e..683de5a6 100644 --- a/src/Database.py +++ b/src/Database.py @@ -80,10 +80,15 @@ class Users(Table): self.database.execute("DELETE FROM users WHERE user_id=?", [user_id]) def get_id(self, server_id: int, nickname: str): - value = self.database.execute_fetchone("""SELECT user_id FROM - users WHERE server_id=? and nickname=?""", + value = self.database.execute_fetchone( + "SELECT user_id FROM users WHERE server_id=? and nickname=?", [server_id, nickname]) return value if value == None else value[0] + def get_nickname(self, server_id: int, user_id: int): + value = self.database.execute_fetchone( + "SELECT nickname FROM users WHERe server_id=? AND user_id=?", + [server_id, user_id]) + return (value or [None])[0] class BotSettings(Table): def set(self, setting: str, value: typing.Any):