From f7f3e5d40b2f399b705f972949619012d5588ed5 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 26 Sep 2024 09:25:31 +0900 Subject: [PATCH] =?UTF-8?q?sql=E3=81=AE=E3=82=A4=E3=83=B3=E3=83=9D?= =?UTF-8?q?=E3=83=BC=E3=83=88=E3=82=92=E4=BF=AE=E6=AD=A3=E3=80=81=E6=97=A5?= =?UTF-8?q?=E6=9C=AC=E8=AA=9E=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_slash.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/dislocker_slash.py b/dislocker_slash.py index a668adf..d27b18a 100644 --- a/dislocker_slash.py +++ b/dislocker_slash.py @@ -2,6 +2,7 @@ import discord import os import json import psycopg2 +from psycopg2 import sql from datetime import datetime import asyncio import string @@ -531,19 +532,19 @@ class DL(): excel_file_path = self.export_dir_path + "pc_usage_history.xlsx" # メインテーブルの列情報を取得(user_idを除く) - cursor.execute(psycopg2.sql.SQL("SELECT * FROM {} LIMIT 0").format(psycopg2.sql.Identifier(main_table))) + cursor.execute(sql.SQL("SELECT * FROM {} LIMIT 0").format(sql.Identifier(main_table))) main_columns = [desc[0] for desc in cursor.description if desc[0] != 'member_id'] # クエリを作成(列名を明確に指定) - query = psycopg2.sql.SQL(""" + query = sql.SQL(""" SELECT {main_columns}, {related_table}.name FROM {main_table} LEFT JOIN {related_table} ON {main_table}.member_id = {related_table}.member_id ORDER BY id """).format( - main_columns=psycopg2.sql.SQL(', ').join([psycopg2.sql.SQL("{}.{}").format(psycopg2.sql.Identifier(main_table), psycopg2.sql.Identifier(col)) for col in main_columns]), - main_table=psycopg2.sql.Identifier(main_table), - related_table=psycopg2.sql.Identifier(related_table) + main_columns=sql.SQL(', ').join([sql.SQL("{}.{}").format(sql.Identifier(main_table), sql.Identifier(col)) for col in main_columns]), + main_table=sql.Identifier(main_table), + related_table=sql.Identifier(related_table) ) cursor.execute(query) @@ -787,7 +788,9 @@ async def devicereg(interaction: discord.Interaction): await interaction.response.send_message(":x: 内部エラーが発生しました。\nサーバーでエラーが発生しています。管理者に問い合わせてください。", ephemeral=True) @tree.command(name="fstop", description="PCの使用を強制終了します。") -async def fstop(interaction: discord.Interaction, pc_number: int, bot_about: str): +async def fstop(interaction: discord.Interaction, PC番号: int, 理由: str): + pc_number = PC番号 + bot_about = 理由 force_stop = dislocker.force_stop(pc_number=pc_number, bot_about=bot_about) if force_stop["result"] == 0: await interaction.response.send_message(f":white_check_mark: PC {pc_number} の使用を強制終了しました。", ephemeral=True)