From dba23585342ad893d2d0713968cb5e30d065c688 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Tue, 1 Oct 2024 11:51:29 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=91=E3=82=B9=E3=83=AF=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=81=AE=E3=82=BF=E3=82=A4=E3=83=A0=E3=82=A2=E3=82=A6=E3=83=88?= =?UTF-8?q?=E3=82=92=E9=80=9A=E7=9F=A5=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB,=20=E7=84=A1=E9=A7=84=E3=81=AA=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker.py | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/dislocker.py b/dislocker.py index 282571a..b15c720 100644 --- a/dislocker.py +++ b/dislocker.py @@ -988,8 +988,8 @@ class Monitor(): dislocker.log(title=f"[SUCCESS] 定期のPCの使用停止処理は完了しました。", flag=0) else: if pc_list: - if len(pc_list) == 1: - member_id = pc_list[0][1] + for i in pc_list: + member_id = i[1] cursor.execute("SELECT * FROM pc_usage_history WHERE member_id= %s AND end_use_time IS NULL ORDER BY id DESC LIMIT 1", (member_id,)) pc_usage = cursor.fetchall() start_time = pc_usage[0][5] @@ -998,36 +998,13 @@ class Monitor(): if time_difference.seconds >= timedelta(seconds=self.allowable_time).seconds: cursor.execute("SELECT * FROM club_member WHERE member_id = %s", (member_id,)) user_info = cursor.fetchall() - stop = dislocker.stop(discord_user_id=user_info[0][3], bot_about="パスワードのタイムアウトでBotによる強制停止。") - - #bot.timeout_notify(pc_number=pc_list[0][0], discord_display_name=user_info[0][1]) + stop = dislocker.stop(discord_user_id=user_info[0][3], bot_about="タイムアウトでBotによる強制停止。") + discord_user_id = dislocker.get_discord_user_id(member_id=member_id)["discord_user_id"] + asyncio.run(send_log(mode="timeout", pc_number=i[0], discord_user_id=discord_user_id)) dislocker.log(title=f"[INFO] パスワードのタイムアウト時間に達したため、強制停止されました。", flag=0) result = {"result": "STOP", "details": str(pc_usage)} else: result = {"result": "BUT SAFE", "details": str(pc_usage)} - - - elif len(pc_list) >= 2: - for i in pc_list: - member_id = i[1] - cursor.execute("SELECT * FROM pc_usage_history WHERE member_id= %s AND end_use_time IS NULL ORDER BY id DESC LIMIT 1", (member_id,)) - pc_usage = cursor.fetchall() - start_time = pc_usage[0][5] - time_difference = current_datetime - start_time - dislocker.log(title=f"[INFO] 現在確認されているパスワード未使用のユーザー", message=f"レコード | {str(pc_usage)}, 経過時間(Sec) | {time_difference.seconds}/{timedelta(seconds=self.allowable_time).seconds}", flag=0) - if time_difference.seconds >= timedelta(seconds=self.allowable_time).seconds: - cursor.execute("SELECT * FROM club_member WHERE member_id = %s", (member_id,)) - user_info = cursor.fetchall() - stop = dislocker.stop(discord_user_id=user_info[0][3], bot_about="タイムアウトでBotによる強制停止。") - - #bot.timeout_notify(pc_number=i[0], discord_display_name=user_info[0][1]) - dislocker.log(title=f"[INFO] パスワードのタイムアウト時間に達したため、強制停止されました。", flag=0) - result = {"result": "STOP", "details": str(pc_usage)} - else: - result = {"result": "BUT SAFE", "details": str(pc_usage)} - - else: - result = {"result": "NONE"} else: result = {"result": "NONE"} @@ -1087,6 +1064,9 @@ async def send_log(**kwargs): elif mode == "stop": log_embed = discord.Embed(title=f":stop_button: PC {pc_number} 番 | 使用終了通知", description=f"<@{discord_user_id}> さんはPCの使用を終了しました。", color=0xE512EB) + + elif mode == "timeout": + log_embed = discord.Embed(title=f":alarm_clock: PC {pc_number} 番 | タイムアウト通知", description=f"<@{discord_user_id}> さんが指定時間内にPCを使用しなかったため、停止されました。", color=0xE512EB) await client.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(embed=log_embed)