管理者コマンドのセキュリティの向上

This commit is contained in:
suti7yk5032 2024-09-26 21:57:13 +09:00
parent 8775b22738
commit 364b32c0e7

View file

@ -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,6 +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"]:
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)
@ -1217,6 +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"]:
max_count = how_much
pc_onetime_password_gen = dislocker.pc_onetime_gen(max_count=max_count)
@ -1241,6 +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"]:
max_count = how_much
device_onetime_password_gen = dislocker.device_onetime_gen(max_count=max_count)
@ -1265,6 +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"]:
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)
@ -1280,6 +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"]:
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)
@ -1291,6 +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"]:
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)
@ -1316,6 +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"]:
pc_master_password_get = dislocker.show_pc_master_password(pc_number=pc_number)
if pc_master_password_get["result"] == 0: