From 71ca2c0cda309873ed931ea89b81ad965984a124 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Wed, 25 Sep 2024 14:50:11 +0900 Subject: [PATCH 01/41] =?UTF-8?q?=E3=82=B9=E3=83=A9=E3=83=83=E3=82=B7?= =?UTF-8?q?=E3=83=A5=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 142 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 dislocker_slash.py diff --git a/dislocker_slash.py b/dislocker_slash.py new file mode 100644 index 0000000..996c9b5 --- /dev/null +++ b/dislocker_slash.py @@ -0,0 +1,142 @@ +import discord +import os +import json +import psycopg2 +import datetime +import asyncio + +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 ディレクトリが見つかりません... 作成します。") + os.mkdir(self.config_dir_path) + + if not os.path.isfile(self.server_config_path): + print("config ファイルが見つかりません... 作成します。") + self.server_config = { + "db": { + "host": "localhost", + "port": "5432", + "db_name": "dislocker", + "username": "user", + "password": "password" + }, + "bot": { + "token": "TYPE HERE BOTS TOKEN KEY", + "activity": { + "name": "Dislocker", + "details": "ロック中...", + "type": "playing", + "state": "ロック中..." + }, + "log_channel_id" : "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)", + "config_channel_id": "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)", + "config_public_channel_id": "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)", + "monitor": { + "search_frequency": 1, + "allowable_time": 180, + "fstop_time": "21:00:00" + }, + "preset_games": ["TEST1", "TEST2", "TEST3", "TEST4", "TEST5"], + "admin_user_id": "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)", + "debug": False + } + } + + with open(self.server_config_path, "w", encoding="utf-8") as w: + json.dump(self.server_config, w, indent=4, ensure_ascii=False) + + + elif os.path.isfile(self.server_config_path): + with open(self.server_config_path, "r", encoding="utf-8") as r: + self.server_config = json.load(r) + print("config ファイルを読み込みました。") + + + if not os.path.isdir(self.export_dir_path): + 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) + + + self.init_result = "ok" + + except (Exception) as error: + print("初回処理でエラーが発生しました。\nエラー内容\n" + str(error)) + self.init_result = "error" + + 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}\n" + else: + detail = f"{current_datetime} | {title}\n{message}\n" + + 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") + +intents = discord.Intents.default() +intents.message_content = True + +client = discord.Client(intents=intents) +tree = discord.app_commands.CommandTree(client) + +@client.event +async def on_ready(): + print("Bot is ready.") + print("Logged in as") + print(client.user.name) + print(client.user.id) + print("------") + await tree.sync() + +@tree.command(name="use", description="パソコンの使用登録をします。") +async def use(interaction: discord.Interaction): + await interaction.response.send_message("パソコンの使用登録をします。", ephemeral=True) + +dislocker = DL() +client.run(dislocker.server_config["bot"]["token"]) \ No newline at end of file From fd8b5e3a8b01f7ea23e841b58618ba108e232ec2 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Wed, 25 Sep 2024 22:46:53 +0900 Subject: [PATCH 02/41] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=99=BB=E9=8C=B2?= =?UTF-8?q?=E3=80=81=E4=BD=BF=E7=94=A8=E5=81=9C=E6=AD=A2=E3=81=8C=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 566 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 561 insertions(+), 5 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 996c9b5..14e5fda 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -4,6 +4,10 @@ import json import psycopg2 import datetime import asyncio +import string +import random +import hashlib +import openpyxl class DL(): def __init__(self): @@ -67,9 +71,66 @@ class DL(): if not os.path.isdir(self.log_dir_path): print("log ディレクトリが見つかりません... 作成します。") os.mkdir(self.log_dir_path) - - self.init_result = "ok" + 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" + else: + self.db = psycopg2.connect(f"host={self.server_config['db']['host']} dbname={self.server_config['db']['db_name']} port={self.server_config['db']['port']} user={self.server_config['db']['username']} password={self.server_config['db']['password']}") + cursor = self.db.cursor() + + self.pc_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + self.keyboard_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + self.mouse_list = [0, 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() + print(find_club_member_table) + if find_club_member_table[0][0] == False: + cursor.execute("CREATE TABLE club_member (member_id SERIAL NOT NULL, name TEXT NOT NULL, discord_user_name TEXT NOT NULL, discord_user_id TEXT NOT NULL, PRIMARY KEY (member_id))") + self.db.commit() + + cursor.execute("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'pc_list')") + find_pc_list_table = cursor.fetchall() + print(find_pc_list_table) + if find_pc_list_table[0][0] == False: + cursor.execute("CREATE TABLE pc_list (pc_number INTEGER NOT NULL, using_member_id INTEGER, password_hash VARCHAR(64), pc_uuid VARCHAR(36), pc_token VARCHAR(36), master_password VARCHAR(16), detail TEXT, PRIMARY KEY (pc_number), FOREIGN KEY (using_member_id) REFERENCES club_member(member_id))") + for i in self.pc_list: + print(i) + cursor.execute("INSERT INTO pc_list (pc_number) VALUES (%s)", (i,)) + self.db.commit() + + cursor.execute("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'keyboard_list')") + find_keyboard_list_table = cursor.fetchall() + print(find_keyboard_list_table) + if find_keyboard_list_table[0][0] == False: + cursor.execute("CREATE TABLE keyboard_list (keyboard_number INTEGER NOT NULL, using_member_id INTEGER, device_instance_path TEXT, device_name TEXT, detail TEXT, PRIMARY KEY (keyboard_number), FOREIGN KEY (using_member_id) REFERENCES club_member(member_id))") + for i in self.keyboard_list: + print(i) + cursor.execute("INSERT INTO keyboard_list (keyboard_number) VALUES (%s)", (i,)) + self.db.commit() + + cursor.execute("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'mouse_list')") + find_mouse_list_table = cursor.fetchall() + print(find_mouse_list_table) + if find_mouse_list_table[0][0] == False: + cursor.execute("CREATE TABLE mouse_list (mouse_number INTEGER NOT NULL, using_member_id INTEGER, device_instance_path TEXT, device_name TEXT, detail TEXT, PRIMARY KEY (mouse_number), FOREIGN KEY (using_member_id) REFERENCES club_member(member_id))") + for i in self.mouse_list: + print(i) + cursor.execute("INSERT INTO mouse_list (mouse_number) VALUES (%s)", (i,)) + self.db.commit() + + cursor.execute("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'pc_usage_history')") + find_pc_usage_history_table = cursor.fetchall() + print(find_pc_usage_history_table) + if find_pc_usage_history_table[0][0] == False: + cursor.execute("CREATE TABLE pc_usage_history (id SERIAL NOT NULL, member_id INTEGER NOT NULL, pc_number INTEGER NOT NULL, keyboard_number INTEGER, mouse_number INTEGER, start_use_time TIMESTAMP NOT NULL, end_use_time TIMESTAMP, use_detail TEXT, bot_about TEXT, PRIMARY KEY (id), FOREIGN KEY (member_id) REFERENCES club_member(member_id), FOREIGN KEY (pc_number) REFERENCES pc_list(pc_number), FOREIGN KEY (keyboard_number) REFERENCES keyboard_list(keyboard_number), FOREIGN KEY (mouse_number) REFERENCES mouse_list(mouse_number))") + self.db.commit() + + cursor.close() + self.init_result = "ok" except (Exception) as error: print("初回処理でエラーが発生しました。\nエラー内容\n" + str(error)) @@ -118,6 +179,469 @@ class DL(): w.write(detail) except: print("LOGGING ERROR mode w") + + def password_generate(self, length): + numbers = string.digits # (1) + password = ''.join(random.choice(numbers) for _ in range(length)) # (2) + return password + + def hash_genarate(self, source): + hashed = hashlib.sha256(source.encode()) + return hashed.hexdigest() + + def user_register_check(self, **kwargs): + try: + discord_user_id = str(kwargs["discord_user_id"]) + + cursor = self.db.cursor() + + cursor.execute("SELECT * FROM club_member WHERE discord_user_id = %s", (discord_user_id,)) + user_record = cursor.fetchall() + #ユーザーデータが見つかった場合(登録済みの場合) + if user_record: + member_id = user_record[0][0] + name = user_record[0][1] + discord_user_name = user_record[0][2] + return {"result": 0, "about": "exist", "user_info": {"member_id": member_id, "name": name, "discord_user_name": discord_user_name}} + #ユーザーデータがなかったら(未登録の場合) + else: + return {"result": 1, "about": "user_data_not_found"} + + except Exception as error: + self.log(title=f"[ERROR] ユーザーの登録状態を調査中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error"} + + finally: + cursor.close() + + def pc_used_check(self, **kwargs): + try: + if "pc_number" in kwargs: + pc_number = int(kwargs["pc_number"]) + else: + pc_number = None + if "discord_user_id" in kwargs: + discord_user_id = str(kwargs["discord_user_id"]) + else: + discord_user_id = None + if "member_id" in kwargs: + member_id = int(kwargs["member_id"]) + else: + member_id = None + + cursor = self.db.cursor() + + if pc_number != None: + # pc番号を指定してpc_listから探す + cursor.execute("SELECT * FROM pc_list WHERE pc_number= %s", (pc_number,)) + pc_list_record = cursor.fetchall() + if pc_list_record[0][1] == None: + return {"result": 0, "about": "vacent"} + else: + return {"result": 1, "about": "used_by_other"} + elif discord_user_id != None: + #ユーザーIDを指定してPC使用履歴から探す + cursor.execute("SELECT * FROM club_member WHERE discord_user_id = %s", (discord_user_id,)) + user_record = cursor.fetchall() + #ユーザーデータが見つかった場合(登録済みの場合) + if user_record: + member_id = user_record[0][0] + 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: + if pc_usage_history_record[0][6] == None: + keyboard_number = pc_usage_history_record[0][3] + mouse_number = pc_usage_history_record[0][4] + + return {"result": 1, "about": "used_by_you", "pc_usage_history": {"pc_number": str(pc_usage_history_record[0][2]), "keyboard_number": keyboard_number, "mouse_number": mouse_number, "start_time": str(pc_usage_history_record[0][5]), "use_detail": str(pc_usage_history_record[0][7])}} + else: + return {"result": 0, "about": "vacent"} + else: + return {"result": 0, "about": "vacent"} + else: + return {"result": 1, "about": "user_data_not_found"} + elif member_id != None: + 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: + if pc_usage_history_record[0][6] == None: + keyboard_number = pc_usage_history_record[0][3] + mouse_number = pc_usage_history_record[0][4] + return {"result": 1, "about": "used_by_you", "pc_usage_history": {"pc_number": str(pc_usage_history_record[0][2]), "keyboard_number": keyboard_number, "mouse_number": mouse_number, "start_time": str(pc_usage_history_record[0][5]), "use_detail": str(pc_usage_history_record[0][7])}} + else: + return {"result": 0, "about": "vacent"} + else: + return {"result": 0, "about": "vacent"} + else: + return {"result": 1, "about": "search_options_error"} + + except Exception as error: + self.log(title=f"[ERROR] PCの使用状況を調査中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error"} + + finally: + if cursor: + cursor.close() + + def keyboard_used_check(self, **kwargs): + try: + cursor = self.db.cursor() + if kwargs["keyboard_number"] == None: + return {"result": 0, "about": "ok"} + else: + keyboard_number = int(kwargs["keyboard_number"]) + + cursor.execute("SELECT * FROM keyboard_list WHERE keyboard_number=%s", (keyboard_number,)) + keyboard_list_record = cursor.fetchall() + if keyboard_list_record[0][1] == None: + return {"result": 0, "about": "ok"} + else: + return {"result": 1, "about": "keyboard_already_in_use_by_other"} + + except Exception as error: + self.log(title=f"[ERROR] キーボードの使用状況を調査中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error"} + + finally: + if cursor: + cursor.close() + + def mouse_used_check(self, **kwargs): + try: + cursor = self.db.cursor() + if kwargs["mouse_number"] == None: + return {"result": 0, "about": "ok"} + else: + mouse_number = int(kwargs["mouse_number"]) + + cursor.execute("SELECT * FROM mouse_list WHERE mouse_number=%s", (mouse_number,)) + mouse_list_record = cursor.fetchall() + if mouse_list_record[0][1] == None: + return {"result": 0, "about": "ok"} + else: + return {"result": 1, "about": "mouse_already_in_use_by_other"} + + except Exception as error: + self.log(title=f"[ERROR] マウスの使用状況を調査中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error"} + + finally: + if cursor: + cursor.close() + + + def register(self, **kwargs): + try: + cursor = self.db.cursor() + user_info = { + "id": str(kwargs["discord_user_id"]), + "name": str(kwargs["name"]), + "display_name": str(kwargs["display_name"]), + "pc_number": int(kwargs["pc_number"]), + "keyboard_number": None, + "mouse_number": None, + "detail": None + } + if "detail" in kwargs: + user_info["detail"] = str(kwargs["detail"]) + else: + pass + + if kwargs["keyboard_number"] == "own": + pass + else: + user_info["keyboard_number"] = int(kwargs["keyboard_number"]) + + if kwargs["mouse_number"] == "own": + pass + else: + user_info["mouse_number"] = int(kwargs["mouse_number"]) + # ユーザー登録されているかの確認 + user_register = self.user_register_check(discord_user_id=user_info["id"]) + if user_register["result"] == 0: + member_id = user_register["user_info"]["member_id"] + name = user_register["user_info"]["name"] + # ユーザーがPCを使っているか + pc_check_self = self.pc_used_check(member_id=member_id) + if pc_check_self["result"] == 0: + # 他の人がそのPCを使っているか + pc_check = self.pc_used_check(pc_number=user_info["pc_number"]) + if pc_check["result"] == 0: + # キーボードは使われているか + keyboard_check = self.keyboard_used_check(keyboard_number=user_info["keyboard_number"]) + if keyboard_check["result"] == 0: + # マウスは使われているか + mouse_check = self.mouse_used_check(mouse_number=user_info["mouse_number"]) + if mouse_check["result"] == 0: + # パスワードとハッシュ作成 + password = self.password_generate(4) + password_hash = self.hash_genarate(password) + # PC使用履歴のテーブルにレコードを挿入 + + 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"])) + # キーボードリストの該当のレコードを自前(None)だったらスキップ、借りていたら更新 + if user_info["keyboard_number"] == None: + pass + else: + cursor.execute("UPDATE keyboard_list SET using_member_id = %s WHERE keyboard_number = %s", (member_id, user_info["keyboard_number"])) + # マウスも同様に + if user_info["mouse_number"] == None: + pass + else: + cursor.execute("UPDATE mouse_list SET using_member_id = %s WHERE mouse_number = %s", (member_id, user_info["mouse_number"])) + self.db.commit() + return {"result": 0, "about": "ok", "output_dict": {"password": str(password), "name": str(name)}} + else: + return {"result": 1, "about": "mouse_already_in_use"} + else: + return {"result": 1, "about": "keyboard_already_in_use"} + else: + return {"result": 1, "about": "pc_already_in_use_by_other"} + else: + return {"result": 1, "about": "pc_already_in_use_by_you", "pc_usage_history": {"pc_number": pc_check_self["pc_usage_history"]["pc_number"], "keyboard_number": pc_check_self["pc_usage_history"]["keyboard_number"], "mouse_number": pc_check_self["pc_usage_history"]["mouse_number"], "start_time": pc_check_self["pc_usage_history"]["start_time"], "use_detail": pc_check_self["pc_usage_history"]["use_detail"]}} + else: + return {"result": 1, "about": "user_data_not_found"} + except Exception as error: + self.log(title=f"[ERROR] PCの使用登録中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error"} + finally: + if cursor: + cursor.close() + + + def stop(self, **kwargs): + try: + cursor = self.db.cursor() + discord_user_id = str(kwargs["discord_user_id"]) + if "bot_about" in kwargs: + bot_about = kwargs["bot_about"] + else: + bot_about = None + + # ユーザーが登録してるかというよりはデータの取得のため + user_register = self.user_register_check(discord_user_id=discord_user_id) + member_id = user_register["user_info"]["member_id"] + name = user_register["user_info"]["name"] + + if user_register["result"] == 0: + 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: + pc_usage_history_id = pc_usage_history_record[0][0] + pc_number = pc_usage_history_record[0][2] + keyboard_number = pc_usage_history_record[0][3] + mouse_number = pc_usage_history_record[0][4] + end_use_time = pc_usage_history_record[0][6] + + # 使用中のとき (使用停止時間がNoneのとき) + if end_use_time == None: + # 利用停止の理由の有無を判断 + if bot_about == None: + cursor.execute("UPDATE pc_usage_history SET end_use_time = clock_timestamp() WHERE id = %s", (pc_usage_history_id,)) + else: + cursor.execute("UPDATE pc_usage_history SET end_use_time = clock_timestamp(), bot_about = %s WHERE id = %s", (bot_about, pc_usage_history_id)) + # pc_listの使用中ユーザーを消す + cursor.execute("UPDATE pc_list SET using_member_id = NULL, password_hash = NULL WHERE pc_number = %s", (pc_number,)) + if keyboard_number == None: + pass + else: + # keyboard_listの使用中ユーザーを消す + cursor.execute("UPDATE keyboard_list SET using_member_id = NULL WHERE keyboard_number = %s", (keyboard_number,)) + if mouse_number == None: + pass + else: + # mouse_listの使用中ユーザーを消す + cursor.execute("UPDATE mouse_list SET using_member_id = NULL WHERE mouse_number = %s", (mouse_number,)) + self.db.commit() + return {"result": 0, "about": "ok", "output_dict": {"pc_number": str(pc_number), "name": str(name)}} + else: + return {"result": 1, "about": "unused"} + else: + return {"result": 1, "about": "unused"} + else: + return {"result": 1, "about": "user_data_not_found"} + + except Exception as error: + self.log(title=f"[ERROR] PCの使用停止処理中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error"} + + finally: + if cursor: + cursor.close() + + def user_register(self, **kwargs): + try: + discord_user_id = str(kwargs["discord_user_id"]) + discord_user_name = str(kwargs["discord_user_name"]) + name = str(kwargs["name"]) + cursor = self.db.cursor() + cursor.execute("SELECT * FROM club_member WHERE discord_user_id = %s", (discord_user_id,)) + user_record = cursor.fetchall() + if not user_record: + cursor.execute("INSERT INTO club_member (name, discord_user_name, discord_user_id) VALUES (%s, %s, %s)", (name, discord_user_name, discord_user_id)) + self.db.commit() + return {"result": 0, "about": "ok"} + else: + return {"result": 1, "about": "already_exists"} + + except Exception as error: + self.log(title=f"[ERROR] ユーザー情報の登録中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error"} + + finally: + if cursor: + cursor.close() + + + def format_datetime(self, value): + if isinstance(value, datetime): + return value.strftime('%Y-%m-%d %H:%M:%S') + return value + + def pc_register(self, **kwargs): + try: + pc_number = int(kwargs["pc_number"]) + cursor = self.db.cursor() + cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s", (pc_number,)) + pc_list = cursor.fetchall() + if not pc_list: + cursor.execute("INSERT INTO pc_list (pc_number) VALUES (%s)", (pc_number,)) + self.db.commit() + return {"result": 0, "about": "ok"} + else: + return {"result": 1, "about": "already_exists"} + + except Exception as error: + self.log(title=f"[ERROR] PCの情報を登録中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error"} + + finally: + if cursor: + cursor.close() + + def report_export(self, **kwargs): + try: + cursor = self.db.cursor() + csv_file_path = self.export_dir_path + "pc_usage_history.csv" + main_table = "pc_usage_history" + related_table = "club_member" + excel_file_path = self.export_dir_path + "pc_usage_history.xlsx" + + # メインテーブルの列情報を取得(user_idを除く) + cursor.execute(psycopg2.sql.SQL("SELECT * FROM {} LIMIT 0").format(psycopg2.sql.Identifier(main_table))) + main_columns = [desc[0] for desc in cursor.description if desc[0] != 'member_id'] + + # クエリを作成(列名を明確に指定) + query = psycopg2.sql.SQL(""" + SELECT {main_columns}, {related_table}.name + FROM {main_table} + LEFT JOIN {related_table} ON {main_table}.member_id = {related_table}.member_id + ORDER BY id + """).format( + main_columns=psycopg2.sql.SQL(', ').join([psycopg2.sql.SQL("{}.{}").format(psycopg2.sql.Identifier(main_table), psycopg2.sql.Identifier(col)) for col in main_columns]), + main_table=psycopg2.sql.Identifier(main_table), + related_table=psycopg2.sql.Identifier(related_table) + ) + + cursor.execute(query) + + # 列名を再構成(nameを2番目に配置) + column_names = [main_columns[0], 'name'] + main_columns[1:] + + rows = cursor.fetchall() + + # Excelワークブックを作成 + wb = openpyxl.Workbook()() + ws = wb.active + + # 列名を書き込み + ws.append(column_names) + + # データを書き込み + for row in rows: + # nameを2番目に移動 + formatted_row = [self.format_datetime(row[0])] + [row[-1]] + [self.format_datetime(field) if field is not None else '' for field in row[1:-1]] + ws.append(formatted_row) + + # 列幅を自動調整 + for col in ws.columns: + max_length = 0 + column = col[0].column_letter + for cell in col: + try: + if len(str(cell.value)) > max_length: + max_length = len(str(cell.value)) + except: + pass + adjusted_width = (max_length + 2) * 1.2 + ws.column_dimensions[column].width = adjusted_width + + # Excelファイルを保存 + wb.save(excel_file_path) + self.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: + self.log(title=f"[ERROR] PCの使用履歴をエクスポート中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error"} + + finally: + if cursor: + cursor.close() + + + def force_stop(self, **kwargs): + try: + pc_number = kwargs["pc_number"] + cursor = self.db.cursor() + if "bot_about" in kwargs: + bot_about = kwargs["bot_about"] + cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s", (pc_number,)) + pc_list_record = cursor.fetchall() + pc_using_member_id = pc_list_record[0][1] + pc_password_hash = pc_list_record[0][2] + if pc_using_member_id == None: + return {"result": 1, "about": "not_used"} + else: + cursor.execute("UPDATE pc_list SET using_member_id = NULL WHERE pc_number = %s", (pc_number,)) + if pc_password_hash == None: + pass + else: + cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (pc_number,)) + cursor.execute("SELECT * FROM pc_usage_history WHERE member_id = %s AND pc_number = %s ORDER BY id DESC LIMIT 1", (pc_using_member_id, pc_number)) + pc_usage_history_record = cursor.fetchall() + pc_usage_history_record_id = pc_usage_history_record[0][0] + keyboard_number = pc_usage_history_record[0][3] + mouse_number = pc_usage_history_record[0][4] + if keyboard_number == None: + pass + else: + # keyboard_listの使用中ユーザーを消す + cursor.execute("UPDATE keyboard_list SET using_member_id = NULL WHERE keyboard_number = %s", (keyboard_number,)) + if mouse_number == None: + pass + else: + # mouse_listの使用中ユーザーを消す + cursor.execute("UPDATE mouse_list SET using_member_id = NULL WHERE mouse_number = %s", (mouse_number,)) + cursor.execute("UPDATE pc_usage_history SET end_use_time = clock_timestamp(), bot_about = %s WHERE id = %s", (bot_about, pc_usage_history_record_id)) + self.db.commit() + return {"result": 0, "about": "ok"} + else: + return {"result": 1, "about": "bot_about_not_found"} + + except Exception as error: + self.log(title=f"[ERROR] fstop中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error"} + + finally: + if cursor: + cursor.close() + +dislocker = DL() intents = discord.Intents.default() intents.message_content = True @@ -135,8 +659,40 @@ async def on_ready(): await tree.sync() @tree.command(name="use", description="パソコンの使用登録をします。") -async def use(interaction: discord.Interaction): - await interaction.response.send_message("パソコンの使用登録をします。", ephemeral=True) +async def use(interaction: discord.Interaction, pc_number: int, keyboard_number: int, mouse_number: int, detail: str): + register = dislocker.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=detail) + if register["result"] == 0: + await interaction.response.send_message(f":white_check_mark: 使用が開始されました。\n>>> # パスワード | {register["output_dict"]["password"]}\n## PC番号 | {pc_number}\n## 使用目的 | {detail}", ephemeral=True) + dislocker.log(title=f"[INFO] PC番号{pc_number} の使用が開始されました。", message=f"名前 | {register["output_dict"]["name"]}, 使用目的 | {detail}", flag=0) + await client.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## 使用目的 | {detail}') + elif register["result"] == 1: + if register["about"] == "pc_already_in_use_by_other": + await interaction.response.send_message(":x: 他の方がそのPCを使用中です。", ephemeral=True) + elif register["about"] == "pc_already_in_use_by_you": + await interaction.response.send_message(f":x: あなたは既にPC {register['pc_usage_history']['pc_number']} を使用中です。\n>>> ## PC番号 | {register['pc_usage_history']['pc_number']}\n## 使用目的 | {register['pc_usage_history']['use_detail']}", ephemeral=True) + elif register["about"] == "keyboard_already_in_use": + await interaction.response.send_message(":x: キーボードは既に使用中です。", ephemeral=True) + elif register["about"] == "mouse_already_in_use": + await interaction.response.send_message(":x: マウスは既に使用中です。", ephemeral=True) + elif register["about"] == "user_data_not_found": + await interaction.response.send_message(":x: ユーザーデータが見つかりませんでした。", ephemeral=True) + elif register["about"] == "error": + await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) + +@tree.command(name="stop", description="パソコンの使用を終了します。") +async def stop(interaction: discord.Interaction): + stop = dislocker.stop(discord_user_id=interaction.user.id) + if stop["result"] == 0: + await interaction.response.send_message(f":white_check_mark: 使用が終了されました。\n>>> ## PC番号 | {stop['output_dict']['pc_number']}", ephemeral=True) + dislocker.log(title=f"[INFO] PC番号{stop['output_dict']['pc_number']} の使用が終了されました。", message=f"名前 | {stop['output_dict']['name']}", flag=0) + await client.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f':white_check_mark: {stop["output_dict"]["name"]} さんがPC {stop["output_dict"]["pc_number"]} の使用を終了しました。\n>>> ## PC番号 | {stop["output_dict"]["pc_number"]}') + elif stop["result"] == 1: + if stop["about"] == "unused": + await interaction.response.send_message(":x: あなたはPCを使用していません。", ephemeral=True) + elif stop["about"] == "user_data_not_found": + await interaction.response.send_message(":x: ユーザーデータが見つかりませんでした。", ephemeral=True) + elif stop["about"] == "error": + await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) + -dislocker = DL() client.run(dislocker.server_config["bot"]["token"]) \ No newline at end of file From 0fc7c0c3ebe1df41b19d93b196f2b61825f0128a Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Wed, 25 Sep 2024 22:56:08 +0900 Subject: [PATCH 03/41] =?UTF-8?q?datetime=E3=81=AEimport=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3,=20=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8?= =?UTF-8?q?=E3=81=AE=E6=96=87=E8=A8=80=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 14e5fda..c5f2802 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -2,7 +2,7 @@ import discord import os import json import psycopg2 -import datetime +from datetime import datetime import asyncio import string import random @@ -658,7 +658,7 @@ async def on_ready(): print("------") await tree.sync() -@tree.command(name="use", description="パソコンの使用登録をします。") +@tree.command(name="use", description="パソコンの使用登録をします。通常はこのコマンドを使用する必要はありません。\n必要引数 : pc_number(PC番号), keyboard_number(キーボード番号), mouse_number(マウス番号), detail(使用目的)") async def use(interaction: discord.Interaction, pc_number: int, keyboard_number: int, mouse_number: int, detail: str): register = dislocker.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=detail) if register["result"] == 0: @@ -679,7 +679,7 @@ async def use(interaction: discord.Interaction, pc_number: int, keyboard_number: elif register["about"] == "error": await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) -@tree.command(name="stop", description="パソコンの使用を終了します。") +@tree.command(name="stop", description="パソコンの使用を終了します。通常はこのコマンドを使用する必要はありません。") async def stop(interaction: discord.Interaction): stop = dislocker.stop(discord_user_id=interaction.user.id) if stop["result"] == 0: @@ -688,11 +688,11 @@ async def stop(interaction: discord.Interaction): await client.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f':white_check_mark: {stop["output_dict"]["name"]} さんがPC {stop["output_dict"]["pc_number"]} の使用を終了しました。\n>>> ## PC番号 | {stop["output_dict"]["pc_number"]}') elif stop["result"] == 1: if stop["about"] == "unused": - await interaction.response.send_message(":x: あなたはPCを使用していません。", ephemeral=True) + await interaction.response.send_message("# :shaking_face: あなたはPCを使用されていないようです...", ephemeral=True) elif stop["about"] == "user_data_not_found": - await interaction.response.send_message(":x: ユーザーデータが見つかりませんでした。", ephemeral=True) + await interaction.response.send_message("# :dizzy_face: ユーザーとして登録されていないようです。\n最初にサーバーで登録を行ってください。", ephemeral=True) elif stop["about"] == "error": - await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) + await interaction.response.send_message("# :skull_crossbones: 停止できませんでした。\n内部エラーが発生しています。", ephemeral=True) client.run(dislocker.server_config["bot"]["token"]) \ No newline at end of file From 5578cffad6d0d57505cf9787507c6ca31c04e30c Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Wed, 25 Sep 2024 22:58:54 +0900 Subject: [PATCH 04/41] =?UTF-8?q?=E8=AA=AC=E6=98=8E=E6=96=87=E8=A8=80?= =?UTF-8?q?=E3=82=92100=E6=96=87=E5=AD=97=E4=BB=A5=E4=B8=8B=E3=81=AB?= =?UTF-8?q?=E6=8A=91=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index c5f2802..1996671 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -658,7 +658,7 @@ async def on_ready(): print("------") await tree.sync() -@tree.command(name="use", description="パソコンの使用登録をします。通常はこのコマンドを使用する必要はありません。\n必要引数 : pc_number(PC番号), keyboard_number(キーボード番号), mouse_number(マウス番号), detail(使用目的)") +@tree.command(name="use", description="パソコンの使用登録をします。通常はこのコマンドを使用する必要はありません。") async def use(interaction: discord.Interaction, pc_number: int, keyboard_number: int, mouse_number: int, detail: str): register = dislocker.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=detail) if register["result"] == 0: From 4f78a54b2f9db7ca2626e8d479f44acf2d6c15a3 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 08:42:54 +0900 Subject: [PATCH 05/41] =?UTF-8?q?=E3=82=B9=E3=83=A9=E3=83=83=E3=82=B7?= =?UTF-8?q?=E3=83=A5=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 117 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/dislocker_slash.py b/dislocker_slash.py index 1996671..a668adf 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -640,6 +640,64 @@ class DL(): finally: if cursor: cursor.close() + + def pc_onetime_gen(self): + try: + if os.path.isfile(dislocker.onetime_config_path): + with open(dislocker.onetime_config_path, "r") as r: + onetime_config = json.load(r) + onetime = onetime_config["onetime"]["pc_register"] + if onetime == None: + onetime = str(self.password_generate(8)) + onetime_config["onetime"]["pc_register"] = onetime + with open(dislocker.onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return {"result": 0, "about": "ok", "onetime": onetime} + else: + return {"result": 0, "already_exists": "ok", "onetime": onetime} + else: + onetime = str(self.password_generate(8)) + onetime_config = { + "onetime": { + "pc_register": onetime, + "device_register": None + } + } + with open(dislocker.onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return {"result": 0, "about": "ok", "onetime": onetime} + except Exception as error: + self.log(title=f"[ERROR] PC登録用のワンタイムパスワードを発行中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error"} + + def device_onetime_gen(self): + try: + if os.path.isfile(dislocker.onetime_config_path): + with open(dislocker.onetime_config_path, "r") as r: + onetime_config = json.load(r) + onetime = onetime_config["onetime"]["device_register"] + if onetime == None: + onetime = str(self.password_generate(8)) + onetime_config["onetime"]["device_register"] = onetime + with open(dislocker.onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return {"result": 0, "about": "ok", "onetime": onetime} + else: + return {"result": 0, "already_exists": "ok", "onetime": onetime} + else: + onetime = str(self.password_generate(8)) + onetime_config = { + "onetime": { + "pc_register": None, + "device_register": onetime + } + } + with open(dislocker.onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return {"result": 0, "about": "ok", "onetime": onetime} + except Exception as error: + self.log(title=f"[ERROR] デバイス登録用のワンタイムパスワードを発行中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error"} dislocker = DL() @@ -658,6 +716,7 @@ async def on_ready(): print("------") await tree.sync() +#使用者側のスラッシュコマンド @tree.command(name="use", description="パソコンの使用登録をします。通常はこのコマンドを使用する必要はありません。") async def use(interaction: discord.Interaction, pc_number: int, keyboard_number: int, mouse_number: int, detail: str): register = dislocker.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=detail) @@ -694,5 +753,63 @@ async def stop(interaction: discord.Interaction): elif stop["about"] == "error": await interaction.response.send_message("# :skull_crossbones: 停止できませんでした。\n内部エラーが発生しています。", ephemeral=True) +#管理者側のスラッシュコマンド +@tree.command(name="userreg", description="ユーザーを登録します。") +async def userreg(interaction: discord.Interaction, discord_user_id: str, discord_user_name: str, name: str): + user_register = dislocker.user_register(discord_user_id=discord_user_id, discord_user_name=discord_user_name, name=name) + if user_register["result"] == 0: + await interaction.response.send_message(":white_check_mark: ユーザーを登録しました。", ephemeral=True) + dislocker.log(title=f"[INFO] ユーザーを登録しました。", message=f"名前 | {name}, Discordユーザー名 | {discord_user_name}, DiscordユーザーID | {discord_user_id}", flag=0) + elif user_register["result"] == 1: + if user_register["about"] == "already_exists": + await interaction.response.send_message(":x: 既に登録されているユーザーです。", ephemeral=True) + elif user_register["about"] == "error": + await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) + +@tree.command(name="pcreg", description="PCを登録するためのワンタイムパスワードを発行します。") +async def pcreg(interaction: discord.Interaction): + onetime = dislocker.pc_onetime_gen() + if onetime["result"] == 0: + await interaction.response.send_message(f":white_check_mark: PC登録用のワンタイムパスワードを発行しました。\n>>> # ワンタイムパスワード | {onetime['onetime']}\n## 有効期限 | 1回の登録でのみ使用可能です。", ephemeral=True) + dislocker.log(title=f"[INFO] PC登録用のワンタイムパスワードを発行しました。", message=f"ワンタイムパスワード | {onetime['onetime']}", flag=0) + elif onetime["result"] == 1: + if onetime["about"] == "error": + await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) + +@tree.command(name="devicereg", description="デバイスを登録するためのワンタイムパスワードを発行します。") +async def devicereg(interaction: discord.Interaction): + onetime = dislocker.device_onetime_gen() + if onetime["result"] == 0: + await interaction.response.send_message(f":white_check_mark: デバイス登録用のワンタイムパスワードを発行しました。\n>>> # ワンタイムパスワード | {onetime['onetime']}\n## 有効期限 | 1回の登録でのみ使用可能です。", ephemeral=True) + dislocker.log(title=f"[INFO] デバイス登録用のワンタイムパスワードを発行しました。", message=f"ワンタイムパスワード | {onetime['onetime']}", flag=0) + elif onetime["result"] == 1: + if onetime["about"] == "error": + await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) + +@tree.command(name="fstop", description="PCの使用を強制終了します。") +async def fstop(interaction: discord.Interaction, pc_number: int, bot_about: str): + force_stop = dislocker.force_stop(pc_number=pc_number, bot_about=bot_about) + if force_stop["result"] == 0: + await interaction.response.send_message(f":white_check_mark: PC {pc_number} の使用を強制終了しました。", ephemeral=True) + dislocker.log(title=f"[INFO] PC {pc_number} の使用を強制終了しました。", message=f"理由 | {bot_about}", flag=0) + elif force_stop["result"] == 1: + if force_stop["about"] == "not_used": + await interaction.response.send_message(":x: そのPCは使用されていません。", ephemeral=True) + elif force_stop["about"] == "bot_about_not_found": + await interaction.response.send_message(":x: 理由が指定されていません。", ephemeral=True) + elif force_stop["about"] == "error": + await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) + +@tree.command(name="report", description="PCの使用履歴をエクスポートします。") +async def report(interaction: discord.Interaction): + report_export = dislocker.report_export() + if report_export["result"] == 0: + await interaction.response.send_message(f":white_check_mark: 使用履歴のレポートです。", file=discord.File(report_export["file_path"]), ephemeral=True) + dislocker.log(title=f"[INFO] PCの使用履歴をエクスポートしました。", message=f"ファイルパス | {report_export['file_path']}", flag=0) + elif report_export["result"] == 1: + if report_export["about"] == "error": + await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) + + client.run(dislocker.server_config["bot"]["token"]) \ No newline at end of file From f7f3e5d40b2f399b705f972949619012d5588ed5 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 09:25:31 +0900 Subject: [PATCH 06/41] =?UTF-8?q?sql=E3=81=AE=E3=82=A4=E3=83=B3=E3=83=9D?= =?UTF-8?q?=E3=83=BC=E3=83=88=E3=82=92=E4=BF=AE=E6=AD=A3=E3=80=81=E6=97=A5?= =?UTF-8?q?=E6=9C=AC=E8=AA=9E=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index a668adf..d27b18a 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -2,6 +2,7 @@ import discord import os import json import psycopg2 +from psycopg2 import sql from datetime import datetime import asyncio import string @@ -531,19 +532,19 @@ class DL(): excel_file_path = self.export_dir_path + "pc_usage_history.xlsx" # メインテーブルの列情報を取得(user_idを除く) - cursor.execute(psycopg2.sql.SQL("SELECT * FROM {} LIMIT 0").format(psycopg2.sql.Identifier(main_table))) + cursor.execute(sql.SQL("SELECT * FROM {} LIMIT 0").format(sql.Identifier(main_table))) main_columns = [desc[0] for desc in cursor.description if desc[0] != 'member_id'] # クエリを作成(列名を明確に指定) - query = psycopg2.sql.SQL(""" + query = sql.SQL(""" SELECT {main_columns}, {related_table}.name FROM {main_table} LEFT JOIN {related_table} ON {main_table}.member_id = {related_table}.member_id ORDER BY id """).format( - main_columns=psycopg2.sql.SQL(', ').join([psycopg2.sql.SQL("{}.{}").format(psycopg2.sql.Identifier(main_table), psycopg2.sql.Identifier(col)) for col in main_columns]), - main_table=psycopg2.sql.Identifier(main_table), - related_table=psycopg2.sql.Identifier(related_table) + main_columns=sql.SQL(', ').join([sql.SQL("{}.{}").format(sql.Identifier(main_table), sql.Identifier(col)) for col in main_columns]), + main_table=sql.Identifier(main_table), + related_table=sql.Identifier(related_table) ) cursor.execute(query) @@ -787,7 +788,9 @@ async def devicereg(interaction: discord.Interaction): await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) @tree.command(name="fstop", description="PCの使用を強制終了します。") -async def fstop(interaction: discord.Interaction, pc_number: int, bot_about: str): +async def fstop(interaction: discord.Interaction, PC番号: int, 理由: str): + pc_number = PC番号 + bot_about = 理由 force_stop = dislocker.force_stop(pc_number=pc_number, bot_about=bot_about) if force_stop["result"] == 0: await interaction.response.send_message(f":white_check_mark: PC {pc_number} の使用を強制終了しました。", ephemeral=True) From 3575818af885df169d79d5a3ab6c62e5c8a77c60 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 09:28:20 +0900 Subject: [PATCH 07/41] =?UTF-8?q?Workbook=E3=81=AE=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=83=9D=E3=83=BC=E3=83=88=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index d27b18a..50fd245 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -9,6 +9,7 @@ import string import random import hashlib import openpyxl +from openpyxl import Workbook class DL(): def __init__(self): @@ -555,7 +556,7 @@ class DL(): rows = cursor.fetchall() # Excelワークブックを作成 - wb = openpyxl.Workbook()() + wb = Workbook() ws = wb.active # 列名を書き込み From db16ddce29455382c73ca72c70ffe81fee49ecfc Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 09:29:19 +0900 Subject: [PATCH 08/41] =?UTF-8?q?=E6=97=A5=E6=9C=AC=E8=AA=9E=E4=BD=BF?= =?UTF-8?q?=E3=81=88=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E3=81=AE=E3=81=A7?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 50fd245..6484861 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -789,13 +789,11 @@ async def devicereg(interaction: discord.Interaction): await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) @tree.command(name="fstop", description="PCの使用を強制終了します。") -async def fstop(interaction: discord.Interaction, PC番号: int, 理由: str): - pc_number = PC番号 - bot_about = 理由 - force_stop = dislocker.force_stop(pc_number=pc_number, bot_about=bot_about) +async def fstop(interaction: discord.Interaction, pc_number: int, about: str): + force_stop = dislocker.force_stop(pc_number=pc_number, bot_about=about) if force_stop["result"] == 0: await interaction.response.send_message(f":white_check_mark: PC {pc_number} の使用を強制終了しました。", ephemeral=True) - dislocker.log(title=f"[INFO] PC {pc_number} の使用を強制終了しました。", message=f"理由 | {bot_about}", flag=0) + dislocker.log(title=f"[INFO] PC {pc_number} の使用を強制終了しました。", message=f"理由 | {about}", flag=0) elif force_stop["result"] == 1: if force_stop["about"] == "not_used": await interaction.response.send_message(":x: そのPCは使用されていません。", ephemeral=True) From f1967f0388dc13ad82308fb58ecd43ccb9f0dfa5 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 16:36:18 +0900 Subject: [PATCH 09/41] =?UTF-8?q?=E3=83=9C=E3=82=BF=E3=83=B3=E5=91=A8?= =?UTF-8?q?=E3=82=8A=E3=81=AE=E6=A9=9F=E8=83=BD=E3=82=92=E7=A7=BB=E6=A4=8D?= =?UTF-8?q?=E3=81=97=E3=81=A6=E3=81=8F=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 231 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) diff --git a/dislocker_slash.py b/dislocker_slash.py index 6484861..913b543 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -700,6 +700,67 @@ class DL(): except Exception as error: self.log(title=f"[ERROR] デバイス登録用のワンタイムパスワードを発行中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) return {"result": 1, "about": "error"} + + +class ReasonModal(discord.ui.Modal): + def __init__(self, title: str, pc_number: str, keyboard_number: str, mouse_number: str, timeout=15) -> None: + super().__init__(title=title, timeout=timeout) + self.reason_input_form = discord.ui.TextInput(label="使用目的を入力してください", style=discord.ui.TextInput.short, custom_id=f"register_{pc_number}_{keyboard_number}_{mouse_number}") + self.add_item(self.reason_input_form) + + async def on_submit(self, interaction: discord.Interaction) -> None: + custom_id = interaction.data["components"][0]["components"][0]["custom_id"] + custom_id_split = custom_id.split("_") + pc_number = custom_id_split[1] + keyboard_number = custom_id_split[2] + mouse_number = custom_id_split[3] + + if keyboard_number == "own": + keyboard_number_show = "自前" + else: + keyboard_number_show = keyboard_number + + if mouse_number == "own": + mouse_number_show = "自前" + else: + mouse_number_show = mouse_number + + register = dislocker.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) + + 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 client.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"]}, 使用目的 | {self.reason_input_form.value}", flag=0) + elif register["about"] == "pc_already_in_use_by_you": + pc_usage_history = register["pc_usage_history"] + if pc_usage_history["keyboard_number"] == None: + keyboard_number_show = "未認証" + elif pc_usage_history["keyboard_number"] == 0: + keyboard_number_show = "自前" + else: + keyboard_number_show = str(pc_usage_history["keyboard_number"]) + + if pc_usage_history["mouse_number"] == None: + mouse_number_show = "未認証" + elif pc_usage_history["mouse_number"] == 0: + mouse_number_show = "自前" + else: + mouse_number_show = str(pc_usage_history["mouse_number"]) + + await interaction.response.send_message(f"# :exploding_head: あなたはPCをもう使用されているようです。\n使用状態を解除するには 終了ボタン で使用終了をお知らせください。\n>>> # PC番号 | {pc_usage_history["pc_number"]}\n# キーボード番号 | {keyboard_number_show}\n# マウス番号 | {mouse_number_show}\n# 使用開始時刻 | {pc_usage_history["start_time"]}", ephemeral=True) + #await interaction.response.send_message(f"# :exploding_head: あなたはPCをもう使用されているようです。\n使用状態を解除するには 終了ボタン で使用終了をお知らせください。\n>>> # PC番号 | {pc_usage_history["pc_number"]}\n# キーボード番号 | {keyboard_number_show}\n# マウス番号 | {mouse_number_show}\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) + dislocker = DL() @@ -718,6 +779,154 @@ async def on_ready(): print("------") await tree.sync() +@client.event +async def on_button(interaction: discord.Interaction): + custom_id = interaction.data["custom_id"] + custom_id_split = custom_id.split("_") + 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 = discord.ui.View(timeout=15) + pc_number = custom_id_split[1] + 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) + keyboard_not_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="キーボードは自前", custom_id=f"keyboardregister_{str(pc_number)}_own") + keyboard_register_view.add_item(keyboard_not_register_button) + + await interaction.response.send_message(f"# :keyboard: キーボードのデバイス番号を選んでください!\n>>> # PC番号 | {str(pc_number)}", view=keyboard_register_view, ephemeral=True) + + elif custom_id_split[0] == "keyboardregister": + mouse_register_view = discord.ui.View(timeout=15) + 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 + 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) + mouse_not_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="マウスは自前", custom_id=f"mouseregister_{str(pc_number)}_{str(keyboard_number)}_own") + mouse_register_view.add_item(mouse_not_register_button) + + await interaction.response.send_message(f"# :mouse_three_button: マウスのデバイス番号を選んでください!\n>>> # PC番号 | {str(pc_number)}\n# キーボード番号 | {str(keyboard_number_show)}", view=mouse_register_view, ephemeral=True) + + elif custom_id_split[0] == "mouseregister": + pc_number = custom_id_split[1] + keyboard_number = custom_id_split[2] + mouse_number = custom_id_split[3] + + if keyboard_number == "own": + keyboard_number_show = "自前" + else: + keyboard_number_show = keyboard_number + + if mouse_number == "own": + mouse_number_show = "自前" + else: + mouse_number_show = mouse_number + + reason_register_view = discord.ui.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"quickreasonregister_{str(pc_number)}_{str(keyboard_number)}_{str(mouse_number)}_{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) + + await interaction.response.send_message(f"# :regional_indicator_q: 使用目的を書いてください!\n>>> # PC番号 | {str(pc_number)}\n# キーボード番号 | {str(keyboard_number_show)}\n# マウス番号 | {str(mouse_number_show)}", view=reason_register_view, ephemeral=True) + + elif custom_id_split[0] == "quickreasonregister": + pc_number = custom_id_split[1] + keyboard_number = custom_id_split[2] + mouse_number = custom_id_split[3] + + if keyboard_number == "own": + keyboard_number_show = "自前" + else: + keyboard_number_show = keyboard_number + + if mouse_number == "own": + mouse_number_show = "自前" + else: + mouse_number_show = mouse_number + + reason = custom_id_split[4] + + register = dislocker.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## キーボード番号 | {str(keyboard_number_show)}\n## マウス番号 | {str(mouse_number_show)}\n## 使用目的 | {reason}", ephemeral=True) + await client.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## 使用目的 | {reason}') + dislocker.log(title=f"[INFO] PC番号{pc_number} の使用が開始されました。", message=f"名前 | {register["output_dict"]["name"]}, 使用目的 | {reason}", flag=0) + elif register["about"] == "pc_already_in_use_by_you": + pc_usage_history = register["pc_usage_history"] + if pc_usage_history["keyboard_number"] == None: + keyboard_number_show = "未認証" + elif pc_usage_history["keyboard_number"] == 0: + keyboard_number_show = "自前" + else: + keyboard_number_show = str(pc_usage_history["keyboard_number"]) + + if pc_usage_history["mouse_number"] == None: + mouse_number_show = "未認証" + elif pc_usage_history["mouse_number"] == 0: + mouse_number_show = "自前" + else: + mouse_number_show = str(pc_usage_history["mouse_number"]) + await interaction.response.send_message(f"# :exploding_head: あなたはPCをもう使用されているようです。\n使用状態を解除するには 終了ボタン で使用終了をお知らせください。\n>>> # PC番号 | {pc_usage_history["pc_number"]}\n# キーボード番号 | {keyboard_number_show}\n# マウス番号 | {mouse_number_show}\n# 使用開始時刻 | {pc_usage_history["start_time"]}", ephemeral=True) + #await interaction.response.send_message(f"# :exploding_head: あなたはPCをもう使用されているようです。\n使用状態を解除するには 終了ボタン で使用終了をお知らせください。\n>>> # PC番号 | {pc_usage_history["pc_number"]}\n# キーボード番号 | {keyboard_number_show}\n# マウス番号 | {mouse_number_show}\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) + + elif custom_id_split[0] == "reasonregister": + pc_number = custom_id_split[1] + keyboard_number = custom_id_split[2] + mouse_number = custom_id_split[3] + + if keyboard_number == "own": + keyboard_number_show = "自前" + else: + keyboard_number_show = keyboard_number + + if mouse_number == "own": + mouse_number_show = "自前" + else: + mouse_number_show = mouse_number + + reason_input_form = ReasonModal(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": + pc_stop = dislocker.stop(discord_user_id=interaction.user.id) + stop_view = discord.ui.View(timeout=15) + if pc_stop["about"] == "unused": + await interaction.response.send_message("# :shaking_face: 使用されていないようです...", ephemeral=True) + elif pc_stop["about"] == "user_data_not_found": + await interaction.response.send_message("# :dizzy_face: ユーザーとして登録されていないようです。\n最初にサーバーで登録を行ってください。", ephemeral=True) + elif pc_stop["about"] == "ok": + await interaction.response.send_message(f":white_check_mark: PC番号 {pc_stop["output_dict"]["pc_number"]} の使用が終了されました。", ephemeral=True) + await client.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f':negative_squared_cross_mark: {pc_stop["output_dict"]["name"]} さんがPC {pc_stop["output_dict"]["pc_number"]} の使用を終了しました。') + else: + await interaction.response.send_message("# :skull_crossbones: 停止できませんでした。\n内部エラーが発生しています。", ephemeral=True) + + elif custom_id_split[0] == "user" and custom_id_split[1] == "register": + user_register = dislocker.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) + elif user_register["about"] == "already_exists": + await interaction.response.send_message("# :no_entry: 登録できませんでした。\nもう登録されている可能性があります。", ephemeral=True) + else: + await interaction.response.send_message("# :no_entry: 登録できませんでした。\n内部エラーが発生しています。", ephemeral=True) + + #使用者側のスラッシュコマンド @tree.command(name="use", description="パソコンの使用登録をします。通常はこのコマンドを使用する必要はありません。") async def use(interaction: discord.Interaction, pc_number: int, keyboard_number: int, mouse_number: int, detail: str): @@ -812,6 +1021,28 @@ async def report(interaction: discord.Interaction): if report_export["about"] == "error": await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) +@tree.command(name="init", description="操作チャンネルにボタン一式を送信します。") +async def button_init(interaction: discord.Interaction, text_channel: discord.TextChannel): + user_register_button_view = discord.ui.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 client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: ユーザー登録はお済ですか?', view=user_register_button_view) + + stop_button_view = discord.ui.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 client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: 使用を停止しますか?', view=stop_button_view) + + pc_button_view = discord.ui.View(timeout=None) + for i in dislocker.pc_list: + pc_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i)}", custom_id=f"pcregister_{str(i)}") + pc_button_view.add_item(pc_register_button) + + await client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: 使いたいPCの番号を選んでください!', view=pc_button_view) + dislocker.log(title=f"[INFO] サーバーで初回処理を実行しました。", flag=0) + client.run(dislocker.server_config["bot"]["token"]) \ No newline at end of file From fc16d15ef9002926abbf2236527771367a752cb4 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 16:52:48 +0900 Subject: [PATCH 10/41] =?UTF-8?q?=E3=83=9C=E3=82=BF=E3=83=B3=E5=91=A8?= =?UTF-8?q?=E3=82=8A=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 913b543..e75931e 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -761,7 +761,6 @@ class ReasonModal(discord.ui.Modal): else: await interaction.response.send_message("# :skull_crossbones: 登録できませんでした。\n内部エラーが発生しています。", ephemeral=True) - dislocker = DL() intents = discord.Intents.default() @@ -780,6 +779,13 @@ async def on_ready(): await tree.sync() @client.event +async def on_interaction(interaction: discord.Interaction): + try: + if interaction.data["component_type"] == 2: + await on_button(interaction) + except KeyError: + pass + async def on_button(interaction: discord.Interaction): custom_id = interaction.data["custom_id"] custom_id_split = custom_id.split("_") @@ -997,7 +1003,7 @@ async def devicereg(interaction: discord.Interaction): if onetime["about"] == "error": await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) -@tree.command(name="fstop", description="PCの使用を強制終了します。") +@tree.command(name="fstop", description="PCの使用登録を強制的に終了します。") async def fstop(interaction: discord.Interaction, pc_number: int, about: str): force_stop = dislocker.force_stop(pc_number=pc_number, bot_about=about) if force_stop["result"] == 0: @@ -1043,6 +1049,8 @@ async def button_init(interaction: discord.Interaction, text_channel: discord.Te await client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: 使いたいPCの番号を選んでください!', view=pc_button_view) dislocker.log(title=f"[INFO] サーバーで初回処理を実行しました。", flag=0) + await interaction.response.send_message(f":white_check_mark: ボタンを送信しました!", ephemeral=True) + client.run(dislocker.server_config["bot"]["token"]) \ No newline at end of file From 65d1f6e5686e8d8627b61d8e9e9b1a6250b80195 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 16:57:49 +0900 Subject: [PATCH 11/41] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=90=86=E7=94=B1?= =?UTF-8?q?=E3=81=AE=E3=83=A2=E3=83=BC=E3=83=80=E3=83=AB=E3=81=8C=E8=B5=B7?= =?UTF-8?q?=E5=8B=95=E3=81=97=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E3=83=90?= =?UTF-8?q?=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index e75931e..89a6a32 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -705,7 +705,7 @@ class DL(): class ReasonModal(discord.ui.Modal): def __init__(self, title: str, pc_number: str, keyboard_number: str, mouse_number: str, timeout=15) -> None: super().__init__(title=title, timeout=timeout) - self.reason_input_form = discord.ui.TextInput(label="使用目的を入力してください", style=discord.ui.TextInput.short, custom_id=f"register_{pc_number}_{keyboard_number}_{mouse_number}") + self.reason_input_form = discord.ui.TextInput(label="使用目的を入力してください", style=discord.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: discord.Interaction) -> None: @@ -795,8 +795,11 @@ async def on_button(interaction: discord.Interaction): keyboard_register_view = discord.ui.View(timeout=15) pc_number = custom_id_split[1] 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) + if i == 0: + pass + else: + 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) keyboard_not_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="キーボードは自前", custom_id=f"keyboardregister_{str(pc_number)}_own") keyboard_register_view.add_item(keyboard_not_register_button) @@ -811,8 +814,11 @@ async def on_button(interaction: discord.Interaction): else: keyboard_number_show = keyboard_number 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) + if i == 0: + pass + else: + 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) mouse_not_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="マウスは自前", custom_id=f"mouseregister_{str(pc_number)}_{str(keyboard_number)}_own") mouse_register_view.add_item(mouse_not_register_button) From ff30611ebda3a93a1ecc3c6b48325f19af2e05c7 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 17:01:20 +0900 Subject: [PATCH 12/41] =?UTF-8?q?=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=81=AE=E6=A8=A9=E9=99=90=E3=82=92=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dislocker_slash.py b/dislocker_slash.py index 89a6a32..72869c0 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -978,6 +978,7 @@ async def stop(interaction: discord.Interaction): #管理者側のスラッシュコマンド @tree.command(name="userreg", description="ユーザーを登録します。") +@discord.app_commands.default_permissions(administrator=True) async def userreg(interaction: discord.Interaction, discord_user_id: str, discord_user_name: str, name: str): user_register = dislocker.user_register(discord_user_id=discord_user_id, discord_user_name=discord_user_name, name=name) if user_register["result"] == 0: @@ -990,6 +991,7 @@ async def userreg(interaction: discord.Interaction, discord_user_id: str, discor await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) @tree.command(name="pcreg", description="PCを登録するためのワンタイムパスワードを発行します。") +@discord.app_commands.default_permissions(administrator=True) async def pcreg(interaction: discord.Interaction): onetime = dislocker.pc_onetime_gen() if onetime["result"] == 0: @@ -1000,6 +1002,7 @@ async def pcreg(interaction: discord.Interaction): await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) @tree.command(name="devicereg", description="デバイスを登録するためのワンタイムパスワードを発行します。") +@discord.app_commands.default_permissions(administrator=True) async def devicereg(interaction: discord.Interaction): onetime = dislocker.device_onetime_gen() if onetime["result"] == 0: @@ -1010,6 +1013,7 @@ async def devicereg(interaction: discord.Interaction): await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) @tree.command(name="fstop", description="PCの使用登録を強制的に終了します。") +@discord.app_commands.default_permissions(administrator=True) async def fstop(interaction: discord.Interaction, pc_number: int, about: str): force_stop = dislocker.force_stop(pc_number=pc_number, bot_about=about) if force_stop["result"] == 0: @@ -1024,6 +1028,7 @@ async def fstop(interaction: discord.Interaction, pc_number: int, about: str): await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) @tree.command(name="report", description="PCの使用履歴をエクスポートします。") +@discord.app_commands.default_permissions(administrator=True) async def report(interaction: discord.Interaction): report_export = dislocker.report_export() if report_export["result"] == 0: @@ -1034,6 +1039,7 @@ async def report(interaction: discord.Interaction): await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) @tree.command(name="init", description="操作チャンネルにボタン一式を送信します。") +@discord.app_commands.default_permissions(administrator=True) async def button_init(interaction: discord.Interaction, text_channel: discord.TextChannel): user_register_button_view = discord.ui.View(timeout=None) user_register_button = discord.ui.Button(style=discord.ButtonStyle.green, label="ユーザー登録", custom_id="user_register") From f13d119eb2dd324aae55aea41222b8f04f18b6ae Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 17:04:55 +0900 Subject: [PATCH 13/41] =?UTF-8?q?=E3=83=87=E3=83=90=E3=82=A4=E3=82=B9?= =?UTF-8?q?=E7=95=AA=E5=8F=B7=E3=81=8C=E8=87=AA=E5=89=8D=E3=81=AE=E6=99=82?= =?UTF-8?q?=E3=81=AB0=E3=82=92=E7=99=BB=E9=8C=B2=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 72869c0..a11ee02 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -340,8 +340,8 @@ class DL(): "name": str(kwargs["name"]), "display_name": str(kwargs["display_name"]), "pc_number": int(kwargs["pc_number"]), - "keyboard_number": None, - "mouse_number": None, + "keyboard_number": 0, + "mouse_number": 0, "detail": None } if "detail" in kwargs: From 6ea299f66141692fd9f676270075833048a102b9 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 17:16:15 +0900 Subject: [PATCH 14/41] =?UTF-8?q?asyncio=E5=B0=8E=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 100 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index a11ee02..a14f97f 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -3,7 +3,7 @@ import os import json import psycopg2 from psycopg2 import sql -from datetime import datetime +from datetime import datetime, timedelta import asyncio import string import random @@ -761,6 +761,92 @@ class ReasonModal(discord.ui.Modal): else: await interaction.response.send_message("# :skull_crossbones: 登録できませんでした。\n内部エラーが発生しています。", ephemeral=True) + +class Monitor(): + def __init__(self, **kwargs) -> None: + self.search_frequency = kwargs["search_frequency"] + self.allowable_time = kwargs["allowable_time"] + self.fstop_time = kwargs["fstop_time"] + self.init_wait_time = 10 + + async def search(self): + try: + asyncio.sleep(self.init_wait_time) + while True: + cursor = dislocker.db.cursor() + cursor.execute("SELECT * FROM pc_list WHERE password_hash IS NOT NULL") + pc_list = cursor.fetchall() + 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 = dislocker.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() + 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=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)} + + + 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"} + + if result["result"] == "NONE": + pass + else: + pass + asyncio.sleep(self.search_frequency) + + + except Exception as 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() + return result + + dislocker = DL() intents = discord.Intents.default() @@ -1064,5 +1150,15 @@ async def button_init(interaction: discord.Interaction, text_channel: discord.Te await interaction.response.send_message(f":white_check_mark: ボタンを送信しました!", ephemeral=True) +async def run(): + print("Botを起動します...") + monitor = Monitor(search_frequency=dislocker.server_config["bot"]["monitor"]["search_frequency"], allowable_time=dislocker.server_config["bot"]["monitor"]["allowable_time"], fstop_time=dislocker.server_config["bot"]["monitor"]["fstop_time"]) + monitor_task = asyncio.create_task(monitor.start()) + client_task = asyncio.create_task(client.run(dislocker.server_config["bot"]["token"])) + await asyncio.gather(monitor_task, client_task) + -client.run(dislocker.server_config["bot"]["token"]) \ No newline at end of file +if dislocker.init_result == "ok": + asyncio.run(run()) +else: + pass \ No newline at end of file From 1cd58404c68da57a7f710c314bab521e57ac0569 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 17:17:15 +0900 Subject: [PATCH 15/41] =?UTF-8?q?=E9=96=A2=E6=95=B0=E3=81=AE=E5=90=8D?= =?UTF-8?q?=E5=89=8D=E3=83=9F=E3=82=B9=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index a14f97f..93530de 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -1153,7 +1153,7 @@ async def button_init(interaction: discord.Interaction, text_channel: discord.Te async def run(): print("Botを起動します...") monitor = Monitor(search_frequency=dislocker.server_config["bot"]["monitor"]["search_frequency"], allowable_time=dislocker.server_config["bot"]["monitor"]["allowable_time"], fstop_time=dislocker.server_config["bot"]["monitor"]["fstop_time"]) - monitor_task = asyncio.create_task(monitor.start()) + monitor_task = asyncio.create_task(monitor.search()) client_task = asyncio.create_task(client.run(dislocker.server_config["bot"]["token"])) await asyncio.gather(monitor_task, client_task) From 885f62540391aaa8d7451ce40e00915583f3f7a8 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 17:26:48 +0900 Subject: [PATCH 16/41] =?UTF-8?q?asyncio=E3=82=92threading=E3=81=AB?= =?UTF-8?q?=E7=BD=AE=E3=81=8D=E6=8F=9B=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 93530de..10abe07 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -10,6 +10,8 @@ import random import hashlib import openpyxl from openpyxl import Workbook +import threading +import time class DL(): def __init__(self): @@ -769,9 +771,13 @@ class Monitor(): self.fstop_time = kwargs["fstop_time"] self.init_wait_time = 10 - async def search(self): + def start(self, **kwargs): + search_thread = threading.Thread(target=self.search) + search_thread.start() + + def search(self): try: - asyncio.sleep(self.init_wait_time) + time.sleep(self.init_wait_time) while True: cursor = dislocker.db.cursor() cursor.execute("SELECT * FROM pc_list WHERE password_hash IS NOT NULL") @@ -833,7 +839,7 @@ class Monitor(): pass else: pass - asyncio.sleep(self.search_frequency) + time.sleep(self.search_frequency) except Exception as error: @@ -1150,15 +1156,10 @@ async def button_init(interaction: discord.Interaction, text_channel: discord.Te await interaction.response.send_message(f":white_check_mark: ボタンを送信しました!", ephemeral=True) -async def run(): +if dislocker.init_result == "ok": print("Botを起動します...") monitor = Monitor(search_frequency=dislocker.server_config["bot"]["monitor"]["search_frequency"], allowable_time=dislocker.server_config["bot"]["monitor"]["allowable_time"], fstop_time=dislocker.server_config["bot"]["monitor"]["fstop_time"]) - monitor_task = asyncio.create_task(monitor.search()) - client_task = asyncio.create_task(client.run(dislocker.server_config["bot"]["token"])) - await asyncio.gather(monitor_task, client_task) - - -if dislocker.init_result == "ok": - asyncio.run(run()) + monitor.start() + client.run(dislocker.server_config["bot"]["token"]) else: - pass \ No newline at end of file + pass From 02e0b8b95d3e64eeec9c6a39edacc5f14851f078 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 17:30:21 +0900 Subject: [PATCH 17/41] =?UTF-8?q?=E3=82=A2=E3=82=AF=E3=83=86=E3=82=A3?= =?UTF-8?q?=E3=83=93=E3=83=86=E3=82=A3=E3=81=AE=E5=A4=89=E6=9B=B4=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E7=A7=BB=E6=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 10abe07..6a04f02 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -863,12 +863,15 @@ tree = discord.app_commands.CommandTree(client) @client.event async def on_ready(): - print("Bot is ready.") - print("Logged in as") - print(client.user.name) - print(client.user.id) - print("------") + dislocker.log(title=f"[SUCCESS] DiscordのBotが起動しました。", message=f"{client.user.name} としてログインしています。", flag=1) await tree.sync() + dislocker_activity = discord.Activity( + name=dislocker.server_config["bot"]["activity"]["name"], + type=discord.ActivityType.competing, + details=dislocker.server_config["bot"]["activity"]["details"], + state=dislocker.server_config["bot"]["activity"]["state"] + ) + await client.change_presence(activity=dislocker_activity) @client.event async def on_interaction(interaction: discord.Interaction): From 33dd3aef9b38c892a76f867314a864f1ee0fb30f Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 18:09:51 +0900 Subject: [PATCH 18/41] =?UTF-8?q?=E6=8C=87=E5=AE=9A=E3=83=A6=E3=83=BC?= =?UTF-8?q?=E3=82=B6=E3=83=BC=E3=81=AEDM=E3=81=AB=E3=81=93=E3=81=9F?= =?UTF-8?q?=E3=81=88=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/dislocker_slash.py b/dislocker_slash.py index 6a04f02..39f1b47 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -873,6 +873,96 @@ async def on_ready(): ) await client.change_presence(activity=dislocker_activity) +@client.event +async def on_message(self, message): + if message.author.bot: + pass + + elif isinstance(message.channel, discord.DMChannel): + if message.author.id == dislocker.server_config["bot"]["admin_user_id"]: + msg_split = message.content.split() + if msg_split[0] == "/pcreg": + max_count = 1 + if len(msg_split) == 2: + if msg_split[1].isdecimal(): + max_count = int(msg_split[1]) + + if os.path.isfile(dislocker.onetime_config_path): + with open(dislocker.onetime_config_path, "r") as r: + onetime_config = json.load(r) + onetime = onetime_config["onetime"]["pc_register"]["password"] + if onetime == None: + onetime = str(self.password_generate(8)) + onetime_config["onetime"]["pc_register"]["password"] = onetime + onetime_config["onetime"]["pc_register"]["max_count"] = max_count + with open(dislocker.onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + await message.channel.send(f"# :dizzy_face: PC登録時のワンタイムパスワードを発行します。\n# パスワード | {onetime}\n# 最大使用回数 | {str(max_count)}") + else: + await message.channel.send(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {onetime}\n# 残り使用回数 | {str(max_count - onetime_config['onetime']['pc_register']['current_count'])}") + else: + onetime = str(self.password_generate(8)) + onetime_config = { + "onetime": { + "pc_register": { + "password": onetime, + "current_count": 0, + "max_count": int(max_count) + }, + "device_register": { + "password": None, + "current_count": None, + "max_count": None + } + } + } + with open(dislocker.onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + await message.channel.send(f"# :dizzy_face: PC登録時のワンタイムパスワードを発行します。\n# パスワード | {onetime}\n# 最大使用回数 | {str(max_count)}") + elif msg_split[0] == "/devreg": + max_count = 1 + if len(msg_split) == 2: + if msg_split[1].isdecimal(): + max_count = int(msg_split[1]) + + if os.path.isfile(dislocker.onetime_config_path): + with open(dislocker.onetime_config_path, "r") as r: + onetime_config = json.load(r) + onetime = onetime_config["onetime"]["device_register"]["password"] + if onetime == None: + onetime = str(self.password_generate(8)) + onetime_config["onetime"]["device_register"]["password"] = onetime + onetime_config["onetime"]["device_register"]["max_count"] = max_count + with open(dislocker.onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + await message.channel.send(f"# :dizzy_face: デバイス登録時のワンタイムパスワードを発行します。\n# パスワード | {onetime}\n# 最大使用回数 | {str(max_count)}") + else: + await message.channel.send(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {onetime}\n# 残り使用回数 | {str(max_count - onetime_config['onetime']['device_register']['current_count'])}") + else: + onetime = str(self.password_generate(8)) + onetime_config = { + "onetime": { + "pc_register": { + "password": None, + "current_count": None, + "max_count": None + }, + "device_register": { + "password": onetime, + "current_count": 0, + "max_count": int(max_count) + } + } + } + with open(dislocker.onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + await message.channel.send(f"# :dizzy_face: デバイス登録時のワンタイムパスワードを発行します。\n# パスワード | {onetime}\n# 最大使用回数 | {str(max_count)}") + + else: + await message.channel.send("# :warning: DMでの応答は、現在無効化されています。") + else: + await message.channel.send("# :warning: DMでの応答は、現在無効化されています。") + @client.event async def on_interaction(interaction: discord.Interaction): try: From aebab83b866f3a502394f7b7bcef1e6fa79f329d Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 18:10:12 +0900 Subject: [PATCH 19/41] =?UTF-8?q?=E3=83=AF=E3=83=B3=E3=82=BF=E3=82=A4?= =?UTF-8?q?=E3=83=A0=E3=83=91=E3=82=B9=E3=83=AF=E3=83=BC=E3=83=89=E3=81=AE?= =?UTF-8?q?=E4=BB=95=E6=A7=98=E5=A4=89=E6=9B=B4=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_auth.py | 61 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/dislocker_auth.py b/dislocker_auth.py index a4b32be..0c08fcd 100644 --- a/dislocker_auth.py +++ b/dislocker_auth.py @@ -334,15 +334,29 @@ def register(): with open(onetime_config_path, "r") as r: onetime_config = json.load(r) - if onetime_password == onetime_config["onetime"]["pc_register"]: + if onetime_password == onetime_config["onetime"]["pc_register"]["password"]: register_result = auth.register(pc_number=pc_number, pc_uuid=pc_uuid) - pc_token = register_result["output_dict"]["pc_token"] - master_password = register_result["output_dict"]["master_password"] - master_password_hash = register_result["output_dict"]["master_password_hash"] - onetime_config["onetime"]["pc_register"] = None - with open(onetime_config_path, "w") as w: - json.dump(onetime_config, w, indent=4) - return jsonify({'message': 'ok', 'pc_token': pc_token, 'master_password': master_password, 'master_password_hash': master_password_hash}), 200 + if register_result["result"] == 0: + pc_token = register_result["output_dict"]["pc_token"] + master_password = register_result["output_dict"]["master_password"] + master_password_hash = register_result["output_dict"]["master_password_hash"] + onetime_config["onetime"]["pc_register"]["current_count"] += 1 + + if onetime_config["onetime"]["pc_register"]["current_count"] == onetime_config["onetime"]["pc_register"]["max_count"]: + onetime_config["onetime"]["pc_register"]["password"] = None + with open(onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return jsonify({'message': 'ok', 'pc_token': pc_token, 'master_password': master_password, 'master_password_hash': master_password_hash}), 200 + else: + with open(onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return jsonify({'message': 'ok', 'pc_token': pc_token, 'master_password': master_password, 'master_password_hash': master_password_hash}), 200 + elif register_result["result"] == 1: + if register_result["about"] == "exist": + return jsonify({'message': 'exist'}), 401 + else: + return jsonify({'message': 'damedesu'}), 401 + else: return jsonify({'message': 'damedesu'}), 401 else: @@ -410,22 +424,37 @@ def device_register(): device_register = auth.device_register(mode="keyboard", number=number, device_instance_path=device_instance_path, device_name=device_name) if device_register["result"] == 0: print(f"キーボード {number} 番の登録処理は成功しました.") - onetime_config["onetime"]["device_register"] = None - with open(onetime_config_path, "w") as w: - json.dump(onetime_config, w, indent=4) - return jsonify({'message': 'ok'}), 200 + onetime_config["onetime"]["device_register"]["current_count"] += 1 + + if onetime_config["onetime"]["device_register"]["current_count"] == onetime_config["onetime"]["device_register"]["max_count"]: + onetime_config["onetime"]["device_register"] = None + with open(onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return jsonify({'message': 'ok'}), 200 + else: + with open(onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return jsonify({'message': 'ok'}), 200 else: print(f"キーボード {number} 番の登録処理は失敗しました.") return jsonify({'message': 'error'}), 500 + elif mode == "mouse": print("マウスの登録処理を開始...") device_register = auth.device_register(mode="mouse", number=number, device_instance_path=device_instance_path, device_name=device_name) if device_register["result"] == 0: print(f"マウス {number} 番の登録処理は成功しました.") - onetime_config["onetime"]["device_register"] = None - with open(onetime_config_path, "w") as w: - json.dump(onetime_config, w, indent=4) - return jsonify({'message': 'ok'}), 200 + onetime_config["onetime"]["device_register"]["current_count"] += 1 + + if onetime_config["onetime"]["device_register"]["current_count"] == onetime_config["onetime"]["device_register"]["max_count"]: + onetime_config["onetime"]["device_register"] = None + with open(onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return jsonify({'message': 'ok'}), 200 + else: + with open(onetime_config_path, "w") as w: + json.dump(onetime_config, w, indent=4) + return jsonify({'message': 'ok'}), 200 else: print(f"マウス {number} 番の登録処理は失敗しました.") return jsonify({'message': 'error'}), 500 From 421b1b48c77d42153ffee8c49edc800bc8041928 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 21:05:43 +0900 Subject: [PATCH 20/41] =?UTF-8?q?=E3=82=B9=E3=83=A9=E3=83=83=E3=82=B7?= =?UTF-8?q?=E3=83=A5=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E3=81=AEPC?= =?UTF-8?q?=E3=80=81=E3=83=87=E3=83=90=E3=82=A4=E3=82=B9=E7=99=BB=E9=8C=B2?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 255 ++++++++++++++++++++++++++------------------- 1 file changed, 150 insertions(+), 105 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 39f1b47..4f7893b 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -645,62 +645,107 @@ class DL(): if cursor: cursor.close() - def pc_onetime_gen(self): + def pc_onetime_gen(self, **kwargs): + if kwargs.get("max_count") == None: + max_count = 1 + elif kwargs.get("max_count").isdecimal(): + max_count = int(kwargs.get("max_count")) + else: + max_count = 1 + try: if os.path.isfile(dislocker.onetime_config_path): with open(dislocker.onetime_config_path, "r") as r: onetime_config = json.load(r) - onetime = onetime_config["onetime"]["pc_register"] - if onetime == None: - onetime = str(self.password_generate(8)) - onetime_config["onetime"]["pc_register"] = onetime + onetime_password = onetime_config["onetime"]["pc_register"]["password"] + if onetime_password == None: + onetime_password = str(self.password_generate(8)) + onetime_config["onetime"]["pc_register"]["password"] = onetime_password + onetime_config["onetime"]["pc_register"]["max_count"] = max_count + onetime_config["onetime"]["pc_register"]["current_count"] = 0 + current_count = onetime_config["onetime"]["pc_register"]["current_count"] with open(dislocker.onetime_config_path, "w") as w: json.dump(onetime_config, w, indent=4) - return {"result": 0, "about": "ok", "onetime": onetime} + return {"result": 0, "about": "ok", "output_dict": {"onetime_password": onetime_password, "current_count": current_count, "max_count": max_count}} else: - return {"result": 0, "already_exists": "ok", "onetime": onetime} + current_count = onetime_config["onetime"]["pc_register"]["current_count"] + max_count = onetime_config["onetime"]["pc_register"]["max_count"] + return {"result": 1, "about": "already_exists", "output_dict": {"onetime_password": onetime_password, "current_count": current_count, "max_count": max_count}} else: - onetime = str(self.password_generate(8)) + onetime_password = str(self.password_generate(8)) onetime_config = { "onetime": { - "pc_register": onetime, - "device_register": None + "pc_register": { + "password": onetime_password, + "current_count": 0, + "max_count": int(max_count) + }, + "device_register": { + "password": None, + "current_count": None, + "max_count": None + } } } + current_count = onetime_config["onetime"]["pc_register"]["current_count"] with open(dislocker.onetime_config_path, "w") as w: json.dump(onetime_config, w, indent=4) - return {"result": 0, "about": "ok", "onetime": onetime} + return {"result": 0, "about": "ok", "output_dict": {"onetime_password": onetime_password, "current_count": current_count, "max_count": max_count}} + except Exception as error: - self.log(title=f"[ERROR] PC登録用のワンタイムパスワードを発行中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + self.log(title=f"[ERROR] PC登録用のワンタイムパスワード発行中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) return {"result": 1, "about": "error"} + - def device_onetime_gen(self): + def device_onetime_gen(self, **kwargs): + if kwargs.get("max_count") == None: + max_count = 1 + elif kwargs.get("max_count").isdecimal(): + max_count = int(kwargs.get("max_count")) + else: + max_count = 1 + try: if os.path.isfile(dislocker.onetime_config_path): with open(dislocker.onetime_config_path, "r") as r: onetime_config = json.load(r) - onetime = onetime_config["onetime"]["device_register"] - if onetime == None: - onetime = str(self.password_generate(8)) - onetime_config["onetime"]["device_register"] = onetime + onetime_password = onetime_config["onetime"]["device_register"]["password"] + if onetime_password == None: + onetime_password = str(self.password_generate(8)) + onetime_config["onetime"]["device_register"]["password"] = onetime_password + onetime_config["onetime"]["device_register"]["max_count"] = max_count + onetime_config["onetime"]["device_register"]["current_count"] = 0 + current_count = onetime_config["onetime"]["device_register"]["current_count"] with open(dislocker.onetime_config_path, "w") as w: json.dump(onetime_config, w, indent=4) - return {"result": 0, "about": "ok", "onetime": onetime} + return {"result": 0, "about": "ok", "output_dict": {"onetime_password": onetime_password, "current_count": current_count, "max_count": max_count}} else: - return {"result": 0, "already_exists": "ok", "onetime": onetime} + current_count = onetime_config["onetime"]["device_register"]["current_count"] + max_count = onetime_config["onetime"]["device_register"]["max_count"] + return {"result": 1, "about": "already_exists", "output_dict": {"onetime_password": onetime_password, "current_count": current_count, "max_count": max_count}} else: - onetime = str(self.password_generate(8)) + onetime_password = str(self.password_generate(8)) onetime_config = { "onetime": { - "pc_register": None, - "device_register": onetime + "pc_register": { + "password": None, + "current_count": None, + "max_count": None + }, + "device_register": { + "password": onetime_password, + "current_count": 0, + "max_count": int(max_count) + } } } + current_count = onetime_config["onetime"]["device_register"]["current_count"] with open(dislocker.onetime_config_path, "w") as w: json.dump(onetime_config, w, indent=4) - return {"result": 0, "about": "ok", "onetime": onetime} + return {"result": 0, "about": "ok", "output_dict": {"onetime_password": onetime_password, "current_count": current_count, "max_count": max_count}} + except Exception as error: - self.log(title=f"[ERROR] デバイス登録用のワンタイムパスワードを発行中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + self.log(title=f"[ERROR] PC登録用のワンタイムパスワード発行中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) return {"result": 1, "about": "error"} @@ -881,87 +926,61 @@ async def on_message(self, message): elif isinstance(message.channel, discord.DMChannel): if message.author.id == dislocker.server_config["bot"]["admin_user_id"]: msg_split = message.content.split() + if msg_split[0] == "/pcreg": max_count = 1 if len(msg_split) == 2: if msg_split[1].isdecimal(): max_count = int(msg_split[1]) + + pc_onetime_password_gen = dislocker.pc_onetime_gen(max_count=max_count) + + if pc_onetime_password_gen["result"] == 0: + pc_onetime_password = str(pc_onetime_password_gen["output_dict"]["onetime_password"]) + pc_onetime_password_max_count = str(pc_onetime_password_gen["output_dict"]["max_count"]) + pc_onetime_password_current_count = str(pc_onetime_password_gen["output_dict"]["current_count"]) + pc_onetime_password_remaining_times = str(int(pc_onetime_password_max_count) - int(pc_onetime_password_current_count)) - if os.path.isfile(dislocker.onetime_config_path): - with open(dislocker.onetime_config_path, "r") as r: - onetime_config = json.load(r) - onetime = onetime_config["onetime"]["pc_register"]["password"] - if onetime == None: - onetime = str(self.password_generate(8)) - onetime_config["onetime"]["pc_register"]["password"] = onetime - onetime_config["onetime"]["pc_register"]["max_count"] = max_count - with open(dislocker.onetime_config_path, "w") as w: - json.dump(onetime_config, w, indent=4) - await message.channel.send(f"# :dizzy_face: PC登録時のワンタイムパスワードを発行します。\n# パスワード | {onetime}\n# 最大使用回数 | {str(max_count)}") + await message.channel.send(f"# :dizzy_face: PC登録時のワンタイムパスワードを発行します。\n# パスワード | {pc_onetime_password}\n# 最大使用回数 | {pc_onetime_password_max_count}\n# 残り使用回数 | {pc_onetime_password_remaining_times}") + elif pc_onetime_password_gen["result"] == 1: + if pc_onetime_password_gen["about"] == "already_exists": + pc_onetime_password = str(pc_onetime_password_gen["output_dict"]["onetime_password"]) + pc_onetime_password_max_count = str(pc_onetime_password_gen["output_dict"]["max_count"]) + pc_onetime_password_current_count = str(pc_onetime_password_gen["output_dict"]["current_count"]) + pc_onetime_password_remaining_times = str(int(pc_onetime_password_max_count) - int(pc_onetime_password_current_count)) + await message.channel.send(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {pc_onetime_password}\n# 残り使用回数 | {pc_onetime_password_remaining_times}") else: - await message.channel.send(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {onetime}\n# 残り使用回数 | {str(max_count - onetime_config['onetime']['pc_register']['current_count'])}") - else: - onetime = str(self.password_generate(8)) - onetime_config = { - "onetime": { - "pc_register": { - "password": onetime, - "current_count": 0, - "max_count": int(max_count) - }, - "device_register": { - "password": None, - "current_count": None, - "max_count": None - } - } - } - with open(dislocker.onetime_config_path, "w") as w: - json.dump(onetime_config, w, indent=4) - await message.channel.send(f"# :dizzy_face: PC登録時のワンタイムパスワードを発行します。\n# パスワード | {onetime}\n# 最大使用回数 | {str(max_count)}") + await message.channel.send("# :skull_crossbones: ワンタイムパスワードの発行に失敗しました。") + elif msg_split[0] == "/devreg": max_count = 1 if len(msg_split) == 2: if msg_split[1].isdecimal(): max_count = int(msg_split[1]) - if os.path.isfile(dislocker.onetime_config_path): - with open(dislocker.onetime_config_path, "r") as r: - onetime_config = json.load(r) - onetime = onetime_config["onetime"]["device_register"]["password"] - if onetime == None: - onetime = str(self.password_generate(8)) - onetime_config["onetime"]["device_register"]["password"] = onetime - onetime_config["onetime"]["device_register"]["max_count"] = max_count - with open(dislocker.onetime_config_path, "w") as w: - json.dump(onetime_config, w, indent=4) - await message.channel.send(f"# :dizzy_face: デバイス登録時のワンタイムパスワードを発行します。\n# パスワード | {onetime}\n# 最大使用回数 | {str(max_count)}") + device_onetime_password_gen = dislocker.device_onetime_gen(max_count=max_count) + + if device_onetime_password_gen["result"] == 0: + device_onetime_password = str(device_onetime_password_gen["output_dict"]["onetime_password"]) + device_onetime_password_max_count = str(device_onetime_password_gen["output_dict"]["max_count"]) + device_onetime_password_current_count = str(device_onetime_password_gen["output_dict"]["current_count"]) + device_onetime_password_remaining_times = str(int(device_onetime_password_max_count) - int(device_onetime_password_current_count)) + + await message.channel.send(f"# :dizzy_face: デバイス登録時のワンタイムパスワードを発行します。\n# パスワード | {device_onetime_password}\n# 最大使用回数 | {device_onetime_password_max_count}\n# 残り使用回数 | {device_onetime_password_remaining_times}") + elif device_onetime_password_gen["result"] == 1: + if device_onetime_password_gen["about"] == "already_exists": + device_onetime_password = str(device_onetime_password_gen["output_dict"]["onetime_password"]) + device_onetime_password_max_count = str(device_onetime_password_gen["output_dict"]["max_count"]) + device_onetime_password_current_count = str(device_onetime_password_gen["output_dict"]["current_count"]) + device_onetime_password_remaining_times = str(int(device_onetime_password_max_count) - int(device_onetime_password_current_count)) + await message.channel.send(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {device_onetime_password}\n# 残り使用回数 | {device_onetime_password_remaining_times}") else: - await message.channel.send(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {onetime}\n# 残り使用回数 | {str(max_count - onetime_config['onetime']['device_register']['current_count'])}") - else: - onetime = str(self.password_generate(8)) - onetime_config = { - "onetime": { - "pc_register": { - "password": None, - "current_count": None, - "max_count": None - }, - "device_register": { - "password": onetime, - "current_count": 0, - "max_count": int(max_count) - } - } - } - with open(dislocker.onetime_config_path, "w") as w: - json.dump(onetime_config, w, indent=4) - await message.channel.send(f"# :dizzy_face: デバイス登録時のワンタイムパスワードを発行します。\n# パスワード | {onetime}\n# 最大使用回数 | {str(max_count)}") + await message.channel.send("# :skull_crossbones: ワンタイムパスワードの発行に失敗しました。") else: await message.channel.send("# :warning: DMでの応答は、現在無効化されています。") else: - await message.channel.send("# :warning: DMでの応答は、現在無効化されています。") + pass @client.event async def on_interaction(interaction: discord.Interaction): @@ -1175,27 +1194,53 @@ async def userreg(interaction: discord.Interaction, discord_user_id: str, discor elif user_register["about"] == "error": await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) -@tree.command(name="pcreg", description="PCを登録するためのワンタイムパスワードを発行します。") +@tree.command(name="pcreg", description="PCをDislockerに登録するためのワンタイムパスワードを発行します。") @discord.app_commands.default_permissions(administrator=True) -async def pcreg(interaction: discord.Interaction): - onetime = dislocker.pc_onetime_gen() - if onetime["result"] == 0: - await interaction.response.send_message(f":white_check_mark: PC登録用のワンタイムパスワードを発行しました。\n>>> # ワンタイムパスワード | {onetime['onetime']}\n## 有効期限 | 1回の登録でのみ使用可能です。", ephemeral=True) - dislocker.log(title=f"[INFO] PC登録用のワンタイムパスワードを発行しました。", message=f"ワンタイムパスワード | {onetime['onetime']}", flag=0) - elif onetime["result"] == 1: - if onetime["about"] == "error": - await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) +async def pcreg(interaction: discord.Interaction, how_much: int = 1): + max_count = how_much + + pc_onetime_password_gen = dislocker.pc_onetime_gen(max_count=max_count) + + if pc_onetime_password_gen["result"] == 0: + pc_onetime_password = str(pc_onetime_password_gen["output_dict"]["onetime_password"]) + pc_onetime_password_max_count = str(pc_onetime_password_gen["output_dict"]["max_count"]) + pc_onetime_password_current_count = str(pc_onetime_password_gen["output_dict"]["current_count"]) + pc_onetime_password_remaining_times = str(int(pc_onetime_password_max_count) - int(pc_onetime_password_current_count)) -@tree.command(name="devicereg", description="デバイスを登録するためのワンタイムパスワードを発行します。") + await interaction.response.send_message(f"# :dizzy_face: PC登録時のワンタイムパスワードを発行します。\n# パスワード | {pc_onetime_password}\n# 最大使用回数 | {pc_onetime_password_max_count}\n# 残り使用回数 | {pc_onetime_password_remaining_times}", ephemeral=True) + elif pc_onetime_password_gen["result"] == 1: + if pc_onetime_password_gen["about"] == "already_exists": + pc_onetime_password = str(pc_onetime_password_gen["output_dict"]["onetime_password"]) + pc_onetime_password_max_count = str(pc_onetime_password_gen["output_dict"]["max_count"]) + pc_onetime_password_current_count = str(pc_onetime_password_gen["output_dict"]["current_count"]) + pc_onetime_password_remaining_times = str(int(pc_onetime_password_max_count) - int(pc_onetime_password_current_count)) + await interaction.response.send_message(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {pc_onetime_password}\n# 残り使用回数 | {pc_onetime_password_remaining_times}", ephemeral=True) + else: + await interaction.response.send_message("# :skull_crossbones: ワンタイムパスワードの発行に失敗しました。", ephemeral=True) + +@tree.command(name="devicereg", description="デバイスをDislockerに登録するためのワンタイムパスワードを発行します。") @discord.app_commands.default_permissions(administrator=True) -async def devicereg(interaction: discord.Interaction): - onetime = dislocker.device_onetime_gen() - if onetime["result"] == 0: - await interaction.response.send_message(f":white_check_mark: デバイス登録用のワンタイムパスワードを発行しました。\n>>> # ワンタイムパスワード | {onetime['onetime']}\n## 有効期限 | 1回の登録でのみ使用可能です。", ephemeral=True) - dislocker.log(title=f"[INFO] デバイス登録用のワンタイムパスワードを発行しました。", message=f"ワンタイムパスワード | {onetime['onetime']}", flag=0) - elif onetime["result"] == 1: - if onetime["about"] == "error": - await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) +async def devicereg(interaction: discord.Interaction, how_much: int): + max_count = how_much + + device_onetime_password_gen = dislocker.device_onetime_gen(max_count=max_count) + + if device_onetime_password_gen["result"] == 0: + device_onetime_password = str(device_onetime_password_gen["output_dict"]["onetime_password"]) + device_onetime_password_max_count = str(device_onetime_password_gen["output_dict"]["max_count"]) + device_onetime_password_current_count = str(device_onetime_password_gen["output_dict"]["current_count"]) + device_onetime_password_remaining_times = str(int(device_onetime_password_max_count) - int(device_onetime_password_current_count)) + + await interaction.response.send_message(f"# :dizzy_face: デバイス登録時のワンタイムパスワードを発行します。\n# パスワード | {device_onetime_password}\n# 最大使用回数 | {device_onetime_password_max_count}\n# 残り使用回数 | {device_onetime_password_remaining_times}", ephemeral=True) + elif device_onetime_password_gen["result"] == 1: + if device_onetime_password_gen["about"] == "already_exists": + device_onetime_password = str(device_onetime_password_gen["output_dict"]["onetime_password"]) + device_onetime_password_max_count = str(device_onetime_password_gen["output_dict"]["max_count"]) + device_onetime_password_current_count = str(device_onetime_password_gen["output_dict"]["current_count"]) + device_onetime_password_remaining_times = str(int(device_onetime_password_max_count) - int(device_onetime_password_current_count)) + await interaction.response.send_message(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {device_onetime_password}\n# 残り使用回数 | {device_onetime_password_remaining_times}", ephemeral=True) + else: + await interaction.response.send_message("# :skull_crossbones: ワンタイムパスワードの発行に失敗しました。", ephemeral=True) @tree.command(name="fstop", description="PCの使用登録を強制的に終了します。") @discord.app_commands.default_permissions(administrator=True) From aa9379b2a6b3282c3709266a6ccf71097a827bd1 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 21:15:47 +0900 Subject: [PATCH 21/41] =?UTF-8?q?=E3=82=B9=E3=83=A9=E3=83=83=E3=82=B7?= =?UTF-8?q?=E3=83=A5=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E3=81=A7=E3=83=AF?= =?UTF-8?q?=E3=83=B3=E3=82=BF=E3=82=A4=E3=83=A0=E3=83=91=E3=82=B9=E3=83=AF?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=81=8C=E8=A6=81=E6=B1=82=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 4f7893b..262cacb 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -648,7 +648,7 @@ class DL(): def pc_onetime_gen(self, **kwargs): if kwargs.get("max_count") == None: max_count = 1 - elif kwargs.get("max_count").isdecimal(): + elif isinstance(kwargs.get("max_count"), int): max_count = int(kwargs.get("max_count")) else: max_count = 1 @@ -700,7 +700,7 @@ class DL(): def device_onetime_gen(self, **kwargs): if kwargs.get("max_count") == None: max_count = 1 - elif kwargs.get("max_count").isdecimal(): + elif isinstance(kwargs.get("max_count"), int): max_count = int(kwargs.get("max_count")) else: max_count = 1 From 224492568a6d1925ea81d6cb9f45194a7269b89a Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 21:22:08 +0900 Subject: [PATCH 22/41] =?UTF-8?q?=E8=B5=B7=E5=8B=95=E6=99=82=E3=81=AB?= =?UTF-8?q?=E3=83=AF=E3=83=B3=E3=82=BF=E3=82=A4=E3=83=A0=E3=83=91=E3=82=B9?= =?UTF-8?q?=E3=83=AF=E3=83=BC=E3=83=89=E3=82=92=E5=89=8A=E9=99=A4=E3=81=99?= =?UTF-8?q?=E3=82=8B=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 262cacb..8b77e51 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -66,7 +66,6 @@ class DL(): with open(self.server_config_path, "r", encoding="utf-8") as r: self.server_config = json.load(r) print("config ファイルを読み込みました。") - if not os.path.isdir(self.export_dir_path): print("export ディレクトリが見つかりません... 作成します。") @@ -79,6 +78,11 @@ class DL(): 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" + + if os.path.isfile(self.onetime_config_path): + print("ワンタイムパスワードが見つかりました。削除します。") + os.remove(self.onetime_config_path) + else: self.db = psycopg2.connect(f"host={self.server_config['db']['host']} dbname={self.server_config['db']['db_name']} port={self.server_config['db']['port']} user={self.server_config['db']['username']} password={self.server_config['db']['password']}") cursor = self.db.cursor() @@ -745,7 +749,7 @@ class DL(): return {"result": 0, "about": "ok", "output_dict": {"onetime_password": onetime_password, "current_count": current_count, "max_count": max_count}} except Exception as error: - self.log(title=f"[ERROR] PC登録用のワンタイムパスワード発行中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + self.log(title=f"[ERROR] デバイス登録用のワンタイムパスワード発行中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) return {"result": 1, "about": "error"} From 42e36bf1c480aa97e65f0b529f3d8a69564ccc15 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 21:24:49 +0900 Subject: [PATCH 23/41] =?UTF-8?q?if=E6=96=87=E3=81=AE=E3=83=9F=E3=82=B9?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=80=81on=5Fmessage=E3=81=AEself=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 8b77e51..c19a2bd 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -75,14 +75,13 @@ class DL(): 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" - if os.path.isfile(self.onetime_config_path): print("ワンタイムパスワードが見つかりました。削除します。") os.remove(self.onetime_config_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" else: self.db = psycopg2.connect(f"host={self.server_config['db']['host']} dbname={self.server_config['db']['db_name']} port={self.server_config['db']['port']} user={self.server_config['db']['username']} password={self.server_config['db']['password']}") cursor = self.db.cursor() @@ -923,7 +922,7 @@ async def on_ready(): await client.change_presence(activity=dislocker_activity) @client.event -async def on_message(self, message): +async def on_message(message): if message.author.bot: pass From 69cb9537ff90a963a34570426bfa170dd99b6b50 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 21:42:33 +0900 Subject: [PATCH 24/41] =?UTF-8?q?=E3=83=9E=E3=82=B9=E3=82=BF=E3=83=BC?= =?UTF-8?q?=E3=83=91=E3=82=B9=E3=83=AF=E3=83=BC=E3=83=89=E3=82=92=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=81=99=E3=82=8B=E3=82=B9=E3=83=A9=E3=83=83=E3=82=B7?= =?UTF-8?q?=E3=83=A5=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E3=81=A8=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/dislocker_slash.py b/dislocker_slash.py index c19a2bd..057a849 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -751,6 +751,23 @@ class DL(): self.log(title=f"[ERROR] デバイス登録用のワンタイムパスワード発行中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) return {"result": 1, "about": "error"} + def show_pc_master_password(self, **kwargs): + if isinstance(kwargs.get("pc_number"), int): + try: + pc_number = int(kwargs.get("pc_number")) + + cursor = self.db.cursor() + cursor.execute("SELECT master_password FROM pc_list WHERE pc_number = %s", (pc_number,)) + pc_master_password_list = cursor.fetchall() + pc_master_password = pc_master_password_list[0][0] + + return {"result": 0, "about": "ok", "output_dict": {"pc_master_password": pc_master_password}} + except Exception as error: + self.log(title=f"[ERROR] PCのマスターパスワードを取得中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error"} + else: + return {"result": 1, "about": "syntax_error"} + class ReasonModal(discord.ui.Modal): def __init__(self, title: str, pc_number: str, keyboard_number: str, mouse_number: str, timeout=15) -> None: @@ -1296,6 +1313,17 @@ async def button_init(interaction: discord.Interaction, text_channel: discord.Te await interaction.response.send_message(f":white_check_mark: ボタンを送信しました!", ephemeral=True) +@tree.command(name="masterpass", description="PCのマスターパスワードを表示します。") +@discord.app_commands.default_permissions(administrator=True) +async def masterpass(interaction: discord.Interaction, pc_number: int): + pc_master_password_get = dislocker.pc_master_password(pc_number=pc_number) + + if pc_master_password_get["result"] == 0: + pc_master_password = pc_master_password_get["output_dict"]["master_password"] + await interaction.response.send_message(f"# :key: PC番号 {pc_number} 番のマスターパスワードは以下の通りです。\n>>> # マスターパスワード | {pc_master_password}", ephemeral=True) + else: + await interaction.response.send_message("# :skull_crossbones: マスターパスワードの取得に失敗しました。", ephemeral=True) + if dislocker.init_result == "ok": print("Botを起動します...") From 6fae61351db941de56c6ac7a6cb8a048e05489d3 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 21:44:16 +0900 Subject: [PATCH 25/41] =?UTF-8?q?=E9=96=A2=E6=95=B0=E5=90=8D=E9=96=93?= =?UTF-8?q?=E9=81=95=E3=81=88=E3=81=A6=E3=81=9F=E3=81=AE=E3=81=A7=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_slash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 057a849..118dc43 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -1316,7 +1316,7 @@ async def button_init(interaction: discord.Interaction, text_channel: discord.Te @tree.command(name="masterpass", description="PCのマスターパスワードを表示します。") @discord.app_commands.default_permissions(administrator=True) async def masterpass(interaction: discord.Interaction, pc_number: int): - pc_master_password_get = dislocker.pc_master_password(pc_number=pc_number) + pc_master_password_get = dislocker.show_pc_master_password(pc_number=pc_number) if pc_master_password_get["result"] == 0: pc_master_password = pc_master_password_get["output_dict"]["master_password"] From 8775b227388bfdebe06bf462157f7a100f39f20c Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 21:45:56 +0900 Subject: [PATCH 26/41] =?UTF-8?q?=E3=82=AD=E3=83=BC=E5=90=8D=E3=82=82?= =?UTF-8?q?=E9=96=93=E9=81=95=E3=81=88=E3=81=A6=E3=81=9F=E3=81=AE=E3=81=A7?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 118dc43..4759b18 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -1319,7 +1319,7 @@ async def masterpass(interaction: discord.Interaction, pc_number: int): pc_master_password_get = dislocker.show_pc_master_password(pc_number=pc_number) if pc_master_password_get["result"] == 0: - pc_master_password = pc_master_password_get["output_dict"]["master_password"] + pc_master_password = pc_master_password_get["output_dict"]["pc_master_password"] await interaction.response.send_message(f"# :key: PC番号 {pc_number} 番のマスターパスワードは以下の通りです。\n>>> # マスターパスワード | {pc_master_password}", ephemeral=True) else: await interaction.response.send_message("# :skull_crossbones: マスターパスワードの取得に失敗しました。", ephemeral=True) From 364b32c0e796444949b73edbca950eb2ba6afa85 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 21:57:13 +0900 Subject: [PATCH 27/41] =?UTF-8?q?=E7=AE=A1=E7=90=86=E8=80=85=E3=82=B3?= =?UTF-8?q?=E3=83=9E=E3=83=B3=E3=83=89=E3=81=AE=E3=82=BB=E3=82=AD=E3=83=A5?= =?UTF-8?q?=E3=83=AA=E3=83=86=E3=82=A3=E3=81=AE=E5=90=91=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 166 ++++++++++++++++++++++++--------------------- 1 file changed, 87 insertions(+), 79 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 4759b18..0ccb343 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -37,6 +37,7 @@ class DL(): "password": "password" }, "bot": { + "server_id": "TYPE HERE SERVER ID", "token": "TYPE HERE BOTS TOKEN KEY", "activity": { "name": "Dislocker", @@ -1204,125 +1205,132 @@ async def stop(interaction: discord.Interaction): @tree.command(name="userreg", description="ユーザーを登録します。") @discord.app_commands.default_permissions(administrator=True) async def userreg(interaction: discord.Interaction, discord_user_id: str, discord_user_name: str, name: str): - user_register = dislocker.user_register(discord_user_id=discord_user_id, discord_user_name=discord_user_name, name=name) - if user_register["result"] == 0: - await interaction.response.send_message(":white_check_mark: ユーザーを登録しました。", ephemeral=True) - dislocker.log(title=f"[INFO] ユーザーを登録しました。", message=f"名前 | {name}, Discordユーザー名 | {discord_user_name}, DiscordユーザーID | {discord_user_id}", flag=0) - elif user_register["result"] == 1: - if user_register["about"] == "already_exists": - await interaction.response.send_message(":x: 既に登録されているユーザーです。", ephemeral=True) - elif user_register["about"] == "error": - await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) + if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + user_register = dislocker.user_register(discord_user_id=discord_user_id, discord_user_name=discord_user_name, name=name) + if user_register["result"] == 0: + await interaction.response.send_message(":white_check_mark: ユーザーを登録しました。", ephemeral=True) + dislocker.log(title=f"[INFO] ユーザーを登録しました。", message=f"名前 | {name}, Discordユーザー名 | {discord_user_name}, DiscordユーザーID | {discord_user_id}", flag=0) + elif user_register["result"] == 1: + if user_register["about"] == "already_exists": + await interaction.response.send_message(":x: 既に登録されているユーザーです。", ephemeral=True) + elif user_register["about"] == "error": + await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) @tree.command(name="pcreg", description="PCをDislockerに登録するためのワンタイムパスワードを発行します。") @discord.app_commands.default_permissions(administrator=True) async def pcreg(interaction: discord.Interaction, how_much: int = 1): - max_count = how_much - - pc_onetime_password_gen = dislocker.pc_onetime_gen(max_count=max_count) - - if pc_onetime_password_gen["result"] == 0: - pc_onetime_password = str(pc_onetime_password_gen["output_dict"]["onetime_password"]) - pc_onetime_password_max_count = str(pc_onetime_password_gen["output_dict"]["max_count"]) - pc_onetime_password_current_count = str(pc_onetime_password_gen["output_dict"]["current_count"]) - pc_onetime_password_remaining_times = str(int(pc_onetime_password_max_count) - int(pc_onetime_password_current_count)) - - await interaction.response.send_message(f"# :dizzy_face: PC登録時のワンタイムパスワードを発行します。\n# パスワード | {pc_onetime_password}\n# 最大使用回数 | {pc_onetime_password_max_count}\n# 残り使用回数 | {pc_onetime_password_remaining_times}", ephemeral=True) - elif pc_onetime_password_gen["result"] == 1: - if pc_onetime_password_gen["about"] == "already_exists": + if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + max_count = how_much + + pc_onetime_password_gen = dislocker.pc_onetime_gen(max_count=max_count) + + if pc_onetime_password_gen["result"] == 0: pc_onetime_password = str(pc_onetime_password_gen["output_dict"]["onetime_password"]) pc_onetime_password_max_count = str(pc_onetime_password_gen["output_dict"]["max_count"]) pc_onetime_password_current_count = str(pc_onetime_password_gen["output_dict"]["current_count"]) pc_onetime_password_remaining_times = str(int(pc_onetime_password_max_count) - int(pc_onetime_password_current_count)) - await interaction.response.send_message(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {pc_onetime_password}\n# 残り使用回数 | {pc_onetime_password_remaining_times}", ephemeral=True) - else: - await interaction.response.send_message("# :skull_crossbones: ワンタイムパスワードの発行に失敗しました。", ephemeral=True) + + await interaction.response.send_message(f"# :dizzy_face: PC登録時のワンタイムパスワードを発行します。\n# パスワード | {pc_onetime_password}\n# 最大使用回数 | {pc_onetime_password_max_count}\n# 残り使用回数 | {pc_onetime_password_remaining_times}", ephemeral=True) + elif pc_onetime_password_gen["result"] == 1: + if pc_onetime_password_gen["about"] == "already_exists": + pc_onetime_password = str(pc_onetime_password_gen["output_dict"]["onetime_password"]) + pc_onetime_password_max_count = str(pc_onetime_password_gen["output_dict"]["max_count"]) + pc_onetime_password_current_count = str(pc_onetime_password_gen["output_dict"]["current_count"]) + pc_onetime_password_remaining_times = str(int(pc_onetime_password_max_count) - int(pc_onetime_password_current_count)) + await interaction.response.send_message(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {pc_onetime_password}\n# 残り使用回数 | {pc_onetime_password_remaining_times}", ephemeral=True) + else: + await interaction.response.send_message("# :skull_crossbones: ワンタイムパスワードの発行に失敗しました。", ephemeral=True) @tree.command(name="devicereg", description="デバイスをDislockerに登録するためのワンタイムパスワードを発行します。") @discord.app_commands.default_permissions(administrator=True) async def devicereg(interaction: discord.Interaction, how_much: int): - max_count = how_much + if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + max_count = how_much - device_onetime_password_gen = dislocker.device_onetime_gen(max_count=max_count) + device_onetime_password_gen = dislocker.device_onetime_gen(max_count=max_count) - if device_onetime_password_gen["result"] == 0: - device_onetime_password = str(device_onetime_password_gen["output_dict"]["onetime_password"]) - device_onetime_password_max_count = str(device_onetime_password_gen["output_dict"]["max_count"]) - device_onetime_password_current_count = str(device_onetime_password_gen["output_dict"]["current_count"]) - device_onetime_password_remaining_times = str(int(device_onetime_password_max_count) - int(device_onetime_password_current_count)) - - await interaction.response.send_message(f"# :dizzy_face: デバイス登録時のワンタイムパスワードを発行します。\n# パスワード | {device_onetime_password}\n# 最大使用回数 | {device_onetime_password_max_count}\n# 残り使用回数 | {device_onetime_password_remaining_times}", ephemeral=True) - elif device_onetime_password_gen["result"] == 1: - if device_onetime_password_gen["about"] == "already_exists": + if device_onetime_password_gen["result"] == 0: device_onetime_password = str(device_onetime_password_gen["output_dict"]["onetime_password"]) device_onetime_password_max_count = str(device_onetime_password_gen["output_dict"]["max_count"]) device_onetime_password_current_count = str(device_onetime_password_gen["output_dict"]["current_count"]) device_onetime_password_remaining_times = str(int(device_onetime_password_max_count) - int(device_onetime_password_current_count)) - await interaction.response.send_message(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {device_onetime_password}\n# 残り使用回数 | {device_onetime_password_remaining_times}", ephemeral=True) - else: - await interaction.response.send_message("# :skull_crossbones: ワンタイムパスワードの発行に失敗しました。", ephemeral=True) + + await interaction.response.send_message(f"# :dizzy_face: デバイス登録時のワンタイムパスワードを発行します。\n# パスワード | {device_onetime_password}\n# 最大使用回数 | {device_onetime_password_max_count}\n# 残り使用回数 | {device_onetime_password_remaining_times}", ephemeral=True) + elif device_onetime_password_gen["result"] == 1: + if device_onetime_password_gen["about"] == "already_exists": + device_onetime_password = str(device_onetime_password_gen["output_dict"]["onetime_password"]) + device_onetime_password_max_count = str(device_onetime_password_gen["output_dict"]["max_count"]) + device_onetime_password_current_count = str(device_onetime_password_gen["output_dict"]["current_count"]) + device_onetime_password_remaining_times = str(int(device_onetime_password_max_count) - int(device_onetime_password_current_count)) + await interaction.response.send_message(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {device_onetime_password}\n# 残り使用回数 | {device_onetime_password_remaining_times}", ephemeral=True) + else: + await interaction.response.send_message("# :skull_crossbones: ワンタイムパスワードの発行に失敗しました。", ephemeral=True) @tree.command(name="fstop", description="PCの使用登録を強制的に終了します。") @discord.app_commands.default_permissions(administrator=True) async def fstop(interaction: discord.Interaction, pc_number: int, about: str): - force_stop = dislocker.force_stop(pc_number=pc_number, bot_about=about) - if force_stop["result"] == 0: - await interaction.response.send_message(f":white_check_mark: PC {pc_number} の使用を強制終了しました。", ephemeral=True) - dislocker.log(title=f"[INFO] PC {pc_number} の使用を強制終了しました。", message=f"理由 | {about}", flag=0) - elif force_stop["result"] == 1: - if force_stop["about"] == "not_used": - await interaction.response.send_message(":x: そのPCは使用されていません。", ephemeral=True) - elif force_stop["about"] == "bot_about_not_found": - await interaction.response.send_message(":x: 理由が指定されていません。", ephemeral=True) - elif force_stop["about"] == "error": - await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) + if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + force_stop = dislocker.force_stop(pc_number=pc_number, bot_about=about) + if force_stop["result"] == 0: + await interaction.response.send_message(f":white_check_mark: PC {pc_number} の使用を強制終了しました。", ephemeral=True) + dislocker.log(title=f"[INFO] PC {pc_number} の使用を強制終了しました。", message=f"理由 | {about}", flag=0) + elif force_stop["result"] == 1: + if force_stop["about"] == "not_used": + await interaction.response.send_message(":x: そのPCは使用されていません。", ephemeral=True) + elif force_stop["about"] == "bot_about_not_found": + await interaction.response.send_message(":x: 理由が指定されていません。", ephemeral=True) + elif force_stop["about"] == "error": + await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) @tree.command(name="report", description="PCの使用履歴をエクスポートします。") @discord.app_commands.default_permissions(administrator=True) async def report(interaction: discord.Interaction): - report_export = dislocker.report_export() - if report_export["result"] == 0: - await interaction.response.send_message(f":white_check_mark: 使用履歴のレポートです。", file=discord.File(report_export["file_path"]), ephemeral=True) - dislocker.log(title=f"[INFO] PCの使用履歴をエクスポートしました。", message=f"ファイルパス | {report_export['file_path']}", flag=0) - elif report_export["result"] == 1: - if report_export["about"] == "error": - await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) + if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + report_export = dislocker.report_export() + if report_export["result"] == 0: + await interaction.response.send_message(f":white_check_mark: 使用履歴のレポートです。", file=discord.File(report_export["file_path"]), ephemeral=True) + dislocker.log(title=f"[INFO] PCの使用履歴をエクスポートしました。", message=f"ファイルパス | {report_export['file_path']}", flag=0) + elif report_export["result"] == 1: + if report_export["about"] == "error": + await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) @tree.command(name="init", description="操作チャンネルにボタン一式を送信します。") @discord.app_commands.default_permissions(administrator=True) async def button_init(interaction: discord.Interaction, text_channel: discord.TextChannel): - user_register_button_view = discord.ui.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) + if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + user_register_button_view = discord.ui.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 client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: ユーザー登録はお済ですか?', view=user_register_button_view) + await client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: ユーザー登録はお済ですか?', view=user_register_button_view) - stop_button_view = discord.ui.View(timeout=None) - stop_button = discord.ui.Button(style=discord.ButtonStyle.danger, label="PCの使用を停止", custom_id="stop") - stop_button_view.add_item(stop_button) + stop_button_view = discord.ui.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 client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: 使用を停止しますか?', view=stop_button_view) + await client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: 使用を停止しますか?', view=stop_button_view) - pc_button_view = discord.ui.View(timeout=None) - for i in dislocker.pc_list: - pc_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i)}", custom_id=f"pcregister_{str(i)}") - pc_button_view.add_item(pc_register_button) + pc_button_view = discord.ui.View(timeout=None) + for i in dislocker.pc_list: + pc_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i)}", custom_id=f"pcregister_{str(i)}") + pc_button_view.add_item(pc_register_button) - await client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: 使いたいPCの番号を選んでください!', view=pc_button_view) - dislocker.log(title=f"[INFO] サーバーで初回処理を実行しました。", flag=0) + await client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: 使いたいPCの番号を選んでください!', view=pc_button_view) + dislocker.log(title=f"[INFO] サーバーで初回処理を実行しました。", flag=0) - await interaction.response.send_message(f":white_check_mark: ボタンを送信しました!", ephemeral=True) + await interaction.response.send_message(f":white_check_mark: ボタンを送信しました!", ephemeral=True) @tree.command(name="masterpass", description="PCのマスターパスワードを表示します。") @discord.app_commands.default_permissions(administrator=True) async def masterpass(interaction: discord.Interaction, pc_number: int): - pc_master_password_get = dislocker.show_pc_master_password(pc_number=pc_number) - - if pc_master_password_get["result"] == 0: - pc_master_password = pc_master_password_get["output_dict"]["pc_master_password"] - await interaction.response.send_message(f"# :key: PC番号 {pc_number} 番のマスターパスワードは以下の通りです。\n>>> # マスターパスワード | {pc_master_password}", ephemeral=True) - else: - await interaction.response.send_message("# :skull_crossbones: マスターパスワードの取得に失敗しました。", ephemeral=True) + if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + pc_master_password_get = dislocker.show_pc_master_password(pc_number=pc_number) + + if pc_master_password_get["result"] == 0: + pc_master_password = pc_master_password_get["output_dict"]["pc_master_password"] + await interaction.response.send_message(f"# :key: PC番号 {pc_number} 番のマスターパスワードは以下の通りです。\n>>> # マスターパスワード | {pc_master_password}", ephemeral=True) + else: + await interaction.response.send_message("# :skull_crossbones: マスターパスワードの取得に失敗しました。", ephemeral=True) if dislocker.init_result == "ok": From 31fd32acc946dbd066c3afe88bab26a9bf171775 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 22:01:05 +0900 Subject: [PATCH 28/41] =?UTF-8?q?admin=5Fuser=E3=81=A8server=5Fid=E3=82=92?= =?UTF-8?q?=E3=83=AA=E3=82=B9=E3=83=88=E3=81=AB=E3=81=97=E3=81=A6=E8=A4=87?= =?UTF-8?q?=E6=95=B0=E6=8C=87=E5=AE=9A=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 0ccb343..dcb08fa 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -37,7 +37,7 @@ class DL(): "password": "password" }, "bot": { - "server_id": "TYPE HERE SERVER ID", + "server_id": ["TYPE HERE SERVER ID (YOU MUST USE INT !!!!)"], "token": "TYPE HERE BOTS TOKEN KEY", "activity": { "name": "Dislocker", @@ -54,7 +54,7 @@ class DL(): "fstop_time": "21:00:00" }, "preset_games": ["TEST1", "TEST2", "TEST3", "TEST4", "TEST5"], - "admin_user_id": "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)", + "admin_user_id": ["TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)"], "debug": False } } @@ -945,7 +945,7 @@ async def on_message(message): pass elif isinstance(message.channel, discord.DMChannel): - if message.author.id == dislocker.server_config["bot"]["admin_user_id"]: + if message.author.id in dislocker.server_config["bot"]["admin_user_id"]: msg_split = message.content.split() if msg_split[0] == "/pcreg": @@ -1205,7 +1205,7 @@ async def stop(interaction: discord.Interaction): @tree.command(name="userreg", description="ユーザーを登録します。") @discord.app_commands.default_permissions(administrator=True) async def userreg(interaction: discord.Interaction, discord_user_id: str, discord_user_name: str, name: str): - if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + if interaction.guild_id in dislocker.server_config["bot"]["server_id"] or interaction.user.id in dislocker.server_config["bot"]["admin_user_id"]: user_register = dislocker.user_register(discord_user_id=discord_user_id, discord_user_name=discord_user_name, name=name) if user_register["result"] == 0: await interaction.response.send_message(":white_check_mark: ユーザーを登録しました。", ephemeral=True) @@ -1219,7 +1219,7 @@ async def userreg(interaction: discord.Interaction, discord_user_id: str, discor @tree.command(name="pcreg", description="PCをDislockerに登録するためのワンタイムパスワードを発行します。") @discord.app_commands.default_permissions(administrator=True) async def pcreg(interaction: discord.Interaction, how_much: int = 1): - if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + if interaction.guild_id in dislocker.server_config["bot"]["server_id"] or interaction.user.id in dislocker.server_config["bot"]["admin_user_id"]: max_count = how_much pc_onetime_password_gen = dislocker.pc_onetime_gen(max_count=max_count) @@ -1244,7 +1244,7 @@ async def pcreg(interaction: discord.Interaction, how_much: int = 1): @tree.command(name="devicereg", description="デバイスをDislockerに登録するためのワンタイムパスワードを発行します。") @discord.app_commands.default_permissions(administrator=True) async def devicereg(interaction: discord.Interaction, how_much: int): - if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + if interaction.guild_id in dislocker.server_config["bot"]["server_id"] or interaction.user.id in dislocker.server_config["bot"]["admin_user_id"]: max_count = how_much device_onetime_password_gen = dislocker.device_onetime_gen(max_count=max_count) @@ -1269,7 +1269,7 @@ async def devicereg(interaction: discord.Interaction, how_much: int): @tree.command(name="fstop", description="PCの使用登録を強制的に終了します。") @discord.app_commands.default_permissions(administrator=True) async def fstop(interaction: discord.Interaction, pc_number: int, about: str): - if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + if interaction.guild_id in dislocker.server_config["bot"]["server_id"] or interaction.user.id in dislocker.server_config["bot"]["admin_user_id"]: force_stop = dislocker.force_stop(pc_number=pc_number, bot_about=about) if force_stop["result"] == 0: await interaction.response.send_message(f":white_check_mark: PC {pc_number} の使用を強制終了しました。", ephemeral=True) @@ -1285,7 +1285,7 @@ async def fstop(interaction: discord.Interaction, pc_number: int, about: str): @tree.command(name="report", description="PCの使用履歴をエクスポートします。") @discord.app_commands.default_permissions(administrator=True) async def report(interaction: discord.Interaction): - if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + if interaction.guild_id in dislocker.server_config["bot"]["server_id"] or interaction.user.id in dislocker.server_config["bot"]["admin_user_id"]: report_export = dislocker.report_export() if report_export["result"] == 0: await interaction.response.send_message(f":white_check_mark: 使用履歴のレポートです。", file=discord.File(report_export["file_path"]), ephemeral=True) @@ -1297,7 +1297,7 @@ async def report(interaction: discord.Interaction): @tree.command(name="init", description="操作チャンネルにボタン一式を送信します。") @discord.app_commands.default_permissions(administrator=True) async def button_init(interaction: discord.Interaction, text_channel: discord.TextChannel): - if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + if interaction.guild_id in dislocker.server_config["bot"]["server_id"] or interaction.user.id in dislocker.server_config["bot"]["admin_user_id"]: user_register_button_view = discord.ui.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) @@ -1323,7 +1323,7 @@ async def button_init(interaction: discord.Interaction, text_channel: discord.Te @tree.command(name="masterpass", description="PCのマスターパスワードを表示します。") @discord.app_commands.default_permissions(administrator=True) async def masterpass(interaction: discord.Interaction, pc_number: int): - if interaction.guild_id == dislocker.server_config["bot"]["server_id"] or interaction.user.id == dislocker.server_config["bot"]["admin_user_id"]: + if interaction.guild_id in dislocker.server_config["bot"]["server_id"] or interaction.user.id in dislocker.server_config["bot"]["admin_user_id"]: pc_master_password_get = dislocker.show_pc_master_password(pc_number=pc_number) if pc_master_password_get["result"] == 0: From 6bf928ac1389ccd02fa308e77677e92c49398457 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sat, 28 Sep 2024 21:52:25 +0900 Subject: [PATCH 29/41] =?UTF-8?q?=E5=90=84PC,=E3=83=87=E3=83=90=E3=82=A4?= =?UTF-8?q?=E3=82=B9=E3=81=AE=E3=83=86=E3=83=BC=E3=83=96=E3=83=AB=E3=81=AB?= =?UTF-8?q?alt=5Fname=E3=82=AB=E3=83=A9=E3=83=A0=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index dcb08fa..4b15eca 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -104,7 +104,7 @@ class DL(): find_pc_list_table = cursor.fetchall() print(find_pc_list_table) if find_pc_list_table[0][0] == False: - cursor.execute("CREATE TABLE pc_list (pc_number INTEGER NOT NULL, using_member_id INTEGER, password_hash VARCHAR(64), pc_uuid VARCHAR(36), pc_token VARCHAR(36), master_password VARCHAR(16), detail TEXT, PRIMARY KEY (pc_number), FOREIGN KEY (using_member_id) REFERENCES club_member(member_id))") + cursor.execute("CREATE TABLE pc_list (pc_number INTEGER NOT NULL, using_member_id INTEGER, password_hash VARCHAR(64), pc_uuid VARCHAR(36), pc_token VARCHAR(36), master_password VARCHAR(16), detail TEXT, alt_name TEXT, PRIMARY KEY (pc_number), FOREIGN KEY (using_member_id) REFERENCES club_member(member_id))") for i in self.pc_list: print(i) cursor.execute("INSERT INTO pc_list (pc_number) VALUES (%s)", (i,)) @@ -114,7 +114,7 @@ class DL(): find_keyboard_list_table = cursor.fetchall() print(find_keyboard_list_table) if find_keyboard_list_table[0][0] == False: - cursor.execute("CREATE TABLE keyboard_list (keyboard_number INTEGER NOT NULL, using_member_id INTEGER, device_instance_path TEXT, device_name TEXT, detail TEXT, PRIMARY KEY (keyboard_number), FOREIGN KEY (using_member_id) REFERENCES club_member(member_id))") + cursor.execute("CREATE TABLE keyboard_list (keyboard_number INTEGER NOT NULL, using_member_id INTEGER, device_instance_path TEXT, device_name TEXT, detail TEXT, alt_name TEXT, PRIMARY KEY (keyboard_number), FOREIGN KEY (using_member_id) REFERENCES club_member(member_id))") for i in self.keyboard_list: print(i) cursor.execute("INSERT INTO keyboard_list (keyboard_number) VALUES (%s)", (i,)) @@ -124,7 +124,7 @@ class DL(): find_mouse_list_table = cursor.fetchall() print(find_mouse_list_table) if find_mouse_list_table[0][0] == False: - cursor.execute("CREATE TABLE mouse_list (mouse_number INTEGER NOT NULL, using_member_id INTEGER, device_instance_path TEXT, device_name TEXT, detail TEXT, PRIMARY KEY (mouse_number), FOREIGN KEY (using_member_id) REFERENCES club_member(member_id))") + cursor.execute("CREATE TABLE mouse_list (mouse_number INTEGER NOT NULL, using_member_id INTEGER, device_instance_path TEXT, device_name TEXT, detail TEXT, alt_name TEXT, PRIMARY KEY (mouse_number), FOREIGN KEY (using_member_id) REFERENCES club_member(member_id))") for i in self.mouse_list: print(i) cursor.execute("INSERT INTO mouse_list (mouse_number) VALUES (%s)", (i,)) From cb3bc05fafe9794796aec789e59b98004600248b Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sat, 28 Sep 2024 22:00:01 +0900 Subject: [PATCH 30/41] =?UTF-8?q?=E3=83=87=E3=83=90=E3=82=A4=E3=82=B9?= =?UTF-8?q?=E3=81=8C=E8=87=AA=E5=89=8D(0=E7=95=AA)=E3=81=AE=E6=99=82?= =?UTF-8?q?=E3=81=AB=E4=BB=96=E4=BA=BA=E3=81=8C=E4=BD=BF=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=82=8B=E5=88=A4=E5=AE=9A=E3=81=AB=E3=81=AA=E3=82=8B?= =?UTF-8?q?=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 4b15eca..7fe8d71 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -390,12 +390,12 @@ class DL(): # 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"])) # キーボードリストの該当のレコードを自前(None)だったらスキップ、借りていたら更新 - if user_info["keyboard_number"] == None: + if user_info["keyboard_number"] == 0: pass else: cursor.execute("UPDATE keyboard_list SET using_member_id = %s WHERE keyboard_number = %s", (member_id, user_info["keyboard_number"])) # マウスも同様に - if user_info["mouse_number"] == None: + if user_info["mouse_number"] == 0: pass else: cursor.execute("UPDATE mouse_list SET using_member_id = %s WHERE mouse_number = %s", (member_id, user_info["mouse_number"])) From ab96092b39c0e49cfeb452fec04bb1b6d1ab5e9a Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sat, 28 Sep 2024 23:41:19 +0900 Subject: [PATCH 31/41] =?UTF-8?q?=E7=AE=A1=E7=90=86=E8=80=85=E5=90=91?= =?UTF-8?q?=E3=81=91=E3=81=AE=E3=82=B9=E3=83=A9=E3=83=83=E3=82=B7=E3=83=A5?= =?UTF-8?q?=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E3=81=AE=E8=BF=94=E4=BF=A1?= =?UTF-8?q?=E3=82=92embed=E3=81=B8=E7=A7=BB=E8=A1=8C,=20PC=E3=81=AE?= =?UTF-8?q?=E3=83=8B=E3=83=83=E3=82=AF=E3=83=8D=E3=83=BC=E3=83=A0=E8=A8=AD?= =?UTF-8?q?=E5=AE=9A=E6=A9=9F=E8=83=BD=E8=BF=BD=E5=8A=A0,=20PC=E3=81=AE?= =?UTF-8?q?=E6=83=85=E5=A0=B1=E5=8F=96=E5=BE=97=E6=A9=9F=E8=83=BD=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 280 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 234 insertions(+), 46 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 7fe8d71..7969d37 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -217,7 +217,7 @@ class DL(): except Exception as error: self.log(title=f"[ERROR] ユーザーの登録状態を調査中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) - return {"result": 1, "about": "error"} + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} finally: cursor.close() @@ -285,7 +285,7 @@ class DL(): except Exception as error: self.log(title=f"[ERROR] PCの使用状況を調査中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) - return {"result": 1, "about": "error"} + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} finally: if cursor: @@ -308,7 +308,7 @@ class DL(): except Exception as error: self.log(title=f"[ERROR] キーボードの使用状況を調査中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) - return {"result": 1, "about": "error"} + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} finally: if cursor: @@ -331,7 +331,7 @@ class DL(): except Exception as error: self.log(title=f"[ERROR] マウスの使用状況を調査中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) - return {"result": 1, "about": "error"} + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} finally: if cursor: @@ -413,7 +413,7 @@ class DL(): return {"result": 1, "about": "user_data_not_found"} except Exception as error: self.log(title=f"[ERROR] PCの使用登録中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) - return {"result": 1, "about": "error"} + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} finally: if cursor: cursor.close() @@ -474,7 +474,7 @@ class DL(): except Exception as error: self.log(title=f"[ERROR] PCの使用停止処理中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) - return {"result": 1, "about": "error"} + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} finally: if cursor: @@ -497,7 +497,7 @@ class DL(): except Exception as error: self.log(title=f"[ERROR] ユーザー情報の登録中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) - return {"result": 1, "about": "error"} + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} finally: if cursor: @@ -524,7 +524,7 @@ class DL(): except Exception as error: self.log(title=f"[ERROR] PCの情報を登録中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) - return {"result": 1, "about": "error"} + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} finally: if cursor: @@ -595,7 +595,7 @@ class DL(): except Exception as error: self.log(title=f"[ERROR] PCの使用履歴をエクスポート中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) - return {"result": 1, "about": "error"} + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} finally: if cursor: @@ -643,7 +643,7 @@ class DL(): except Exception as error: self.log(title=f"[ERROR] fstop中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) - return {"result": 1, "about": "error"} + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} finally: if cursor: @@ -698,7 +698,7 @@ class DL(): except Exception as error: self.log(title=f"[ERROR] PC登録用のワンタイムパスワード発行中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) - return {"result": 1, "about": "error"} + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} def device_onetime_gen(self, **kwargs): @@ -750,11 +750,11 @@ class DL(): except Exception as error: self.log(title=f"[ERROR] デバイス登録用のワンタイムパスワード発行中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) - return {"result": 1, "about": "error"} + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} def show_pc_master_password(self, **kwargs): - if isinstance(kwargs.get("pc_number"), int): - try: + try: + if isinstance(kwargs.get("pc_number"), int): pc_number = int(kwargs.get("pc_number")) cursor = self.db.cursor() @@ -763,11 +763,81 @@ class DL(): pc_master_password = pc_master_password_list[0][0] return {"result": 0, "about": "ok", "output_dict": {"pc_master_password": pc_master_password}} - except Exception as error: + + else: + return {"result": 1, "about": "syntax_error"} + except Exception as error: self.log(title=f"[ERROR] PCのマスターパスワードを取得中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) - return {"result": 1, "about": "error"} - else: - return {"result": 1, "about": "syntax_error"} + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} + + finally: + if cursor: + cursor.close() + + def get_discord_user_id(self, **kwargs): + try: + member_id = int(kwargs["member_id"]) + cursor = self.db.cursor() + cursor.execute("SELECT discord_user_id FROM club_member WHERE member_id = %s", (member_id,)) + discord_user_id_list = cursor.fetchall() + discord_user_id = discord_user_id_list[0][0] + return {"result": 0, "about": "ok", "discord_user_id": discord_user_id} + + except Exception as error: + self.log(title=f"[ERROR] DiscordのユーザーIDの取得中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} + + finally: + if cursor: + cursor.close() + + def get_pc_list(self, **kwargs): + try: + cursor = self.db.cursor() + + if "pc_number" in kwargs: + pc_number = int(kwargs["pc_number"]) + cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s", (pc_number,)) + pc_list = cursor.fetchall() + + return {"result": 0, "about": "ok", "output_dict": {pc_number: {"pc_number": pc_list[0][0], "using_member_id": pc_list[0][1], "master_password": [0][5], "detail": pc_list[0][6], "alt_name": pc_list[0][7]}}} + else: + cursor.execute("SELECT * FROM pc_list ORDER BY pc_number") + pc_list = cursor.fetchall() + pc_list = {} + for i in pc_list: + pc_list[i[0]] = {"pc_number": i[0], "using_member_id": i[1], "master_password": i[5], "detail": i[6], "alt_name": i[7]} + + return {"result": 0, "about": "ok", "output_dict": pc_list} + + except Exception as error: + self.log(title=f"[ERROR] PCリストの取得中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} + + finally: + if cursor: + cursor.close() + + def set_pc_nickname(self, **kwargs): + try: + cursor = self.db.cursor() + + if 'pc_number' in kwargs and 'alt_name' in kwargs: + pc_number = int(kwargs["pc_number"]) + alt_name = kwargs["alt_name"] + cursor.execute("UPDATE pc_list SET alt_name = %s WHERE pc_number = %s", (alt_name, pc_number)) + self.db.commit() + return {"result": 0, "about": "ok"} + else: + return {"result": 1, "about": "syntax_error"} + + except Exception as error: + self.log(title=f"[ERROR] PCのニックネームの設定中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} + + finally: + if cursor: + cursor.close() class ReasonModal(discord.ui.Modal): @@ -953,7 +1023,7 @@ async def on_message(message): if len(msg_split) == 2: if msg_split[1].isdecimal(): max_count = int(msg_split[1]) - + pc_onetime_password_gen = dislocker.pc_onetime_gen(max_count=max_count) if pc_onetime_password_gen["result"] == 0: @@ -962,16 +1032,28 @@ async def on_message(message): pc_onetime_password_current_count = str(pc_onetime_password_gen["output_dict"]["current_count"]) pc_onetime_password_remaining_times = str(int(pc_onetime_password_max_count) - int(pc_onetime_password_current_count)) - await message.channel.send(f"# :dizzy_face: PC登録時のワンタイムパスワードを発行します。\n# パスワード | {pc_onetime_password}\n# 最大使用回数 | {pc_onetime_password_max_count}\n# 残り使用回数 | {pc_onetime_password_remaining_times}") + result_embed = discord.Embed(title=":dizzy_face: PCの登録", description=f"PC登録時のワンタイムパスワードを発行します。", color=0x2286C9) + result_embed.add_field(name="パスワード", value=pc_onetime_password) + result_embed.add_field(name="最大使用回数", value=pc_onetime_password_max_count) + result_embed.add_field(name="残り使用回数", value=pc_onetime_password_remaining_times) + elif pc_onetime_password_gen["result"] == 1: if pc_onetime_password_gen["about"] == "already_exists": pc_onetime_password = str(pc_onetime_password_gen["output_dict"]["onetime_password"]) pc_onetime_password_max_count = str(pc_onetime_password_gen["output_dict"]["max_count"]) pc_onetime_password_current_count = str(pc_onetime_password_gen["output_dict"]["current_count"]) pc_onetime_password_remaining_times = str(int(pc_onetime_password_max_count) - int(pc_onetime_password_current_count)) - await message.channel.send(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {pc_onetime_password}\n# 残り使用回数 | {pc_onetime_password_remaining_times}") + + result_embed = discord.Embed(title=":dizzy_face: PCの登録", description=f"ワンタイムパスワードはもう発行されており、有効です。", color=0x2286C9) + result_embed.add_field(name="パスワード", value=pc_onetime_password) + result_embed.add_field(name="最大使用回数", value=pc_onetime_password_max_count) + result_embed.add_field(name="残り使用回数", value=pc_onetime_password_remaining_times) + else: - await message.channel.send("# :skull_crossbones: ワンタイムパスワードの発行に失敗しました。") + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'サーバーでエラーが発生しています。', color=0xC91111) + result_embed.add_field(name=f"{pc_onetime_password_gen['output_dict']['error_class_name']}", value=f"{pc_onetime_password_gen['output_dict']['error_args']}") + + await message.channel.send(embed=result_embed) elif msg_split[0] == "/devreg": max_count = 1 @@ -987,19 +1069,31 @@ async def on_message(message): device_onetime_password_current_count = str(device_onetime_password_gen["output_dict"]["current_count"]) device_onetime_password_remaining_times = str(int(device_onetime_password_max_count) - int(device_onetime_password_current_count)) - await message.channel.send(f"# :dizzy_face: デバイス登録時のワンタイムパスワードを発行します。\n# パスワード | {device_onetime_password}\n# 最大使用回数 | {device_onetime_password_max_count}\n# 残り使用回数 | {device_onetime_password_remaining_times}") + result_embed = discord.Embed(title=":dizzy_face: デバイスの登録", description=f"デバイス登録時のワンタイムパスワードを発行します。", color=0x2286C9) + result_embed.add_field(name="パスワード", value=device_onetime_password) + result_embed.add_field(name="最大使用回数", value=device_onetime_password_max_count) + result_embed.add_field(name="残り使用回数", value=device_onetime_password_remaining_times) + elif device_onetime_password_gen["result"] == 1: if device_onetime_password_gen["about"] == "already_exists": device_onetime_password = str(device_onetime_password_gen["output_dict"]["onetime_password"]) device_onetime_password_max_count = str(device_onetime_password_gen["output_dict"]["max_count"]) device_onetime_password_current_count = str(device_onetime_password_gen["output_dict"]["current_count"]) device_onetime_password_remaining_times = str(int(device_onetime_password_max_count) - int(device_onetime_password_current_count)) - await message.channel.send(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {device_onetime_password}\n# 残り使用回数 | {device_onetime_password_remaining_times}") + result_embed = discord.Embed(title=":dizzy_face: デバイスの登録", description=f"ワンタイムパスワードはもう発行されており、有効です。", color=0x2286C9) + result_embed.add_field(name="パスワード", value=device_onetime_password) + result_embed.add_field(name="最大使用回数", value=device_onetime_password_max_count) + result_embed.add_field(name="残り使用回数", value=device_onetime_password_remaining_times) + else: - await message.channel.send("# :skull_crossbones: ワンタイムパスワードの発行に失敗しました。") + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'サーバーでエラーが発生しています。', color=0xC91111) + result_embed.add_field(name=f"{device_onetime_password_gen['output_dict']['error_class_name']}", value=f"{device_onetime_password_gen['output_dict']['error_args']}") + + await message.channel.send(embed=result_embed) else: - await message.channel.send("# :warning: DMでの応答は、現在無効化されています。") + result_embed = discord.Embed(title=":x: 警告", description=f'DMでの操作はサポートされていません。', color=0xC91111) + await message.channel.send(embed=result_embed) else: pass @@ -1191,15 +1285,23 @@ async def stop(interaction: discord.Interaction): stop = dislocker.stop(discord_user_id=interaction.user.id) if stop["result"] == 0: await interaction.response.send_message(f":white_check_mark: 使用が終了されました。\n>>> ## PC番号 | {stop['output_dict']['pc_number']}", ephemeral=True) + result_embed = discord.Embed(title=":white_check_mark: 使用停止処理は完了しました。", description=f'PC番号 {stop['output_dict']['pc_number']} 番の使用停止処理が完了しました。', color=0x56FF01) dislocker.log(title=f"[INFO] PC番号{stop['output_dict']['pc_number']} の使用が終了されました。", message=f"名前 | {stop['output_dict']['name']}", flag=0) - await client.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f':white_check_mark: {stop["output_dict"]["name"]} さんがPC {stop["output_dict"]["pc_number"]} の使用を終了しました。\n>>> ## PC番号 | {stop["output_dict"]["pc_number"]}') + log_embed = discord.Embed(title=f":information_source: PC番号 {stop['output_dict']['pc_number']} の使用は終了されました。", description=f"<@{interaction.user.id}> によるリクエスト", color=0x2286C9) + await client.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(embed=log_embed) + elif stop["result"] == 1: if stop["about"] == "unused": - await interaction.response.send_message("# :shaking_face: あなたはPCを使用されていないようです...", ephemeral=True) + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'あなたはPCを使用されていないようです...', color=0xC91111) + elif stop["about"] == "user_data_not_found": - await interaction.response.send_message("# :dizzy_face: ユーザーとして登録されていないようです。\n最初にサーバーで登録を行ってください。", ephemeral=True) + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'Dislockerのユーザーとして登録されていないようです。\n登録を行ってから、またお試しください。', color=0xC91111) + elif stop["about"] == "error": - await interaction.response.send_message("# :skull_crossbones: 停止できませんでした。\n内部エラーが発生しています。", ephemeral=True) + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'サーバーでエラーが発生しています。', color=0xC91111) + result_embed.add_field(name=f"{stop['output_dict']['error_class_name']}", value=f"{stop['output_dict']['error_args']}") + + await interaction.response.send_message(embed=result_embed, ephemeral=True) #管理者側のスラッシュコマンド @tree.command(name="userreg", description="ユーザーを登録します。") @@ -1208,13 +1310,18 @@ async def userreg(interaction: discord.Interaction, discord_user_id: str, discor if interaction.guild_id in dislocker.server_config["bot"]["server_id"] or interaction.user.id in dislocker.server_config["bot"]["admin_user_id"]: user_register = dislocker.user_register(discord_user_id=discord_user_id, discord_user_name=discord_user_name, name=name) if user_register["result"] == 0: - await interaction.response.send_message(":white_check_mark: ユーザーを登録しました。", ephemeral=True) + result_embed = discord.Embed(title=":white_check_mark: ユーザー登録が完了しました。", description=f'続いて、PCの使用登録を行いましょう!', color=0x56FF01) dislocker.log(title=f"[INFO] ユーザーを登録しました。", message=f"名前 | {name}, Discordユーザー名 | {discord_user_name}, DiscordユーザーID | {discord_user_id}", flag=0) + elif user_register["result"] == 1: if user_register["about"] == "already_exists": - await interaction.response.send_message(":x: 既に登録されているユーザーです。", ephemeral=True) + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'既に登録されているユーザーです。', color=0xC91111) + elif user_register["about"] == "error": - await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'サーバーでエラーが発生しています。', color=0xC91111) + result_embed.add_field(name=f"{user_register['output_dict']['error_class_name']}", value=f"{user_register['output_dict']['error_args']}") + + await interaction.response.send_message(embed=result_embed, ephemeral=True) @tree.command(name="pcreg", description="PCをDislockerに登録するためのワンタイムパスワードを発行します。") @discord.app_commands.default_permissions(administrator=True) @@ -1230,16 +1337,28 @@ async def pcreg(interaction: discord.Interaction, how_much: int = 1): pc_onetime_password_current_count = str(pc_onetime_password_gen["output_dict"]["current_count"]) pc_onetime_password_remaining_times = str(int(pc_onetime_password_max_count) - int(pc_onetime_password_current_count)) - await interaction.response.send_message(f"# :dizzy_face: PC登録時のワンタイムパスワードを発行します。\n# パスワード | {pc_onetime_password}\n# 最大使用回数 | {pc_onetime_password_max_count}\n# 残り使用回数 | {pc_onetime_password_remaining_times}", ephemeral=True) + result_embed = discord.Embed(title=":dizzy_face: PCの登録", description=f"PC登録時のワンタイムパスワードを発行します。", color=0x2286C9) + result_embed.add_field(name="パスワード", value=pc_onetime_password) + result_embed.add_field(name="最大使用回数", value=pc_onetime_password_max_count) + result_embed.add_field(name="残り使用回数", value=pc_onetime_password_remaining_times) + elif pc_onetime_password_gen["result"] == 1: if pc_onetime_password_gen["about"] == "already_exists": pc_onetime_password = str(pc_onetime_password_gen["output_dict"]["onetime_password"]) pc_onetime_password_max_count = str(pc_onetime_password_gen["output_dict"]["max_count"]) pc_onetime_password_current_count = str(pc_onetime_password_gen["output_dict"]["current_count"]) pc_onetime_password_remaining_times = str(int(pc_onetime_password_max_count) - int(pc_onetime_password_current_count)) - await interaction.response.send_message(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {pc_onetime_password}\n# 残り使用回数 | {pc_onetime_password_remaining_times}", ephemeral=True) + + result_embed = discord.Embed(title=":dizzy_face: PCの登録", description=f"ワンタイムパスワードはもう発行されており、有効です。", color=0x2286C9) + result_embed.add_field(name="パスワード", value=pc_onetime_password) + result_embed.add_field(name="最大使用回数", value=pc_onetime_password_max_count) + result_embed.add_field(name="残り使用回数", value=pc_onetime_password_remaining_times) + else: - await interaction.response.send_message("# :skull_crossbones: ワンタイムパスワードの発行に失敗しました。", ephemeral=True) + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'サーバーでエラーが発生しています。', color=0xC91111) + result_embed.add_field(name=f"{pc_onetime_password_gen['output_dict']['error_class_name']}", value=f"{pc_onetime_password_gen['output_dict']['error_args']}") + + await interaction.response.send_message(embed=result_embed, ephemeral=True) @tree.command(name="devicereg", description="デバイスをDislockerに登録するためのワンタイムパスワードを発行します。") @discord.app_commands.default_permissions(administrator=True) @@ -1255,16 +1374,28 @@ async def devicereg(interaction: discord.Interaction, how_much: int): device_onetime_password_current_count = str(device_onetime_password_gen["output_dict"]["current_count"]) device_onetime_password_remaining_times = str(int(device_onetime_password_max_count) - int(device_onetime_password_current_count)) - await interaction.response.send_message(f"# :dizzy_face: デバイス登録時のワンタイムパスワードを発行します。\n# パスワード | {device_onetime_password}\n# 最大使用回数 | {device_onetime_password_max_count}\n# 残り使用回数 | {device_onetime_password_remaining_times}", ephemeral=True) + result_embed = discord.Embed(title=":dizzy_face: デバイスの登録", description=f"デバイス登録時のワンタイムパスワードを発行します。", color=0x2286C9) + result_embed.add_field(name="パスワード", value=device_onetime_password) + result_embed.add_field(name="最大使用回数", value=device_onetime_password_max_count) + result_embed.add_field(name="残り使用回数", value=device_onetime_password_remaining_times) + elif device_onetime_password_gen["result"] == 1: if device_onetime_password_gen["about"] == "already_exists": device_onetime_password = str(device_onetime_password_gen["output_dict"]["onetime_password"]) device_onetime_password_max_count = str(device_onetime_password_gen["output_dict"]["max_count"]) device_onetime_password_current_count = str(device_onetime_password_gen["output_dict"]["current_count"]) device_onetime_password_remaining_times = str(int(device_onetime_password_max_count) - int(device_onetime_password_current_count)) - await interaction.response.send_message(f"# :dizzy_face: 既にワンタイムパスワードは発行されています。\n# パスワード | {device_onetime_password}\n# 残り使用回数 | {device_onetime_password_remaining_times}", ephemeral=True) + result_embed = discord.Embed(title=":dizzy_face: デバイスの登録", description=f"ワンタイムパスワードはもう発行されており、有効です。", color=0x2286C9) + result_embed.add_field(name="パスワード", value=device_onetime_password) + result_embed.add_field(name="最大使用回数", value=device_onetime_password_max_count) + result_embed.add_field(name="残り使用回数", value=device_onetime_password_remaining_times) + else: - await interaction.response.send_message("# :skull_crossbones: ワンタイムパスワードの発行に失敗しました。", ephemeral=True) + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'サーバーでエラーが発生しています。', color=0xC91111) + result_embed.add_field(name=f"{device_onetime_password_gen['output_dict']['error_class_name']}", value=f"{device_onetime_password_gen['output_dict']['error_args']}") + + await interaction.response.send_message(embed=result_embed, ephemeral=True) + @tree.command(name="fstop", description="PCの使用登録を強制的に終了します。") @discord.app_commands.default_permissions(administrator=True) @@ -1272,15 +1403,21 @@ async def fstop(interaction: discord.Interaction, pc_number: int, about: str): if interaction.guild_id in dislocker.server_config["bot"]["server_id"] or interaction.user.id in dislocker.server_config["bot"]["admin_user_id"]: force_stop = dislocker.force_stop(pc_number=pc_number, bot_about=about) if force_stop["result"] == 0: - await interaction.response.send_message(f":white_check_mark: PC {pc_number} の使用を強制終了しました。", ephemeral=True) + result_embed = discord.Embed(title=":white_check_mark: 処理が完了しました。", description=f'PC番号 {str(pc_number)} 番の使用登録は抹消されました。', color=0x56FF01) + dislocker.log(title=f"[INFO] PC {pc_number} の使用を強制終了しました。", message=f"理由 | {about}", flag=0) elif force_stop["result"] == 1: if force_stop["about"] == "not_used": - await interaction.response.send_message(":x: そのPCは使用されていません。", ephemeral=True) + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'指定されたPCは使用されていないようです...', color=0xC91111) + elif force_stop["about"] == "bot_about_not_found": - await interaction.response.send_message(":x: 理由が指定されていません。", ephemeral=True) + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'強制停止する理由を入力してください。', color=0xC91111) + elif force_stop["about"] == "error": - await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'サーバーでエラーが発生しています。', color=0xC91111) + result_embed.add_field(name=f"{force_stop['output_dict']['error_class_name']}", value=f"{force_stop['output_dict']['error_args']}") + + await interaction.response.send_message(embed=result_embed, ephemeral=True) @tree.command(name="report", description="PCの使用履歴をエクスポートします。") @discord.app_commands.default_permissions(administrator=True) @@ -1318,7 +1455,9 @@ async def button_init(interaction: discord.Interaction, text_channel: discord.Te await client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: 使いたいPCの番号を選んでください!', view=pc_button_view) dislocker.log(title=f"[INFO] サーバーで初回処理を実行しました。", flag=0) - await interaction.response.send_message(f":white_check_mark: ボタンを送信しました!", ephemeral=True) + result_embed = discord.Embed(title=":white_check_mark: 初回処理が完了しました。", description=f'指定したテキストチャンネルをご確認ください。', color=0x56FF01) + + await interaction.response.send_message(embed=result_embed, ephemeral=True) @tree.command(name="masterpass", description="PCのマスターパスワードを表示します。") @discord.app_commands.default_permissions(administrator=True) @@ -1328,9 +1467,58 @@ async def masterpass(interaction: discord.Interaction, pc_number: int): if pc_master_password_get["result"] == 0: pc_master_password = pc_master_password_get["output_dict"]["pc_master_password"] - await interaction.response.send_message(f"# :key: PC番号 {pc_number} 番のマスターパスワードは以下の通りです。\n>>> # マスターパスワード | {pc_master_password}", ephemeral=True) + + result_embed = discord.Embed(title=":information_source: マスターパスワード", description=f"PC番号 {str(pc_number)} 番のマスターパスワードを表示します。", color=0x2286C9) + result_embed.add_field(name=f"マスターパスワード", value=f"{str(pc_master_password)}") + else: - await interaction.response.send_message("# :skull_crossbones: マスターパスワードの取得に失敗しました。", ephemeral=True) + result_embed = discord.Embed(title=":x: 取得に失敗しました。", description=f'サーバーでエラーが発生しています。', color=0xC91111) + result_embed.add_field(name=f"{pc_master_password_get['output_dict']['error_class_name']}", value=f"{pc_master_password_get['output_dict']['error_args']}") + + await interaction.response.send_message(embed=result_embed, ephemeral=True) + +@tree.command(name="pcinfo", description="PCの情報を表示します。") +@discord.app_commands.default_permissions(administrator=True) +async def pcinfo(interaction: discord.Interaction): + if interaction.guild_id in dislocker.server_config["bot"]["server_id"] or interaction.user.id in dislocker.server_config["bot"]["admin_user_id"]: + pc_list = dislocker.get_pc_list() + + if pc_list["result"] == 0: + result_embed = discord.Embed(title=":information_source: 現在のPCリスト", description="PCリストです。", color=0x2286C9) + + for i in pc_list['output_dict'].keys(): + if i['alt_name'] == None: + pc_name_title = f'{i['pc_number']} 番' + else: + pc_name_title = f'{i['pc_number']} 番 ({i['alt_name']})' + + if i['using_member_id'] == None: + pc_using_value = f'未使用' + else: + discord_user_id = dislocker.get_discord_user_id(i['using_member_id']) + pc_using_value = f'<@{discord_user_id}> が使用中' + + result_embed.add_field(name=f'{pc_name_title}', value=f'{pc_using_value}') + + else: + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'サーバーでエラーが発生しています。', color=0xC91111) + result_embed.add_field(name=f"{pc_list['output_dict']['error_class_name']}", value=f"{pc_list['output_dict']['error_args']}") + + await interaction.response.send_message(embed=result_embed, ephemeral=True) + +@tree.command(name="pcnickname", description="PCにニックネームを設定します。") +@discord.app_commands.default_permissions(administrator=True) +async def pcnickname(interaction: discord.Interaction, pc_number: int, nickname: str): + if interaction.guild_id in dislocker.server_config["bot"]["server_id"] or interaction.user.id in dislocker.server_config["bot"]["admin_user_id"]: + pc_nickname_set = dislocker.set_pc_nickname(pc_number=pc_number, nickname=nickname) + if pc_nickname_set["result"] == 0: + result_embed = discord.Embed(title=":white_check_mark: 操作が完了しました。", description=f'PC番号 {str(pc_number)} のニックネームは {str(nickname)} に設定されました。', color=0x56FF01) + + else: + result_embed = discord.Embed(title=":x: 操作に失敗しました。", description=f'サーバーでエラーが発生しています。ニックネームは変更されません。', color=0xC91111) + result_embed.add_field(name=f"{pc_nickname_set['output_dict']['error_class_name']}", value=f"{pc_nickname_set['output_dict']['error_args']}") + + await interaction.response.send_message(embed=result_embed, ephemeral=True) if dislocker.init_result == "ok": From 5f175064477f95d24f127a0b9716525d64e01c89 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sun, 29 Sep 2024 00:08:56 +0900 Subject: [PATCH 32/41] =?UTF-8?q?PC,=E3=83=87=E3=83=90=E3=82=A4=E3=82=B9?= =?UTF-8?q?=E3=81=AE=E7=99=BB=E9=8C=B2=E3=83=9C=E3=82=BF=E3=83=B3=E3=81=8C?= =?UTF-8?q?db=E3=81=A8=E9=80=A3=E5=8B=95=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 101 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 15 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 7969d37..941bc21 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -804,11 +804,71 @@ class DL(): else: cursor.execute("SELECT * FROM pc_list ORDER BY pc_number") pc_list = cursor.fetchall() - pc_list = {} + pc_list_base = {} for i in pc_list: - pc_list[i[0]] = {"pc_number": i[0], "using_member_id": i[1], "master_password": i[5], "detail": i[6], "alt_name": i[7]} + pc_list_base[i[0]] = {"pc_number": i[0], "using_member_id": i[1], "master_password": i[5], "detail": i[6], "alt_name": i[7]} - return {"result": 0, "about": "ok", "output_dict": pc_list} + return {"result": 0, "about": "ok", "output_dict": pc_list_base} + + except Exception as error: + self.log(title=f"[ERROR] PCリストの取得中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} + + finally: + if cursor: + cursor.close() + + def get_keyboard_list(self, **kwargs): + try: + cursor = self.db.cursor() + + if "keyboard_number" in kwargs: + keyboard_number = int(kwargs["keyboard_number"]) + cursor.execute("SELECT * FROM keyboard_list WHERE keyboard_number = %s", (keyboard_number,)) + keyboard_list = cursor.fetchall() + + return {"result": 0, "about": "ok", "output_dict": {keyboard_number: {"keyboard_number": keyboard_list[0][0], "using_member_id": keyboard_list[0][1], "device_instance_path": keyboard_list[0][2], "device_name": keyboard_list[0][3], "detail": keyboard_list[0][4], "alt_name": keyboard_list[0][5]}}} + else: + cursor.execute("SELECT * FROM keyboard_list ORDER BY keyboard_number") + keyboard_list = cursor.fetchall() + keyboard_list_base = {} + for i in keyboard_list: + if i['keyboard_number'] == 0: + pass + else: + keyboard_list_base[i[0]] = {"keyboard_number": i[0], "using_member_id": i[1], "device_instance_path": i[2], "device_name": i[3], "detail": i[4], "alt_name": i[5]} + + return {"result": 0, "about": "ok", "output_dict": keyboard_list_base} + + except Exception as error: + self.log(title=f"[ERROR] PCリストの取得中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} + + finally: + if cursor: + cursor.close() + + def get_mouse_list(self, **kwargs): + try: + cursor = self.db.cursor() + + if "mouse_number" in kwargs: + mouse_number = int(kwargs["mouse_number"]) + cursor.execute("SELECT * FROM mouse_list WHERE mouse_number = %s", (mouse_number,)) + mouse_list = cursor.fetchall() + + return {"result": 0, "about": "ok", "output_dict": {mouse_number: {"mouse_number": mouse_list[0][0], "using_member_id": mouse_list[0][1], "device_instance_path": mouse_list[0][2], "device_name": mouse_list[0][3], "detail": mouse_list[0][4], "alt_name": mouse_list[0][5]}}} + else: + cursor.execute("SELECT * FROM mouse_list ORDER BY mouse_number") + mouse_list = cursor.fetchall() + mouse_list_base = {} + for i in mouse_list: + if i['mouse_number'] == 0: + pass + else: + mouse_list_base[i[0]] = {"keyboard_number": i[0], "using_member_id": i[1], "device_instance_path": i[2], "device_name": i[3], "detail": i[4], "alt_name": i[5]} + + return {"result": 0, "about": "ok", "output_dict": mouse_list_base} except Exception as error: self.log(title=f"[ERROR] PCリストの取得中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) @@ -1113,12 +1173,15 @@ async def on_button(interaction: discord.Interaction): if custom_id_split[0] == "pcregister": keyboard_register_view = discord.ui.View(timeout=15) pc_number = custom_id_split[1] - for i in dislocker.keyboard_list: - if i == 0: - pass + keyboard_list = dislocker.get_keyboard_list() + + for i in keyboard_list["output_dict"].keys(): + if i['alt_name'] == None: + keyboard_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i['keyboard_number'])} 番", custom_id=f"keyboardregister_{str(pc_number)}_{str(i['keyboard_number'])}") else: - 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) + keyboard_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i['keyboard_number'])} 番 | ({i['alt_name']})", custom_id=f"keyboardregister_{str(pc_number)}_{str(i['keyboard_number'])}") + keyboard_register_view.add_item(keyboard_register_button) + keyboard_not_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="キーボードは自前", custom_id=f"keyboardregister_{str(pc_number)}_own") keyboard_register_view.add_item(keyboard_not_register_button) @@ -1128,16 +1191,19 @@ async def on_button(interaction: discord.Interaction): mouse_register_view = discord.ui.View(timeout=15) pc_number = custom_id_split[1] keyboard_number = custom_id_split[2] + mouse_list = dislocker.get_mouse_list() if keyboard_number == "own": keyboard_number_show = "自前" else: keyboard_number_show = keyboard_number - for i in dislocker.mouse_list: - if i == 0: - pass + + for i in mouse_list["output_dict"].keys(): + if i['alt_name'] == None: + mouse_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i['mouse_number'])} 番", custom_id=f"mouseregister_{str(pc_number)}_{str(keyboard_number)}_{str(i['mouse_number'])}") else: - 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) + mouse_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i['mouse_number'])} 番 | ({i['alt_name']})", custom_id=f"mouseregister_{str(pc_number)}_{str(keyboard_number)}_{str(i['mouse_number'])}") + mouse_register_view.add_item(mouse_register_button) + mouse_not_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="マウスは自前", custom_id=f"mouseregister_{str(pc_number)}_{str(keyboard_number)}_own") mouse_register_view.add_item(mouse_not_register_button) @@ -1435,6 +1501,8 @@ async def report(interaction: discord.Interaction): @discord.app_commands.default_permissions(administrator=True) async def button_init(interaction: discord.Interaction, text_channel: discord.TextChannel): if interaction.guild_id in dislocker.server_config["bot"]["server_id"] or interaction.user.id in dislocker.server_config["bot"]["admin_user_id"]: + pc_list = dislocker.get_pc_list() + user_register_button_view = discord.ui.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) @@ -1448,8 +1516,11 @@ async def button_init(interaction: discord.Interaction, text_channel: discord.Te await client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: 使用を停止しますか?', view=stop_button_view) pc_button_view = discord.ui.View(timeout=None) - for i in dislocker.pc_list: - pc_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i)}", custom_id=f"pcregister_{str(i)}") + for i in pc_list["output_dict"].keys(): + if i['alt_name'] == None: + pc_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i['pc_number'])} 番", custom_id=f"pcregister_{str(i['pc_number'])}") + else: + pc_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i['pc_number'])} 番 | ({i['alt_name']})", custom_id=f"pcregister_{str(i['pc_number'])}") pc_button_view.add_item(pc_register_button) await client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: 使いたいPCの番号を選んでください!', view=pc_button_view) From c82351e1868576300bffdf64a14046be91213ec9 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sun, 29 Sep 2024 00:18:30 +0900 Subject: [PATCH 33/41] =?UTF-8?q?=E3=83=9C=E3=82=BF=E3=83=B3=E3=82=92?= =?UTF-8?q?=E5=91=BC=E3=81=B3=E5=87=BA=E3=81=9B=E3=81=AA=E3=81=84=E3=83=90?= =?UTF-8?q?=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 941bc21..13680cf 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -1176,10 +1176,11 @@ async def on_button(interaction: discord.Interaction): keyboard_list = dislocker.get_keyboard_list() for i in keyboard_list["output_dict"].keys(): - if i['alt_name'] == None: - keyboard_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i['keyboard_number'])} 番", custom_id=f"keyboardregister_{str(pc_number)}_{str(i['keyboard_number'])}") + current_keyboard_list = keyboard_list['output_dict'][i] + if current_keyboard_list['alt_name'] == None: + keyboard_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(current_keyboard_list['keyboard_number'])} 番", custom_id=f"keyboardregister_{str(pc_number)}_{str(current_keyboard_list['keyboard_number'])}") else: - keyboard_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i['keyboard_number'])} 番 | ({i['alt_name']})", custom_id=f"keyboardregister_{str(pc_number)}_{str(i['keyboard_number'])}") + keyboard_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(current_keyboard_list['keyboard_number'])} 番 | ({current_keyboard_list['alt_name']})", custom_id=f"keyboardregister_{str(pc_number)}_{str(current_keyboard_list['keyboard_number'])}") keyboard_register_view.add_item(keyboard_register_button) keyboard_not_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="キーボードは自前", custom_id=f"keyboardregister_{str(pc_number)}_own") @@ -1198,10 +1199,11 @@ async def on_button(interaction: discord.Interaction): keyboard_number_show = keyboard_number for i in mouse_list["output_dict"].keys(): + current_mouse_list = mouse_list['output_dict'][i] if i['alt_name'] == None: - mouse_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i['mouse_number'])} 番", custom_id=f"mouseregister_{str(pc_number)}_{str(keyboard_number)}_{str(i['mouse_number'])}") + mouse_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(current_mouse_list['mouse_number'])} 番", custom_id=f"mouseregister_{str(pc_number)}_{str(keyboard_number)}_{str(current_mouse_list['mouse_number'])}") else: - mouse_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i['mouse_number'])} 番 | ({i['alt_name']})", custom_id=f"mouseregister_{str(pc_number)}_{str(keyboard_number)}_{str(i['mouse_number'])}") + mouse_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(current_mouse_list['mouse_number'])} 番 | ({current_mouse_list['alt_name']})", custom_id=f"mouseregister_{str(pc_number)}_{str(keyboard_number)}_{str(current_mouse_list['mouse_number'])}") mouse_register_view.add_item(mouse_register_button) mouse_not_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label="マウスは自前", custom_id=f"mouseregister_{str(pc_number)}_{str(keyboard_number)}_own") @@ -1517,10 +1519,11 @@ async def button_init(interaction: discord.Interaction, text_channel: discord.Te pc_button_view = discord.ui.View(timeout=None) for i in pc_list["output_dict"].keys(): - if i['alt_name'] == None: - pc_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i['pc_number'])} 番", custom_id=f"pcregister_{str(i['pc_number'])}") + current_pc_list = pc_list['output_dict'][i] + if current_pc_list['alt_name'] == None: + pc_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(current_pc_list['pc_number'])} 番", custom_id=f"pcregister_{str(current_pc_list['pc_number'])}") else: - pc_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(i['pc_number'])} 番 | ({i['alt_name']})", custom_id=f"pcregister_{str(i['pc_number'])}") + pc_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(current_pc_list['pc_number'])} 番 | ({current_pc_list['alt_name']})", custom_id=f"pcregister_{str(current_pc_list['pc_number'])}") pc_button_view.add_item(pc_register_button) await client.get_channel(text_channel.id).send(f'# :index_pointing_at_the_viewer: 使いたいPCの番号を選んでください!', view=pc_button_view) @@ -1558,15 +1561,16 @@ async def pcinfo(interaction: discord.Interaction): result_embed = discord.Embed(title=":information_source: 現在のPCリスト", description="PCリストです。", color=0x2286C9) for i in pc_list['output_dict'].keys(): - if i['alt_name'] == None: - pc_name_title = f'{i['pc_number']} 番' + current_pc_list = pc_list['output_dict'][i] + if current_pc_list['alt_name'] == None: + pc_name_title = f'{current_pc_list['pc_number']} 番' else: - pc_name_title = f'{i['pc_number']} 番 ({i['alt_name']})' + pc_name_title = f'{current_pc_list['pc_number']} 番 ({current_pc_list['alt_name']})' - if i['using_member_id'] == None: + if current_pc_list['using_member_id'] == None: pc_using_value = f'未使用' else: - discord_user_id = dislocker.get_discord_user_id(i['using_member_id']) + discord_user_id = dislocker.get_discord_user_id(current_pc_list['using_member_id']) pc_using_value = f'<@{discord_user_id}> が使用中' result_embed.add_field(name=f'{pc_name_title}', value=f'{pc_using_value}') From dfb21e3a257780c4b1e94f921ef0d7ab11617aec Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sun, 29 Sep 2024 00:24:15 +0900 Subject: [PATCH 34/41] =?UTF-8?q?=E3=82=AD=E3=83=BC=E3=83=9C=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=80=81=E3=83=9E=E3=82=A6=E3=82=B9=E3=81=AE=E3=83=9C?= =?UTF-8?q?=E3=82=BF=E3=83=B3=E3=81=8C=E5=91=BC=E3=81=B3=E5=87=BA=E3=81=9B?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 13680cf..c0e53fa 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -833,7 +833,7 @@ class DL(): keyboard_list = cursor.fetchall() keyboard_list_base = {} for i in keyboard_list: - if i['keyboard_number'] == 0: + if i[0] == 0: pass else: keyboard_list_base[i[0]] = {"keyboard_number": i[0], "using_member_id": i[1], "device_instance_path": i[2], "device_name": i[3], "detail": i[4], "alt_name": i[5]} @@ -841,7 +841,7 @@ class DL(): return {"result": 0, "about": "ok", "output_dict": keyboard_list_base} except Exception as error: - self.log(title=f"[ERROR] PCリストの取得中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + self.log(title=f"[ERROR] キーボードリストの取得中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} finally: @@ -863,7 +863,7 @@ class DL(): mouse_list = cursor.fetchall() mouse_list_base = {} for i in mouse_list: - if i['mouse_number'] == 0: + if i[0] == 0: pass else: mouse_list_base[i[0]] = {"keyboard_number": i[0], "using_member_id": i[1], "device_instance_path": i[2], "device_name": i[3], "detail": i[4], "alt_name": i[5]} @@ -871,7 +871,7 @@ class DL(): return {"result": 0, "about": "ok", "output_dict": mouse_list_base} except Exception as error: - self.log(title=f"[ERROR] PCリストの取得中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) + self.log(title=f"[ERROR] マウスリストの取得中にエラーが発生しました。 {str(error.__class__.__name__)}", message=str(error.args), flag=1) return {"result": 1, "about": "error", "output_dict": {"error_class_name": str(error.__class__.__name__), "error_args": str(error.args)}} finally: From b0865354a3bcb8aaf5bb4385cba0abb4644188eb Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sun, 29 Sep 2024 00:28:59 +0900 Subject: [PATCH 35/41] =?UTF-8?q?PC=E3=81=AE=E3=83=8B=E3=83=83=E3=82=AF?= =?UTF-8?q?=E3=83=8D=E3=83=BC=E3=83=A0=E3=81=8C=E7=99=BB=E9=8C=B2=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=81=AA=E3=81=84=E3=83=90=E3=82=B0=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_slash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index c0e53fa..82036a6 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -1585,7 +1585,7 @@ async def pcinfo(interaction: discord.Interaction): @discord.app_commands.default_permissions(administrator=True) async def pcnickname(interaction: discord.Interaction, pc_number: int, nickname: str): if interaction.guild_id in dislocker.server_config["bot"]["server_id"] or interaction.user.id in dislocker.server_config["bot"]["admin_user_id"]: - pc_nickname_set = dislocker.set_pc_nickname(pc_number=pc_number, nickname=nickname) + pc_nickname_set = dislocker.set_pc_nickname(pc_number=pc_number, alt_name=nickname) if pc_nickname_set["result"] == 0: result_embed = discord.Embed(title=":white_check_mark: 操作が完了しました。", description=f'PC番号 {str(pc_number)} のニックネームは {str(nickname)} に設定されました。', color=0x56FF01) From 970e04bc75cddd1c47dde72fa815de611962c62b Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sun, 29 Sep 2024 00:31:32 +0900 Subject: [PATCH 36/41] =?UTF-8?q?=E3=83=9E=E3=82=A6=E3=82=B9=E3=81=AE?= =?UTF-8?q?=E7=99=BB=E9=8C=B2=E3=83=9C=E3=82=BF=E3=83=B3=E3=81=8C=E5=87=BA?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index 82036a6..a080391 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -1200,7 +1200,7 @@ async def on_button(interaction: discord.Interaction): for i in mouse_list["output_dict"].keys(): current_mouse_list = mouse_list['output_dict'][i] - if i['alt_name'] == None: + if current_mouse_list['alt_name'] == None: mouse_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(current_mouse_list['mouse_number'])} 番", custom_id=f"mouseregister_{str(pc_number)}_{str(keyboard_number)}_{str(current_mouse_list['mouse_number'])}") else: mouse_register_button = discord.ui.Button(style=discord.ButtonStyle.primary, label=f"{str(current_mouse_list['mouse_number'])} 番 | ({current_mouse_list['alt_name']})", custom_id=f"mouseregister_{str(pc_number)}_{str(keyboard_number)}_{str(current_mouse_list['mouse_number'])}") From 0b718125ee64312c14296eafd51ccfd902b79474 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sun, 29 Sep 2024 00:40:13 +0900 Subject: [PATCH 37/41] =?UTF-8?q?=E3=83=9E=E3=82=A6=E3=82=B9=E3=81=AE?= =?UTF-8?q?=E7=99=BB=E9=8C=B2=E3=83=9C=E3=82=BF=E3=83=B3=E3=81=8C=E5=87=BA?= =?UTF-8?q?=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E4=BF=AE=E6=AD=A3(2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index a080391..8b01d1d 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -866,7 +866,7 @@ class DL(): if i[0] == 0: pass else: - mouse_list_base[i[0]] = {"keyboard_number": i[0], "using_member_id": i[1], "device_instance_path": i[2], "device_name": i[3], "detail": i[4], "alt_name": i[5]} + mouse_list_base[i[0]] = {"mouse_number": i[0], "using_member_id": i[1], "device_instance_path": i[2], "device_name": i[3], "detail": i[4], "alt_name": i[5]} return {"result": 0, "about": "ok", "output_dict": mouse_list_base} From f237d4ce0686723342263b7e1d25f0ac2d1bea9e Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sun, 29 Sep 2024 00:52:32 +0900 Subject: [PATCH 38/41] =?UTF-8?q?dislocker=E3=81=AE=E5=9C=A7=E7=B8=AE?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/download.cmd | 1 + 1 file changed, 1 insertion(+) diff --git a/script/download.cmd b/script/download.cmd index 5584a13..6644a85 100644 --- a/script/download.cmd +++ b/script/download.cmd @@ -12,4 +12,5 @@ tar -xf %dir%\dislocker_client.zip -C %dir%\temp_ds mkdir C:\ProgramData\Dislocker xcopy /e %dir%\temp_ds C:\ProgramData\Dislocker rmdir /s /q %dir%\temp_ds +del %dir%\dislocker_client.zip C:\ProgramData\Dislocker\setup.cmd \ No newline at end of file From d6e046178ee83e0bf7c539c479c3ac8ffb6cbb84 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sun, 29 Sep 2024 00:52:52 +0900 Subject: [PATCH 39/41] =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=BF=E3=83=BC?= =?UTF-8?q?=E3=83=8D=E3=83=83=E3=83=88=E7=B5=8C=E7=94=B1=E3=81=A7=E3=82=A2?= =?UTF-8?q?=E3=83=83=E3=83=97=E3=83=87=E3=83=BC=E3=83=88=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=81=9F=E3=82=81=E3=81=AE=E3=82=B9=E3=82=AF=E3=83=AA=E3=83=97?= =?UTF-8?q?=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/update_online.cmd | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 script/update_online.cmd diff --git a/script/update_online.cmd b/script/update_online.cmd new file mode 100644 index 0000000..0cee3d8 --- /dev/null +++ b/script/update_online.cmd @@ -0,0 +1,18 @@ +@echo off +set dir=%~dp0 +cd %dir% + +set download_url="" + +curl -L %download_url% -o %dir%\dislocker_client.zip + +mkdir %dir%\temp_ds +tar -xf %dir%\dislocker_client.zip -C %dir%\temp_ds + +rmdir /s /q C:\ProgramData\Dislocker\_internal +xcopy /e %dir%\temp_ds C:\ProgramData\Dislocker +xcopy /Y %dir%\temp_ds\dislocker_client.exe C:\ProgramData\Dislocker\dislocker_client.exe +rmdir /s /q %dir%\temp_ds +del %dir%\dislocker_client.zip +echo Abvf[gBDefendeřx߁AxNĂĂB +pause \ No newline at end of file From d93111b7237eaf532e5a969968fb3d1c671f8594 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sun, 29 Sep 2024 00:59:55 +0900 Subject: [PATCH 40/41] =?UTF-8?q?=E3=82=B3=E3=83=94=E3=83=BC=E3=82=92=5Fin?= =?UTF-8?q?ternal=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF=E3=83=88=E3=83=AA?= =?UTF-8?q?=E3=81=A0=E3=81=91=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/update_online.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/update_online.cmd b/script/update_online.cmd index 0cee3d8..66c9d6a 100644 --- a/script/update_online.cmd +++ b/script/update_online.cmd @@ -10,7 +10,7 @@ mkdir %dir%\temp_ds tar -xf %dir%\dislocker_client.zip -C %dir%\temp_ds rmdir /s /q C:\ProgramData\Dislocker\_internal -xcopy /e %dir%\temp_ds C:\ProgramData\Dislocker +xcopy /e %dir%\temp_ds\_internal C:\ProgramData\Dislocker\_internal xcopy /Y %dir%\temp_ds\dislocker_client.exe C:\ProgramData\Dislocker\dislocker_client.exe rmdir /s /q %dir%\temp_ds del %dir%\dislocker_client.zip From 1385eff922bbde13cf592753d2108d38eafdc550 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sun, 29 Sep 2024 01:02:51 +0900 Subject: [PATCH 41/41] =?UTF-8?q?=E6=96=87=E8=A8=80=E3=82=92=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dislocker_client.py b/dislocker_client.py index d3517ab..a2f6ed0 100644 --- a/dislocker_client.py +++ b/dislocker_client.py @@ -284,7 +284,7 @@ class Lock(customtkinter.CTkToplevel): self.msg_subtitle_1 = customtkinter.CTkLabel(self.msg_subtitle_frame, text='サインインするには、Discordのダイレクトメッセージに送信された\nパスワードを入力してください。', font=self.general_font, justify="left") self.msg_subtitle_1.grid(row=0, column=0, padx=10, sticky="ew") - self.msg_subtitle_2 = customtkinter.CTkLabel(self.msg_subtitle_frame, text='※ パスワードの有効期限は23:59までです。', font=self.general_small_font, justify="left") + self.msg_subtitle_2 = customtkinter.CTkLabel(self.msg_subtitle_frame, text='※ パスワードの有効期限は発行から5分間です。', font=self.general_small_font, justify="left") self.msg_subtitle_2.grid(row=1, column=0, padx=10, sticky="w") self.input_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent')