指定ユーザーのDMにこたえるように
This commit is contained in:
parent
02e0b8b95d
commit
33dd3aef9b
1 changed files with 90 additions and 0 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue