Monitorを修正

This commit is contained in:
suti7yk5032 2024-08-23 02:04:41 +09:00
parent 3160f1c079
commit ef0bd4b509

View file

@ -358,7 +358,7 @@ class Bot(discord.Client):
else: else:
cursor.execute("UPDATE mouse_list SET using_member_id = %s WHERE mouse_number = %s", (member_id, user_info["mouse_number"])) cursor.execute("UPDATE mouse_list SET using_member_id = %s WHERE mouse_number = %s", (member_id, user_info["mouse_number"]))
dislocker.db.commit() dislocker.db.commit()
return {"result": 0, "about": "ok", "output": {"password": str(password), "name": str(discord_user_name)}} return {"result": 0, "about": "ok", "output_dict": {"password": str(password), "name": str(discord_user_name)}}
else: else:
return {"result": 1, "about": "mouse_already_in_use"} return {"result": 1, "about": "mouse_already_in_use"}
else: else:
@ -948,20 +948,20 @@ class Monitor():
else: else:
if pc_list: if pc_list:
if len(pc_list) == 1: if len(pc_list) == 1:
user_id = pc_list[0][1] member_id = pc_list[0][1]
cursor.execute("SELECT * FROM pc_usage_history WHERE member_id= %s AND end_use_time IS NULL ORDER BY id DESC LIMIT 1", (user_id,)) 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() pc_usage = cursor.fetchall()
print(pc_usage) print(pc_usage)
start_time = pc_usage[0][4] start_time = pc_usage[0][5]
print(start_time) print(start_time)
print(type(start_time)) print(type(start_time))
time_difference = current_datetime - start_time time_difference = current_datetime - start_time
print(current_datetime, start_time) print(current_datetime, start_time)
print(time_difference.seconds, timedelta(seconds=self.allowable_time).seconds) print(time_difference.seconds, timedelta(seconds=self.allowable_time).seconds)
if time_difference.seconds >= timedelta(seconds=self.allowable_time).seconds: if time_difference.seconds >= timedelta(seconds=self.allowable_time).seconds:
cursor.execute("SELECT * FROM club_member WHERE id = %s", (user_id,)) cursor.execute("SELECT * FROM club_member WHERE id = %s", (member_id,))
user_info = cursor.fetchall() user_info = cursor.fetchall()
stop = bot.stop(user_id=user_info[0][3], bot_about="パスワードのタイムアウトでBotによる強制停止。") stop = bot.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]) bot.timeout_notify(pc_number=pc_list[0][0], discord_display_name=user_info[0][1])
result = {"result": "STOP", "details": str(pc_usage)} result = {"result": "STOP", "details": str(pc_usage)}
@ -972,19 +972,19 @@ class Monitor():
elif len(pc_list) >= 2: elif len(pc_list) >= 2:
for i in pc_list: for i in pc_list:
print(i) print(i)
user_id = i[1] 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", (user_id,)) 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() pc_usage = cursor.fetchall()
print(pc_usage) print(pc_usage)
start_time = pc_usage[0][4] start_time = pc_usage[0][5]
print(start_time) print(start_time)
print(type(start_time)) print(type(start_time))
time_difference = current_datetime - start_time time_difference = current_datetime - start_time
print(time_difference.seconds, timedelta(seconds=self.allowable_time).seconds) print(time_difference.seconds, timedelta(seconds=self.allowable_time).seconds)
if time_difference.seconds >= timedelta(seconds=self.allowable_time).seconds: if time_difference.seconds >= timedelta(seconds=self.allowable_time).seconds:
cursor.execute("SELECT * FROM club_member WHERE id = %s", (user_id,)) cursor.execute("SELECT * FROM club_member WHERE id = %s", (member_id,))
user_info = cursor.fetchall() user_info = cursor.fetchall()
stop = bot.stop(user_id=user_info[0][3], bot_about="タイムアウトでBotによる強制停止。") stop = bot.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]) bot.timeout_notify(pc_number=i[0], discord_display_name=user_info[0][1])
result = {"result": "STOP", "details": str(pc_usage)} result = {"result": "STOP", "details": str(pc_usage)}
@ -1047,8 +1047,8 @@ class Reason(Modal):
print(register) print(register)
if register["about"] == "ok": if register["about"] == "ok":
await interaction.response.send_message(f":white_check_mark: 使用が開始されました。\n>>> # パスワード | {register["password"]}\n## PC番号 | {pc_number}\n## キーボード番号 | {keyboard_number_show}\n## マウス番号 | {mouse_number_show}\n## 使用目的 | {self.reason_input_form.value}", ephemeral=True) await interaction.response.send_message(f":white_check_mark: 使用が開始されました。\n>>> # パスワード | {register["output_dict"]["password"]}\n## PC番号 | {pc_number}\n## キーボード番号 | {keyboard_number_show}\n## マウス番号 | {mouse_number_show}\n## 使用目的 | {self.reason_input_form.value}", ephemeral=True)
await bot.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f':white_check_mark: {register["name"]} さんがPC {pc_number} の使用を開始しました。\n>>> ## キーボード番号 | {keyboard_number_show}\n## マウス番号 | {mouse_number_show}\n## 使用目的 | {self.reason_input_form.value}') await bot.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f':white_check_mark: {register["output_dict"]["name"]} さんがPC {pc_number} の使用を開始しました。\n>>> ## キーボード番号 | {keyboard_number_show}\n## マウス番号 | {mouse_number_show}\n## 使用目的 | {self.reason_input_form.value}')
elif register["about"] == "pc_already_in_use_by_you": elif register["about"] == "pc_already_in_use_by_you":
pc_usage_history = register["pc_usage_history"] pc_usage_history = register["pc_usage_history"]
await interaction.response.send_message(f"# :exploding_head: あなたはPCをもう使用されているようです。\n使用状態を解除するには 終了ボタン で使用終了をお知らせください。\n>>> # PC番号 | {pc_usage_history["pc_number"]}\n# キーボード番号 | {pc_usage_history["keyboard_number"]}\n# マウス番号 | {pc_usage_history["mouse_number"]}\n# 使用開始時刻 | {pc_usage_history["start_time"]}\n# 使用目的 | {pc_usage_history["use_detail"]}", ephemeral=True) await interaction.response.send_message(f"# :exploding_head: あなたはPCをもう使用されているようです。\n使用状態を解除するには 終了ボタン で使用終了をお知らせください。\n>>> # PC番号 | {pc_usage_history["pc_number"]}\n# キーボード番号 | {pc_usage_history["keyboard_number"]}\n# マウス番号 | {pc_usage_history["mouse_number"]}\n# 使用開始時刻 | {pc_usage_history["start_time"]}\n# 使用目的 | {pc_usage_history["use_detail"]}", ephemeral=True)