使用理由のプリセットを指定できるように
ログファイルを作成するように いくつか説明の追加
This commit is contained in:
parent
5384cc9668
commit
cf0013e53a
1 changed files with 127 additions and 83 deletions
206
dislocker.py
206
dislocker.py
|
@ -17,8 +17,10 @@ class DL():
|
|||
def __init__(self):
|
||||
self.config_dir_path = "./config/"
|
||||
self.export_dir_path = "./export/"
|
||||
self.log_dir_path = "./log/"
|
||||
self.server_config_path = self.config_dir_path + "server.json"
|
||||
self.onetime_config_path = self.config_dir_path + "onetime.json"
|
||||
self.log_path = self.log_dir_path + "dislocker.txt"
|
||||
try:
|
||||
if not os.path.isdir(self.config_dir_path):
|
||||
print("config ディレクトリが見つかりません... 作成します。")
|
||||
|
@ -50,7 +52,9 @@ class DL():
|
|||
"allowable_time": 180,
|
||||
"fstop_time": "21:00:00"
|
||||
},
|
||||
"admin_user_id": "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)"
|
||||
"preset_games": ["TEST1", "TEST2", "TEST3", "TEST4", "TEST5"],
|
||||
"admin_user_id": "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)",
|
||||
"debug": False
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,6 +72,10 @@ class DL():
|
|||
print("export ディレクトリが見つかりません... 作成します。")
|
||||
os.mkdir(self.export_dir_path)
|
||||
|
||||
if not os.path.isdir(self.log_dir_path):
|
||||
print("log ディレクトリが見つかりません... 作成します。")
|
||||
os.mkdir(self.log_dir_path)
|
||||
|
||||
if type(self.server_config["bot"]["log_channel_id"]) is not int or type(self.server_config["bot"]["config_channel_id"]) is not int:
|
||||
print("config ファイル内でチャンネルIDがint型で記述されていません。int型で記述して、起動してください。")
|
||||
self.init_result = "not_int"
|
||||
|
@ -78,6 +86,8 @@ class DL():
|
|||
self.pc_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
self.keyboard_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
self.mouse_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
self.preset_games = self.server_config["bot"]["preset_games"]
|
||||
self.debug = self.server_config["bot"]["debug"]
|
||||
|
||||
cursor.execute("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'club_member')")
|
||||
find_club_member_table = cursor.fetchall()
|
||||
|
@ -133,6 +143,53 @@ class DL():
|
|||
finally:
|
||||
pass
|
||||
|
||||
def log(self, **kwargs):
|
||||
if self.debug == True:
|
||||
flag = 1
|
||||
else:
|
||||
if "flag" in kwargs:
|
||||
if kwargs["flag"] == 1:
|
||||
flag = 1
|
||||
else:
|
||||
flag = 0
|
||||
else:
|
||||
flag = 0
|
||||
|
||||
if flag == 1:
|
||||
title = str(kwargs["title"])
|
||||
if "message" in kwargs:
|
||||
message = str(kwargs["message"])
|
||||
else:
|
||||
message = None
|
||||
|
||||
current_datetime = str(datetime.now())
|
||||
|
||||
if message == None:
|
||||
detail = f"{current_datetime} | {title}"
|
||||
else:
|
||||
detail = f"{current_datetime} | {title}\n{message}"
|
||||
|
||||
print(detail)
|
||||
|
||||
if os.path.isfile(self.log_path):
|
||||
try:
|
||||
with open(self.log_path, "a", encoding="utf-8") as a:
|
||||
a.write(detail)
|
||||
except:
|
||||
print("LOGGING ERROR mode a")
|
||||
else:
|
||||
try:
|
||||
with open(self.log_path, "w", encoding="utf-8") as w:
|
||||
w.write(detail)
|
||||
except:
|
||||
print("LOGGING ERROR mode w")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Bot(discord.Client):
|
||||
|
||||
|
@ -164,10 +221,7 @@ class Bot(discord.Client):
|
|||
return {"result": 1, "about": "user_data_not_found"}
|
||||
|
||||
except Exception as error:
|
||||
print("ユーザーの登録状態を調査中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
dislocker.log(title=f"[ERROR] ユーザーの登録状態を調査中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1)
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
|
@ -208,7 +262,6 @@ class Bot(discord.Client):
|
|||
cursor.execute("SELECT * FROM pc_usage_history WHERE member_id = %s ORDER BY id DESC LIMIT 1", (member_id,))
|
||||
pc_usage_history_record = cursor.fetchall()
|
||||
if pc_usage_history_record:
|
||||
print("used")
|
||||
if pc_usage_history_record[0][5] == None:
|
||||
return {"result": 1, "about": "used_by_you", "pc_usage_history": {"pc_number": str(pc_usage_history_record[0][2]), "keyboard_number": str(pc_usage_history_record[0][3]), "mouse_number": str(pc_usage_history_record[0][4]), "start_time": str(pc_usage_history_record[0][5]), "use_detail": str(pc_usage_history_record[0][7])}}
|
||||
else:
|
||||
|
@ -221,7 +274,6 @@ class Bot(discord.Client):
|
|||
cursor.execute("SELECT * FROM pc_usage_history WHERE member_id = %s ORDER BY id DESC LIMIT 1", (member_id,))
|
||||
pc_usage_history_record = cursor.fetchall()
|
||||
if pc_usage_history_record:
|
||||
print("used")
|
||||
if pc_usage_history_record[0][5] == None:
|
||||
return {"result": 1, "about": "used_by_you", "pc_usage_history": {"pc_number": str(pc_usage_history_record[0][2]), "keyboard_number": str(pc_usage_history_record[0][3]), "mouse_number": str(pc_usage_history_record[0][4]), "start_time": str(pc_usage_history_record[0][5]), "use_detail": str(pc_usage_history_record[0][7])}}
|
||||
else:
|
||||
|
@ -232,10 +284,7 @@ class Bot(discord.Client):
|
|||
return {"result": 1, "about": "search_options_error"}
|
||||
|
||||
except Exception as error:
|
||||
print("PCの使用状況を調査中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
dislocker.log(title=f"[ERROR] PCの使用状況を調査中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1)
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
|
@ -258,10 +307,7 @@ class Bot(discord.Client):
|
|||
return {"result": 1, "about": "keyboard_already_in_use_by_other"}
|
||||
|
||||
except Exception as error:
|
||||
print("キーボードの使用状況を調査中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
dislocker.log(title=f"[ERROR] キーボードの使用状況を調査中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1)
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
|
@ -284,10 +330,7 @@ class Bot(discord.Client):
|
|||
return {"result": 1, "about": "mouse_already_in_use_by_other"}
|
||||
|
||||
except Exception as error:
|
||||
print("マウスの使用状況を調査中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
dislocker.log(title=f"[ERROR] マウスの使用状況を調査中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1)
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
|
@ -331,15 +374,12 @@ class Bot(discord.Client):
|
|||
if pc_check_self["result"] == 0:
|
||||
# 他の人がそのPCを使っているか
|
||||
pc_check = self.pc_used_check(pc_number=user_info["pc_number"])
|
||||
print(pc_check)
|
||||
if pc_check["result"] == 0:
|
||||
# キーボードは使われているか
|
||||
keyboard_check = self.keyboard_used_check(keyboard_number=user_info["keyboard_number"])
|
||||
print(keyboard_check)
|
||||
if keyboard_check["result"] == 0:
|
||||
# マウスは使われているか
|
||||
mouse_check = self.mouse_used_check(mouse_number=user_info["mouse_number"])
|
||||
print(mouse_check)
|
||||
if mouse_check["result"] == 0:
|
||||
# パスワードとハッシュ作成
|
||||
password = self.password_generate(4)
|
||||
|
@ -372,10 +412,7 @@ class Bot(discord.Client):
|
|||
else:
|
||||
return {"result": 1, "about": "user_data_not_found"}
|
||||
except Exception as error:
|
||||
print("登録処理中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
dislocker.log(title=f"[ERROR] PCの使用登録中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1)
|
||||
return {"result": 1, "about": "error"}
|
||||
finally:
|
||||
if cursor:
|
||||
|
@ -436,10 +473,7 @@ class Bot(discord.Client):
|
|||
return {"result": 1, "about": "user_data_not_found"}
|
||||
|
||||
except Exception as error:
|
||||
print("停止処理中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
dislocker.log(title=f"[ERROR] PCの使用停止処理中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1)
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
|
@ -462,10 +496,7 @@ class Bot(discord.Client):
|
|||
return {"result": 1, "about": "already_exists"}
|
||||
|
||||
except Exception as error:
|
||||
print("ユーザー登録中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
dislocker.log(title=f"[ERROR] ユーザー情報の登録中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1)
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
|
@ -492,10 +523,7 @@ class Bot(discord.Client):
|
|||
return {"result": 1, "about": "already_exists"}
|
||||
|
||||
except Exception as error:
|
||||
print("PCの登録中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
dislocker.log(title=f"[ERROR] PCの情報を登録中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1)
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
|
@ -561,16 +589,12 @@ class Bot(discord.Client):
|
|||
|
||||
# Excelファイルを保存
|
||||
wb.save(excel_file_path)
|
||||
|
||||
print(f"テーブル '{main_table}' の内容を '{excel_file_path}' に出力しました。")
|
||||
dislocker.log(title=f"[SUCCESS] PCの使用履歴をエクスポートしました。", message=f"ファイルパス | {excel_file_path}", flag=0)
|
||||
return {"result": 0, "about": "ok", "file_path": excel_file_path}
|
||||
|
||||
|
||||
except Exception as error:
|
||||
print("使用履歴のエクスポート中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
dislocker.log(title=f"[ERROR] PCの使用履歴をエクスポート中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1)
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
|
@ -618,10 +642,7 @@ class Bot(discord.Client):
|
|||
return {"result": 1, "about": "bot_about_not_found"}
|
||||
|
||||
except Exception as error:
|
||||
print("fstop中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
dislocker.log(title=f"[ERROR] fstop中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1)
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
|
@ -645,7 +666,7 @@ class Bot(discord.Client):
|
|||
|
||||
|
||||
async def on_ready(self):
|
||||
print("DiscordのBotが起動しました。")
|
||||
dislocker.log(title=f"[SUCCESS] DiscordのBotが起動しました。", flag=1)
|
||||
dislocker_activity = discord.Activity(
|
||||
name=dislocker.server_config["bot"]["activity"]["name"],
|
||||
type=discord.ActivityType.competing,
|
||||
|
@ -734,16 +755,17 @@ class Bot(discord.Client):
|
|||
elif message.channel.id == dislocker.server_config["bot"]["config_channel_id"]:
|
||||
msg_split = message.content.split()
|
||||
if msg_split[0] == "/register":
|
||||
print(len(msg_split))
|
||||
if len(msg_split) == 1:
|
||||
register = self.user_register(name=message.author.display_name, discord_user_name=message.author.name, discord_user_id=message.author.id)
|
||||
print(register)
|
||||
if register["about"] == "ok":
|
||||
await message.channel.send(f"# :white_check_mark: ユーザー情報が登録されました。\n>>> ユーザー名:{message.author.display_name}")
|
||||
dislocker.log(title=f"[INFO] ユーザー情報が登録されました。", message=f"名前 | {message.author.display_name}, DiscordユーザーID | {message.author.id}, Discordユーザーネーム | {message.author.name}", flag=0)
|
||||
elif register["about"] == "already_exists":
|
||||
await message.channel.send("# :no_entry: 登録できませんでした。\nもう登録されている可能性があります。")
|
||||
dislocker.log(title=f"[INFO] 既存のユーザー情報は登録されませんでした。", message=f"名前 | {message.author.display_name}, DiscordユーザーID | {message.author.id}, Discordユーザーネーム | {message.author.name}", flag=0)
|
||||
else:
|
||||
await message.channel.send("# :no_entry: 登録できませんでした。\n内部エラーが発生しています。")
|
||||
dislocker.log(title=f"[INFO] 登録できなかったユーザーの情報です。", message=f"名前 | {message.author.display_name}, DiscordユーザーID | {message.author.id}, Discordユーザーネーム | {message.author.name}", flag=1)
|
||||
|
||||
elif len(msg_split) <= 3:
|
||||
await message.channel.send("# :japanese_goblin: 入力内容に不備があります。\n名前、Discordのユーザー名、DiscordのユーザーIDのいずれかが入力されていません。")
|
||||
|
@ -801,6 +823,7 @@ class Bot(discord.Client):
|
|||
else:
|
||||
await message.channel.send("# :warning: PCを登録できませんでした。\n構文が間違っています。\n-# /pcregister PC番号")
|
||||
|
||||
# /init ボタン月のメッセージ一式を指定チャンネルに送信
|
||||
elif msg_split[0] == "/init":
|
||||
user_register_button_view = View(timeout=None)
|
||||
user_register_button = discord.ui.Button(style=discord.ButtonStyle.green, label="ユーザー登録", custom_id="user_register")
|
||||
|
@ -820,7 +843,9 @@ class Bot(discord.Client):
|
|||
pc_button_view.add_item(pc_register_button)
|
||||
|
||||
await self.get_channel(dislocker.server_config["bot"]["config_public_channel_id"]).send(f'# :index_pointing_at_the_viewer: 使いたいPCの番号を選んでください!', view=pc_button_view)
|
||||
dislocker.log(title=f"[INFO] サーバーで初回処理を実行しました。", flag=0)
|
||||
|
||||
# /registerbutton PCの選択ボタンを指定チャンネルに送信
|
||||
elif msg_split[0] == "/registerbutton":
|
||||
pc_button_view = View(timeout=None)
|
||||
for i in dislocker.pc_list:
|
||||
|
@ -828,29 +853,32 @@ class Bot(discord.Client):
|
|||
pc_button_view.add_item(pc_register_button)
|
||||
|
||||
await self.get_channel(dislocker.server_config["bot"]["config_public_channel_id"]).send(f'# :index_pointing_at_the_viewer: 使いたいPCの番号を選んでください!', view=pc_button_view)
|
||||
dislocker.log(title=f"[INFO] サーバーでPC番号のボタンを送信しました。", flag=0)
|
||||
|
||||
# /stopbutton 利用停止のボタンを指定チャンネルに送信
|
||||
elif msg_split[0] == "/stopbutton":
|
||||
stop_button_view = View(timeout=None)
|
||||
stop_button = discord.ui.Button(style=discord.ButtonStyle.danger, label="PCの使用を停止", custom_id="stop")
|
||||
stop_button_view.add_item(stop_button)
|
||||
|
||||
await self.get_channel(dislocker.server_config["bot"]["config_public_channel_id"]).send(f'# :index_pointing_at_the_viewer: 使用を停止しますか?', view=stop_button_view)
|
||||
dislocker.log(title=f"[INFO] サーバーでPCの使用停止ボタンを送信しました。", flag=0)
|
||||
|
||||
# /userbutton ユーザー登録のボタンを指定チャンネルに送信
|
||||
elif msg_split[0] == "/userbutton":
|
||||
user_register_button_view = View(timeout=None)
|
||||
user_register_button = discord.ui.Button(style=discord.ButtonStyle.green, label="ユーザー登録", custom_id="user_register")
|
||||
user_register_button_view.add_item(user_register_button)
|
||||
|
||||
await self.get_channel(dislocker.server_config["bot"]["config_public_channel_id"]).send(f'# :index_pointing_at_the_viewer: ユーザー登録はお済ですか?', view=user_register_button_view)
|
||||
dislocker.log(title=f"[INFO] サーバーでユーザー登録ボタンを送信しました。", flag=0)
|
||||
|
||||
|
||||
elif message.channel.id == dislocker.server_config["bot"]["config_public_channel_id"]:
|
||||
msg_split = message.content.split()
|
||||
if msg_split[0] == "/register":
|
||||
print(len(msg_split))
|
||||
if len(msg_split) == 1:
|
||||
register = self.user_register(name=message.author.display_name, discord_user_name=message.author.name, discord_user_id=message.author.id)
|
||||
print(register)
|
||||
if register["about"] == "ok":
|
||||
await message.channel.send(f"# :white_check_mark: ユーザー情報が登録されました。\nユーザー名:{message.author.display_name}")
|
||||
elif register["about"] == "already_exists":
|
||||
|
@ -863,12 +891,11 @@ class Bot(discord.Client):
|
|||
async def on_button(self, interaction: Interaction):
|
||||
custom_id = interaction.data["custom_id"]
|
||||
custom_id_split = custom_id.split("_")
|
||||
print(custom_id, custom_id_split[0])
|
||||
dislocker.log(title=f"[INFO] ボタンが押されました。", message=f"custom_id | {custom_id}, DiscordユーザーID | {interaction.user.id}", flag=0)
|
||||
|
||||
if custom_id_split[0] == "pcregister":
|
||||
keyboard_register_view = View(timeout=15)
|
||||
pc_number = custom_id_split[1]
|
||||
print(custom_id_split)
|
||||
for i in dislocker.keyboard_list:
|
||||
keyboard_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i)}", custom_id=f"keyboardregister_{str(pc_number)}_{str(i)}")
|
||||
keyboard_register_view.add_item(keyboard_register_button)
|
||||
|
@ -885,7 +912,6 @@ class Bot(discord.Client):
|
|||
keyboard_number_show = "自前"
|
||||
else:
|
||||
keyboard_number_show = keyboard_number
|
||||
print(custom_id_split)
|
||||
for i in dislocker.mouse_list:
|
||||
mouse_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i)}", custom_id=f"mouseregister_{str(pc_number)}_{str(keyboard_number)}_{str(i)}")
|
||||
mouse_register_view.add_item(mouse_register_button)
|
||||
|
@ -907,6 +933,9 @@ class Bot(discord.Client):
|
|||
else:
|
||||
mouse_number_show = mouse_number
|
||||
reason_register_view = View(timeout=15)
|
||||
for i in dislocker.preset_games:
|
||||
reason_quick_button = reason_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i)}", custom_id=f"reasonregister_{str(pc_number)}_{str(keyboard_number)}_{str(mouse_number)}_quick_{str(i)}")
|
||||
reason_register_view.add_item(reason_quick_button)
|
||||
reason_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="使用目的を入力する", custom_id=f"reasonregister_{str(pc_number)}_{str(keyboard_number)}_{str(mouse_number)}")
|
||||
reason_register_view.add_item(reason_button)
|
||||
|
||||
|
@ -915,14 +944,41 @@ class Bot(discord.Client):
|
|||
elif custom_id_split[0] == "reasonregister":
|
||||
pc_number = custom_id_split[1]
|
||||
keyboard_number = custom_id_split[2]
|
||||
if keyboard_number == "own":
|
||||
keyboard_number_show = "自前"
|
||||
else:
|
||||
keyboard_number_show = keyboard_number
|
||||
mouse_number = custom_id_split[3]
|
||||
if mouse_number == "own":
|
||||
mouse_number_show = "自前"
|
||||
else:
|
||||
mouse_number_show = mouse_number
|
||||
if custom_id_split[4] == "quick":
|
||||
reason = custom_id_split[5]
|
||||
register = bot.register(discord_user_id=interaction.user.id, name=interaction.user.name, display_name=interaction.user.display_name, pc_number=pc_number, keyboard_number=keyboard_number, mouse_number=mouse_number, detail=reason)
|
||||
if register["about"] == "ok":
|
||||
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## 使用目的 | {reason}", ephemeral=True)
|
||||
await bot.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f':white_check_mark: {register["output_dict"]["name"]} さんがPC {pc_number} の使用を開始しました。\n>>> ## PC番号 | {pc_number}\n## キーボード番号 | {keyboard_number_show}\n## マウス番号 | {mouse_number_show}\n## 使用目的 | {reason}')
|
||||
dislocker.log(title=f"[INFO] PC番号{pc_number} の使用が開始されました。", message=f"名前 | {register["output_dict"]["name"]}, キーボード番号 | {keyboard_number_show}, マウス番号 | {mouse_number_show}, 使用目的 | {reason}", flag=0)
|
||||
elif register["about"] == "pc_already_in_use_by_you":
|
||||
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)
|
||||
elif register["about"] == "pc_already_in_use_by_other":
|
||||
await interaction.response.send_message(f"# :man_gesturing_no: そのPCは他のメンバーによって使用されています。\n別のPC番号を指定して、再度お試しください。", ephemeral=True)
|
||||
elif register["about"] == "keyboard_already_in_use":
|
||||
await interaction.response.send_message(f"# :man_gesturing_no: そのキーボードは他のメンバーによって使用されています。\n別のキーボードのデバイス番号を指定して、再度お試しください。", ephemeral=True)
|
||||
elif register["about"] == "mouse_already_in_use":
|
||||
await interaction.response.send_message(f"# :man_gesturing_no: そのマウスは他のメンバーによって使用されています。\n別のマウスのデバイス番号を指定して、再度お試しください。", ephemeral=True)
|
||||
elif register["about"] == "user_data_not_found":
|
||||
await interaction.response.send_message("# :dizzy_face: ユーザーとして登録されていないようです。\n最初にサーバーで登録を行ってください。", ephemeral=True)
|
||||
else:
|
||||
await interaction.response.send_message("# :skull_crossbones: 登録できませんでした。\n内部エラーが発生しています。", ephemeral=True)
|
||||
else:
|
||||
reason_input_form = Reason(title="Dislocker | 登録", pc_number=str(pc_number), keyboard_number=str(keyboard_number), mouse_number=str(mouse_number))
|
||||
await interaction.response.send_modal(reason_input_form)
|
||||
|
||||
elif custom_id_split[0] == "stop":
|
||||
print("STOP running")
|
||||
pc_stop = self.stop(discord_user_id=interaction.user.id)
|
||||
print(pc_stop)
|
||||
stop_view = View(timeout=15)
|
||||
if pc_stop["about"] == "unused":
|
||||
await interaction.response.send_message("# :shaking_face: 使用されていないようです...", ephemeral=True)
|
||||
|
@ -935,7 +991,6 @@ class Bot(discord.Client):
|
|||
await interaction.response.send_message("# :skull_crossbones: 停止できませんでした。\n内部エラーが発生しています。", ephemeral=True)
|
||||
|
||||
elif custom_id_split[0] == "user" and custom_id_split[1] == "register":
|
||||
print("User Register RUnning")
|
||||
user_register = self.user_register(name=interaction.user.display_name, discord_user_name=interaction.user.name, discord_user_id=interaction.user.id)
|
||||
if user_register["about"] == "ok":
|
||||
await interaction.response.send_message(f"# :white_check_mark: ユーザー情報が登録されました。\n>>> ユーザー名:{interaction.user.display_name}", ephemeral=True)
|
||||
|
@ -966,28 +1021,27 @@ class Monitor():
|
|||
current_datetime = datetime.now()
|
||||
fstop_time = self.fstop_time
|
||||
if current_datetime.time().strftime("%H:%M:%S") == fstop_time:
|
||||
dislocker.log(title=f"[INFO] 定期のPCの使用停止処理を開始します。", flag=0)
|
||||
for i in dislocker.pc_list:
|
||||
stop = bot.force_stop(pc_number=i, bot_about="使用停止忘れによるBotによる強制停止。")
|
||||
result = {"result": "FSTOP"}
|
||||
dislocker.log(title=f"[SUCCESS] 定期のPCの使用停止処理は完了しました。", flag=0)
|
||||
else:
|
||||
if pc_list:
|
||||
if len(pc_list) == 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", (member_id,))
|
||||
pc_usage = cursor.fetchall()
|
||||
print(pc_usage)
|
||||
start_time = pc_usage[0][5]
|
||||
print(start_time)
|
||||
print(type(start_time))
|
||||
time_difference = current_datetime - start_time
|
||||
print(current_datetime, start_time)
|
||||
print(time_difference.seconds, timedelta(seconds=self.allowable_time).seconds)
|
||||
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 = 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])
|
||||
dislocker.log(title=f"[INFO] パスワードのタイムアウト時間に達したため、強制停止されました。", flag=0)
|
||||
result = {"result": "STOP", "details": str(pc_usage)}
|
||||
else:
|
||||
result = {"result": "BUT SAFE", "details": str(pc_usage)}
|
||||
|
@ -995,22 +1049,19 @@ class Monitor():
|
|||
|
||||
elif len(pc_list) >= 2:
|
||||
for i in pc_list:
|
||||
print(i)
|
||||
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()
|
||||
print(pc_usage)
|
||||
start_time = pc_usage[0][5]
|
||||
print(start_time)
|
||||
print(type(start_time))
|
||||
time_difference = current_datetime - start_time
|
||||
print(time_difference.seconds, timedelta(seconds=self.allowable_time).seconds)
|
||||
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 = 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])
|
||||
dislocker.log(title=f"[INFO] パスワードのタイムアウト時間に達したため、強制停止されました。", flag=0)
|
||||
result = {"result": "STOP", "details": str(pc_usage)}
|
||||
else:
|
||||
result = {"result": "BUT SAFE", "details": str(pc_usage)}
|
||||
|
@ -1023,23 +1074,18 @@ class Monitor():
|
|||
if result["result"] == "NONE":
|
||||
pass
|
||||
else:
|
||||
print(current_datetime)
|
||||
print(result["result"])
|
||||
pass
|
||||
time.sleep(self.search_frequency)
|
||||
|
||||
|
||||
except Exception as error:
|
||||
print("自動停止処理中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
dislocker.log(title=f"[ERROR] 自動停止処理中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1)
|
||||
result = {"result": "error"}
|
||||
dislocker.db.rollback()
|
||||
|
||||
finally:
|
||||
if cursor:
|
||||
cursor.close()
|
||||
print(result["result"])
|
||||
return result
|
||||
|
||||
|
||||
|
@ -1047,13 +1093,11 @@ class Monitor():
|
|||
class Reason(Modal):
|
||||
def __init__(self, title: str, pc_number: str, keyboard_number: str, mouse_number: str, timeout=15) -> None:
|
||||
super().__init__(title=title, timeout=timeout)
|
||||
print(pc_number, keyboard_number, mouse_number)
|
||||
self.reason_input_form = TextInput(label="使用目的を入力してください", style=TextStyle.short, custom_id=f"register_{pc_number}_{keyboard_number}_{mouse_number}")
|
||||
self.add_item(self.reason_input_form)
|
||||
|
||||
async def on_submit(self, interaction: Interaction) -> None:
|
||||
custom_id = interaction.data["components"][0]["components"][0]["custom_id"]
|
||||
print(custom_id)
|
||||
custom_id_split = custom_id.split("_")
|
||||
pc_number = custom_id_split[1]
|
||||
keyboard_number = custom_id_split[2]
|
||||
|
@ -1068,11 +1112,11 @@ class Reason(Modal):
|
|||
mouse_number_show = mouse_number
|
||||
|
||||
register = bot.register(discord_user_id=interaction.user.id, name=interaction.user.name, display_name=interaction.user.display_name, pc_number=pc_number, keyboard_number=keyboard_number, mouse_number=mouse_number, detail=self.reason_input_form.value)
|
||||
print(register)
|
||||
|
||||
if register["about"] == "ok":
|
||||
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["output_dict"]["name"]} さんがPC {pc_number} の使用を開始しました。\n>>> ## PC番号 | {pc_number}\n## キーボード番号 | {keyboard_number_show}\n## マウス番号 | {mouse_number_show}\n## 使用目的 | {self.reason_input_form.value}')
|
||||
dislocker.log(title=f"[INFO] PC番号{pc_number} の使用が開始されました。", message=f"名前 | {register["output_dict"]["name"]}, キーボード番号 | {keyboard_number_show}, マウス番号 | {mouse_number_show}, 使用目的 | {self.reason_input_form.value}", flag=0)
|
||||
elif register["about"] == "pc_already_in_use_by_you":
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue