PC,デバイスの登録ボタンがdbと連動するように
This commit is contained in:
parent
ab96092b39
commit
5f17506447
1 changed files with 86 additions and 15 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue