From 33dd3aef9b38c892a76f867314a864f1ee0fb30f Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 18:09:51 +0900 Subject: [PATCH] =?UTF-8?q?=E6=8C=87=E5=AE=9A=E3=83=A6=E3=83=BC=E3=82=B6?= =?UTF-8?q?=E3=83=BC=E3=81=AEDM=E3=81=AB=E3=81=93=E3=81=9F=E3=81=88?= =?UTF-8?q?=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: