From 1e8ef35e3fc9f18f86995144f671bfa853688126 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Fri, 23 Aug 2024 01:30:58 +0900 Subject: [PATCH] =?UTF-8?q?cursor=E3=81=8C=E8=A6=8B=E3=81=A4=E3=81=8B?= =?UTF-8?q?=E3=82=89=E3=81=AA=E3=81=84=E3=82=A8=E3=83=A9=E3=83=BC=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=9F=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/dislocker.py b/dislocker.py index b348162..7f5cf34 100644 --- a/dislocker.py +++ b/dislocker.py @@ -237,7 +237,8 @@ class Bot(discord.Client): return {"result": 1, "about": "error"} finally: - cursor.close() + if cursor: + cursor.close() def keyboard_used_check(self, **kwargs): try: @@ -263,7 +264,8 @@ class Bot(discord.Client): return {"result": 1, "about": "error"} finally: - cursor.close() + if cursor: + cursor.close() def mouse_used_check(self, **kwargs): try: @@ -289,11 +291,13 @@ class Bot(discord.Client): return {"result": 1, "about": "error"} finally: - cursor.close() + if cursor: + cursor.close() def register(self, **kwargs): try: + cursor = None user_info = { "id": str(kwargs["user_id"]), "name": str(kwargs["name"]), @@ -317,7 +321,6 @@ class Bot(discord.Client): pass else: user_info["mouse_number"] = int(kwargs["mouse_number"]) - cursor = dislocker.db.cursor() # ユーザー登録されているかの確認 user_register = self.user_register_check(discord_user_id=user_info["id"]) if user_register["result"] == 0: @@ -339,6 +342,7 @@ class Bot(discord.Client): password = self.password_generate(4) password_hash = self.hash_genarate(password) # PC使用履歴のテーブルにレコードを挿入 + cursor = dislocker.db.cursor() cursor.execute("INSERT INTO pc_usage_history (member_id, pc_number, keyboard_number, mouse_number, start_use_time, use_detail) VALUES (%s, %s, %s, %s, clock_timestamp(), %s)", (member_id, user_info["pc_number"], user_info["keyboard_number"], user_info["mouse_number"], user_info["detail"])) # PCリストの該当のレコードを更新 cursor.execute("UPDATE pc_list SET using_member_id = %s, password_hash = %s WHERE pc_number = %s", (member_id, password_hash, user_info["pc_number"])) @@ -371,7 +375,8 @@ class Bot(discord.Client): print(str(error)) return {"result": 1, "about": "error"} finally: - cursor.close() + if cursor: + cursor.close() def stop(self, **kwargs): @@ -434,7 +439,8 @@ class Bot(discord.Client): return {"result": 1, "about": "error"} finally: - cursor.close() + if cursor: + cursor.close() def user_register(self, **kwargs): try: @@ -459,7 +465,8 @@ class Bot(discord.Client): return {"result": 1, "about": "error"} finally: - cursor.close() + if cursor: + cursor.close() def format_datetime(self, value): @@ -488,7 +495,8 @@ class Bot(discord.Client): return {"result": 1, "about": "error"} finally: - cursor.close() + if cursor: + cursor.close() def report_export(self, **kwargs): try: @@ -562,7 +570,8 @@ class Bot(discord.Client): return {"result": 1, "about": "error"} finally: - cursor.close() + if cursor: + cursor.close() def force_stop(self, **kwargs): @@ -612,7 +621,8 @@ class Bot(discord.Client): return {"result": 1, "about": "error"} finally: - cursor.close() + if cursor: + cursor.close() async def timeout_notify(self, **kwargs): try: @@ -1002,7 +1012,8 @@ class Monitor(): dislocker.db.rollback() finally: - cursor.close() + if cursor: + cursor.close() print(result["result"]) return result