From d03d5ec4ef5bf9a237d6cb7fa6c7a5cca611d3af Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sun, 9 Jun 2024 18:49:46 +0900 Subject: [PATCH] =?UTF-8?q?=E8=BF=94=E3=82=8A=E5=80=A4=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/dislocker.py b/dislocker.py index 5d2cda2..1a3cfde 100644 --- a/dislocker.py +++ b/dislocker.py @@ -36,18 +36,21 @@ class Bot(discord.Client): user_record = cursor.fetchall() #ユーザーデータがなかったら(未登録の場合) if not user_record[0]: - return {"result": "user_data_not_found"} + result = {"result": "user_data_not_found"} + return result #ユーザーデータが見つかった場合(登録済みの場合) elif user_record[0]: cursor.execute("SELECT * FROM pc_usage_history WHERE member_id=%s ORDER BY id DESC LIMIT 1", (user_record[0][0],)) pc_usage_history_record = cursor.fetchall() if pc_usage_history_record[0][5] == None: - return {"result": "pc_already_in_use_by_you", "pc_number": str(pc_usage_history_record[0][2]), "device_number": str(pc_usage_history_record[0][3]), "start_time": str(pc_usage_history_record[0][4]), "detail": str(pc_usage_history_record[0][6])} + result = {"result": "pc_already_in_use_by_you", "pc_number": str(pc_usage_history_record[0][2]), "device_number": str(pc_usage_history_record[0][3]), "start_time": str(pc_usage_history_record[0][4]), "detail": str(pc_usage_history_record[0][6])} + return result elif pc_usage_history_record[0][5] == None: cursor.execute("SELECT * FROM pc_list WHERE pc_number=%s ORDER BY id DESC LIMIT 1", (pc_number,)) pc_list_record = cursor.fetchall() if not pc_list_record[0][1] == None: - return {"result": "pc_already_in_use_by_other"} + result = {"result": "pc_already_in_use_by_other"} + return result elif pc_list_record[0][1] == None: if detail == None: cursor.execute("INSERT INTO pc_usage_history (member_id, pc_number, device_number, start_use_time) VALUES (%s, %s, %s, current_timestamp)", (user_record[0][0], pc_number, device_number)) @@ -58,7 +61,8 @@ class Bot(discord.Client): cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (user_record[0][0], pc_number)) cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password_hash, pc_number)) self.db.commit() - return {"result": "ok", "password": str(password), "name": str(user_record[0][1])} + result = {"result": "ok", "password": str(password), "name": str(user_record[0][1])} + return result def stop(self, **kwrags): discord_user_id = str(kwrags["user_id"]) @@ -68,23 +72,26 @@ class Bot(discord.Client): cursor.execute("SELECT * FROM pc_usage_history WHERE member_id= %s ORDER BY id DESC LIMIT 1", (user_record[0][0],)) pc_usage_history_record = cursor.fetchall() if not pc_usage_history_record[0][5] == None: - return {"result": "unused"} + result = {"result": "unused"} + return result elif pc_usage_history_record[0][5] == None: cursor.execute("UPDATE pc_usage_history SET end_use_time = current_timestamp WHERE id = %s", (pc_usage_history_record[0][0],)) cursor.execute("UPDATE pc_list SET using_user_id = NULL WHERE pc_number = %s", (pc_usage_history_record[0][2],)) cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (pc_usage_history_record[0][2],)) self.db.commit() - return {"result": "ok", "pc_number": str(pc_usage_history_record[0][2]), "name": str(user_record[0][1])} + result = {"result": "ok", "pc_number": str(pc_usage_history_record[0][2]), "name": str(user_record[0][1])} + return result async def on_ready(self): print("ログイン成功") async def on_message(self, message): if message.author.bot: - return + pass if isinstance(message.channel, discord.DMChannel): msg_split = message.content.split() + print(msg_split) if msg_split[0] == "/password" or "/start": #メッセージの要素が2つ以下の場合は拒否 if len(msg_split) <= 2: