diff --git a/dislocker.py b/dislocker.py index 991fbb0..7adde0d 100644 --- a/dislocker.py +++ b/dislocker.py @@ -60,6 +60,28 @@ class Bot(discord.Client): cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password_hash, pc_number)) self.db.commit() result = {"result": "ok", "password": str(password), "name": str(user_record[0][1])} + else: + 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: + 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: + cursor.execute("SELECT * FROM pc_list WHERE pc_number=%s", (pc_number,)) + pc_list_record = cursor.fetchall() + if not pc_list_record[0][1] == None: + result = {"result": "pc_already_in_use_by_other"} + else: + 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)) + #使用用途があるとき + else: + cursor.execute("INSERT INTO pc_usage_history (member_id, pc_number, device_number, start_use_time, use_detail) VALUES (%s, %s, %s, current_timestamp, %s)", (user_record[0][0], pc_number, device_number, detail)) + + 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() + result = {"result": "ok", "password": str(password), "name": str(user_record[0][1])} return result