初回の処理を修正

This commit is contained in:
suti7yk5032 2024-06-09 20:11:20 +09:00
parent 5c15c0b092
commit 260779fca3

View file

@ -41,8 +41,9 @@ class Bot(discord.Client):
else: else:
cursor.execute("SELECT * FROM pc_usage_history WHERE member_id=%s ORDER BY id DESC LIMIT 1", (user_record[0][0],)) cursor.execute("SELECT * FROM pc_usage_history WHERE member_id=%s ORDER BY id DESC LIMIT 1", (user_record[0][0],))
pc_usage_history_record = cursor.fetchall() pc_usage_history_record = cursor.fetchall()
if pc_usage_history_record[0][5] == None: if pc_usage_history_record:
result = {"result": "pc_already_in_use_by_you", "pc_number": str(pc_usage_history_record[0][2]), "device_number": str(pc_usage_history_record[0][3]), "start_time": str(pc_usage_history_record[0][4]), "detail": str(pc_usage_history_record[0][6])} if pc_usage_history_record[0][5] == None:
result = {"result": "pc_already_in_use_by_you", "pc_number": str(pc_usage_history_record[0][2]), "device_number": str(pc_usage_history_record[0][3]), "start_time": str(pc_usage_history_record[0][4]), "detail": str(pc_usage_history_record[0][6])}
else: else:
cursor.execute("SELECT * FROM pc_list WHERE pc_number=%s", (pc_number,)) cursor.execute("SELECT * FROM pc_list WHERE pc_number=%s", (pc_number,))
pc_list_record = cursor.fetchall() pc_list_record = cursor.fetchall()
@ -69,15 +70,15 @@ class Bot(discord.Client):
user_record = cursor.fetchall() user_record = cursor.fetchall()
cursor.execute("SELECT * FROM pc_usage_history WHERE member_id= %s ORDER BY id DESC LIMIT 1", (user_record[0][0],)) cursor.execute("SELECT * FROM pc_usage_history WHERE member_id= %s ORDER BY id DESC LIMIT 1", (user_record[0][0],))
pc_usage_history_record = cursor.fetchall() pc_usage_history_record = cursor.fetchall()
if not pc_usage_history_record[0][5] == None: if pc_usage_history_record:
result = {"result": "unused"} if not pc_usage_history_record[0][5] == None:
result = {"result": "unused"}
else: else:
cursor.execute("UPDATE pc_usage_history SET end_use_time = current_timestamp WHERE id = %s", (pc_usage_history_record[0][0],)) cursor.execute("UPDATE pc_usage_history SET end_use_time = current_timestamp WHERE id = %s", (pc_usage_history_record[0][0],))
cursor.execute("UPDATE pc_list SET using_user_id = NULL WHERE pc_number = %s", (pc_usage_history_record[0][2],)) cursor.execute("UPDATE pc_list SET using_user_id = NULL WHERE pc_number = %s", (pc_usage_history_record[0][2],))
cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (pc_usage_history_record[0][2],)) cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (pc_usage_history_record[0][2],))
self.db.commit() self.db.commit()
result = {"result": "ok", "pc_number": str(pc_usage_history_record[0][2]), "name": str(user_record[0][1])} result = {"result": "ok", "pc_number": str(pc_usage_history_record[0][2]), "name": str(user_record[0][1])}
return result return result
@ -164,9 +165,6 @@ class Bot(discord.Client):
await message.channel.send("なんでかわからんけど不正です。") await message.channel.send("なんでかわからんけど不正です。")
config_dir_path = "./config/" config_dir_path = "./config/"
db_config_path = config_dir_path + "db.json" db_config_path = config_dir_path + "db.json"
if not os.path.isfile(db_config_path): if not os.path.isfile(db_config_path):