返り値を修正

This commit is contained in:
suti7yk5032 2024-06-09 18:49:46 +09:00
parent 0427c021a0
commit d03d5ec4ef

View file

@ -36,18 +36,21 @@ class Bot(discord.Client):
user_record = cursor.fetchall()
#ユーザーデータがなかったら(未登録の場合)
if not user_record[0]:
return {"result": "user_data_not_found"}
result = {"result": "user_data_not_found"}
return result
#ユーザーデータが見つかった場合(登録済みの場合)
elif user_record[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()
if pc_usage_history_record[0][5] == None:
return {"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])}
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])}
return result
elif pc_usage_history_record[0][5] == None:
cursor.execute("SELECT * FROM pc_list WHERE pc_number=%s ORDER BY id DESC LIMIT 1", (pc_number,))
pc_list_record = cursor.fetchall()
if not pc_list_record[0][1] == None:
return {"result": "pc_already_in_use_by_other"}
result = {"result": "pc_already_in_use_by_other"}
return result
elif pc_list_record[0][1] == None:
if detail == None:
cursor.execute("INSERT INTO pc_usage_history (member_id, pc_number, device_number, start_use_time) VALUES (%s, %s, %s, current_timestamp)", (user_record[0][0], pc_number, device_number))
@ -58,7 +61,8 @@ class Bot(discord.Client):
cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (user_record[0][0], pc_number))
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password_hash, pc_number))
self.db.commit()
return {"result": "ok", "password": str(password), "name": str(user_record[0][1])}
result = {"result": "ok", "password": str(password), "name": str(user_record[0][1])}
return result
def stop(self, **kwrags):
discord_user_id = str(kwrags["user_id"])
@ -68,23 +72,26 @@ class Bot(discord.Client):
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()
if not pc_usage_history_record[0][5] == None:
return {"result": "unused"}
result = {"result": "unused"}
return result
elif pc_usage_history_record[0][5] == None:
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 password_hash = NULL WHERE pc_number = %s", (pc_usage_history_record[0][2],))
self.db.commit()
return {"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
async def on_ready(self):
print("ログイン成功")
async def on_message(self, message):
if message.author.bot:
return
pass
if isinstance(message.channel, discord.DMChannel):
msg_split = message.content.split()
print(msg_split)
if msg_split[0] == "/password" or "/start":
#メッセージの要素が2つ以下の場合は拒否
if len(msg_split) <= 2: