From 1bf03a600e421a111cce27120fed4cfbb2c7b5a5 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Sat, 20 Jul 2024 23:08:27 +0900 Subject: [PATCH] =?UTF-8?q?PC=E3=81=AE=E7=99=BB=E9=8C=B2=E3=81=8C=E3=83=81?= =?UTF-8?q?=E3=83=A3=E3=83=B3=E3=83=8D=E3=83=AB=E4=B8=8A=E3=81=A7=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.py | 124 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 93 insertions(+), 31 deletions(-) diff --git a/dislocker.py b/dislocker.py index 0b404d7..9da1875 100644 --- a/dislocker.py +++ b/dislocker.py @@ -32,7 +32,8 @@ class DL(): "bot": { "token": "TYPE HERE BOTS TOKEN KEY", "log_channel_id" : "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)", - "config_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 !!!!)" } } @@ -247,6 +248,30 @@ class Bot(discord.Client): return value.strftime('%Y-%m-%d %H:%M:%S') return value + def pc_register(self, **kwargs): + try: + pc_number = int(kwargs["pc_number"]) + cursor = dislocker.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,)) + dislocker.db.commit() + result = {"result": "ok"} + else: + result = {"result": "already_exists"} + + except Exception as error: + print("PCの登録中にエラーが発生しました。\nエラー内容") + print(str(error.__class__.__name__)) + print(str(error.args)) + print(str(error)) + result = {"result": "error"} + + finally: + cursor.close() + return result + def report_export(self, **kwargs): try: cursor = dislocker.db.cursor() @@ -358,7 +383,7 @@ class Bot(discord.Client): if msg_split[0] == "/password" or msg_split[0] == "/start": #メッセージの要素が2つ以下の場合は拒否 if len(msg_split) <= 2: - await message.channel.send("PC番号、もしくはデバイス番号が入力されていません。") + await message.channel.send("# :warning: PC番号、もしくはデバイス番号が入力されていません。") #メッセージの要素が3つ以上の場合 elif len(msg_split) >= 3: #番号が数字であることを確認 @@ -372,28 +397,28 @@ class Bot(discord.Client): if register["result"] == "ok": if len(msg_split) == 3: - await message.channel.send(f"使用が開始されました。\nパスワード | {register["password"]}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}") + await message.channel.send(f":white_check_mark: 使用が開始されました。\n>>> # パスワード | {register["password"]}\n>>> # PC番号 | {msg_split[1]}\n>>> # デバイス番号 | {msg_split[2]}") elif len(msg_split) == 4: - await message.channel.send(f"使用が開始されました。\nパスワード | {register["password"]}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n使用目的 | {msg_split[3]}") - await self.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f'{register["name"]} さんがPC {msg_split[1]} を使用しています') + await message.channel.send(f":white_check_mark: 使用が開始されました。\n>>> # パスワード | {register["password"]}\n>>> # PC番号 | {msg_split[1]}\n>>> # デバイス番号 | {msg_split[2]}\n>>> # 使用目的 | {msg_split[3]}") + await self.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f':white_check_mark: {register["name"]} さんがPC {msg_split[1]} の使用を開始しました。') elif register["result"] == "user_data_not_found": - await message.channel.send("ユーザーとして登録されていないようです。最初にサーバーで登録を行ってください。") + await message.channel.send("# :dizzy_face: ユーザーとして登録されていないようです。\n最初にサーバーで登録を行ってください。") elif register["result"] == "pc_already_in_use_by_you": - await message.channel.send(f"あなたはPCをもう使用されているようです。使用状態を解除するには /stop で使用終了をお知らせください。\nPC番号 | {register["pc_number"]}\nデバイス番号 | {register["device_number"]}\n使用開始時刻 | {register["start_time"]}\n使用目的 | {register["detail"]}") + await message.channel.send(f"# :exploding_head: あなたはPCをもう使用されているようです。\n使用状態を解除するには /stop で使用終了をお知らせください。\n>>> # PC番号 | {register["pc_number"]}\n>>> # デバイス番号 | {register["device_number"]}\n>>> # 使用開始時刻 | {register["start_time"]}\n>>> # 使用目的 | {register["detail"]}") elif register["result"] == "pc_already_in_use_by_other": - await message.channel.send(f"そのPCは他のメンバーによって使用されています。別のPC番号を指定して、再度お試しください。") + await message.channel.send(f"# :man_gesturing_no: そのPCは他のメンバーによって使用されています。\n別のPC番号を指定して、再度お試しください。") else: - await message.channel.send("番号がおかしいようです。") + await message.channel.send("# :dizzy_face: 番号がおかしいようです。") else: - await message.channel.send("指定された番号は不正です。") + await message.channel.send("# :dizzy_face: 指定された番号は不正です。") elif msg_split[0] == "/stop": stop = self.stop(user_id=message.author.id) if stop["result"] == "unused": - await message.channel.send("使用されていないようです...") + await message.channel.send("# :shaking_face: 使用されていないようです...") elif stop["result"] == "ok": - await message.channel.send(f"PC番号 {stop["pc_number"]} の使用が終了されました。") - await self.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f'{stop["name"]} さんがPC {stop["pc_number"]} の使用を終了しました') + await message.channel.send(f"# :negative_squared_cross_mark: PC番号 {stop["pc_number"]} の使用が終了されました。") + await self.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f':negative_squared_cross_mark: {stop["name"]} さんがPC {stop["pc_number"]} の使用を終了しました。') elif message.channel.id == dislocker.server_config["bot"]["config_channel_id"]: msg_split = message.content.split() @@ -403,47 +428,84 @@ class Bot(discord.Client): register = self.user_register(name=message.author.display_name, discord_user_name=message.author.name, discord_user_id=message.author.id) print(register) if register["result"] == "ok": - await message.channel.send(f"ユーザー情報が登録されました。\nユーザー名:{message.author.display_name}") + await message.channel.send(f"# :white_check_mark: ユーザー情報が登録されました。\nユーザー名:{message.author.display_name}") elif register["result"] == "already_exists": - await message.channel.send("登録できませんでした。もう登録されている可能性があります。") + await message.channel.send("# :no_entry: 登録できませんでした。\nもう登録されている可能性があります。") else: - await message.channel.send("登録できませんでした。内部エラーが発生しています。") + await message.channel.send("# :no_entry: 登録できませんでした。\n内部エラーが発生しています。") elif len(msg_split) <= 3: - await message.channel.send("名前、Discordのユーザー名、DiscordのユーザーIDのいずれかが入力されていません。") + await message.channel.send("# :japanese_goblin: 入力内容に不備があります。\n名前、Discordのユーザー名、DiscordのユーザーIDのいずれかが入力されていません。") elif len(msg_split) == 4: if msg_split[3].isdigit(): register = self.user_register(name=msg_split[1], discord_user_name=msg_split[2], discord_user_id=msg_split[3]) if register["result"] == "ok": - await message.channel.send(f"登録が完了しました。\n名前 | {msg_split[1]}\nDiscordのユーザー名 | {msg_split[2]}\nDiscordのユーザーID | {msg_split[3]}") + await message.channel.send(f"# :white_check_mark: 登録が完了しました。\n>>> # 名前 | {msg_split[1]}\n>>> # Discordのユーザー名 | {msg_split[2]}\n>>> # DiscordのユーザーID | {msg_split[3]}") elif register["result"] == "already_exists": - await message.channel.send("そのDiscordアカウントはすでに登録されています。") + await message.channel.send("# :skull_crossbones: 登録できませんでした。\nそのDiscordアカウントはすでに登録されています。") else: - await message.channel.send("DiscordのユーザーIDが不正です。") + await message.channel.send("# :skull_crossbones: 登録できませんでした。\nDiscordのユーザーIDが不正です。") else: - await message.channel.send("なんでかわからんけど不正です。") + await message.channel.send("# :skull_crossbones: 登録できませんでした。\n内部エラーが発生しています。") elif msg_split[0] == "/export": export = self.report_export() if export["result"] == "ok": - await message.channel.send("使用履歴のレポートです。", file=discord.File(export["file_path"])) + await message.channel.send("# :page_facing_up: 使用履歴のレポートです。", file=discord.File(export["file_path"])) pass elif export["result"] == "export_error": - await message.channel.send("エクスポートに失敗しました。") + await message.channel.send("# :volcano: エクスポートに失敗しました。") elif msg_split[0] == "/fstop": if len(msg_split) == 1: - await message.channel.send("PC番号を指定してください。") + await message.channel.send("# :warning: 登録を解除できませんでした。\n使用を停止したいPC番号を指定してください。\n-# /fstop PC番号") elif len(msg_split) == 2: - fstop = self.force_stop(pc_number=msg_split[1]) - if fstop["result"] == "ok": - await message.channel.send(f"PC番号 {msg_split[1]} の使用登録を解除しました。") - elif fstop["result"] == "not_used": - await message.channel.send("PCは使用されていないようです...") + if msg_split[1].isdigit(): + fstop = self.force_stop(pc_number=msg_split[1]) + if fstop["result"] == "ok": + await message.channel.send(f"# :white_check_mark: PC番号 {msg_split[1]} の使用登録を解除しました。") + elif fstop["result"] == "not_used": + await message.channel.send("# :exploding_head: 登録を解除できませんでした。\nPCは使用されていないようです...") + else: + await message.channel.send("# :x: 登録を解除できませんでした。\n内部エラーが発生しています。") else: - await message.channel.send("エラーが発生しました。") + await message.channel.send("# :warning: 登録を解除できませんでした。\nPC番号を認識できません。\n-# 半角数字で入力してください。") else: - await message.channel.send("引数が多すぎます。") + await message.channel.send("# warning: 登録を解除できませんでした。\構文が間違っています。\n-# /fstop PC番号") + + elif msg_split[0] == "/pcregister": + if len(msg_split) == 1: + await message.channel.send("# :warning: PCを登録できませんでした。\n登録したいPC番号を指定してください。\n-# 半角数字で入力してください。") + elif len(msg_split) == 2: + if msg_split[1].isdigit(): + pc_register = self.pc_register(pc_number=msg_split[1]) + if pc_register["result"] == "ok": + await message.channel.send(f"# :white_check_mark: PCを登録しました。\n>>> # PC番号 | {msg_split[1]}") + elif pc_register["result"] == "already_exists": + await message.channel.send(f":x: PCを登録できませんでした。\nその番号のPCは既に存在します。") + else: + await message.channel.send("# :x: PCを登録できませんでした。\n内部エラーが発生しています。") + else: + await message.channel.send("# :warning: PCを登録できませんでした。\nPC番号を認識できません。\n-# 半角数字で入力してください。") + else: + await message.channel.send("# :warning: PCを登録できませんでした。\n構文が間違っています。\n-# /pcregister PC番号") + + + elif message.channel.id == dislocker.server_config["bot"]["config_public_channel_id"]: + msg_split = message.content.split() + if msg_split[0] == "/register": + print(len(msg_split)) + if len(msg_split) == 1: + register = self.user_register(name=message.author.display_name, discord_user_name=message.author.name, discord_user_id=message.author.id) + print(register) + if register["result"] == "ok": + await message.channel.send(f"# :white_check_mark: ユーザー情報が登録されました。\nユーザー名:{message.author.display_name}") + elif register["result"] == "already_exists": + await message.channel.send("# :skull_crossbones: 登録できませんでした。\nそのDiscordアカウントはすでに登録されています。") + else: + await message.channel.send("# :skull_crossbones: 登録できませんでした。\n内部エラーが発生しています。") + else: + await message.channel.send("# :skull_crossbones: 登録できませんでした。\n\n-# もしかして...\n-# 手動でメンバーを登録したいですか?\n-# もしそうなら、このチャンネルにはその権限がありません。\n-# そのチャンネルに移動してから、もう一度試してみてください!") dislocker = DL()