タイムスタンプのバグを修正
自動停止処理が時間をおいて起動するように
This commit is contained in:
parent
b9d9e797d3
commit
ba9f227e09
1 changed files with 13 additions and 11 deletions
24
dislocker.py
24
dislocker.py
|
@ -155,10 +155,10 @@ class Bot(discord.Client):
|
|||
result = {"result": "pc_already_in_use_by_other"}
|
||||
else:
|
||||
if user_info["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], user_info["pc_number"], user_info["device_number"]))
|
||||
cursor.execute("INSERT INTO pc_usage_history (member_id, pc_number, device_number, start_use_time) VALUES (%s, %s, %s, clock_timestamp())", (user_record[0][0], user_info["pc_number"], user_info["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], user_info["pc_number"], user_info["device_number"], user_info["detail"]))
|
||||
cursor.execute("INSERT INTO pc_usage_history (member_id, pc_number, device_number, start_use_time, use_detail) VALUES (%s, %s, %s, clock_timestamp(), %s)", (user_record[0][0], user_info["pc_number"], user_info["device_number"], user_info["detail"]))
|
||||
|
||||
cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (user_record[0][0], user_info["pc_number"]))
|
||||
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password_hash, user_info["pc_number"]))
|
||||
|
@ -173,10 +173,10 @@ class Bot(discord.Client):
|
|||
result = {"result": "pc_already_in_use_by_other"}
|
||||
else:
|
||||
if user_info["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], user_info["pc_number"], user_info["device_number"]))
|
||||
cursor.execute("INSERT INTO pc_usage_history (member_id, pc_number, device_number, start_use_time) VALUES (%s, %s, %s, clock_timestamp())", (user_record[0][0], user_info["pc_number"], user_info["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], user_info["pc_number"], user_info["device_number"], user_info["detail"]))
|
||||
cursor.execute("INSERT INTO pc_usage_history (member_id, pc_number, device_number, start_use_time, use_detail) VALUES (%s, %s, %s, clock_timestamp(), %s)", (user_record[0][0], user_info["pc_number"], user_info["device_number"], user_info["detail"]))
|
||||
|
||||
cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (user_record[0][0], user_info["pc_number"]))
|
||||
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password_hash, user_info["pc_number"]))
|
||||
|
@ -184,10 +184,10 @@ class Bot(discord.Client):
|
|||
result = {"result": "ok", "password": str(password), "name": str(user_record[0][1])}
|
||||
else:
|
||||
if user_info["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], user_info["pc_number"], user_info["device_number"]))
|
||||
cursor.execute("INSERT INTO pc_usage_history (member_id, pc_number, device_number, start_use_time) VALUES (%s, %s, %s, clock_timestamp())", (user_record[0][0], user_info["pc_number"], user_info["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], user_info["pc_number"], user_info["device_number"], user_info["detail"]))
|
||||
cursor.execute("INSERT INTO pc_usage_history (member_id, pc_number, device_number, start_use_time, use_detail) VALUES (%s, %s, %s, clock_timestamp(), %s)", (user_record[0][0], user_info["pc_number"], user_info["device_number"], user_info["detail"]))
|
||||
|
||||
cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (user_record[0][0], user_info["pc_number"]))
|
||||
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password_hash, user_info["pc_number"]))
|
||||
|
@ -219,7 +219,7 @@ class Bot(discord.Client):
|
|||
if not pc_usage_history_record[0][5] == None:
|
||||
result = {"result": "unused"}
|
||||
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 = clock_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],))
|
||||
dislocker.db.commit()
|
||||
|
@ -376,7 +376,7 @@ class Bot(discord.Client):
|
|||
|
||||
cursor.execute("SELECT * FROM pc_usage_history WHERE member_id = %s AND pc_number = %s ORDER BY id DESC LIMIT 1", (pc_list_record[0][1], pc_number))
|
||||
pc_usage_history_record = cursor.fetchall()
|
||||
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 = clock_timestamp() WHERE id = %s", (pc_usage_history_record[0][0],))
|
||||
dislocker.db.commit()
|
||||
result = {"result": "ok"}
|
||||
|
||||
|
@ -642,6 +642,7 @@ class Monitor():
|
|||
def __init__(self, **kwargs) -> None:
|
||||
self.serach_time = kwargs["search_time"]
|
||||
self.allowable_time = kwargs["allowable_time"]
|
||||
self.init_wait_time = 10
|
||||
|
||||
def start(self, **kwargs):
|
||||
serach_thread = threading.Thread(target=self.search)
|
||||
|
@ -650,6 +651,7 @@ class Monitor():
|
|||
|
||||
def search(self):
|
||||
try:
|
||||
time.sleep(self.init_wait_time)
|
||||
while True:
|
||||
cursor = dislocker.db.cursor()
|
||||
cursor.execute("SELECT * FROM pc_list WHERE password_hash IS NOT NULL")
|
||||
|
@ -675,7 +677,7 @@ class Monitor():
|
|||
stop = bot.stop(user_id=user_info[0][3])
|
||||
|
||||
bot.timeout_notify(pc_number=pc_list[0][0], discord_display_name=user_info[0][1])
|
||||
time.sleep(1)
|
||||
result = {"result": "STOP"}
|
||||
else:
|
||||
result = {"result": "BUT SAFE"}
|
||||
|
||||
|
@ -699,7 +701,7 @@ class Monitor():
|
|||
stop = bot.stop(user_id=user_info[0][3])
|
||||
|
||||
bot.timeout_notify(pc_number=i[0], discord_display_name=user_info[0][1])
|
||||
time.sleep(0.1)
|
||||
result = {"result": "STOP"}
|
||||
else:
|
||||
result = {"result": "BUT SAFE"}
|
||||
|
||||
|
@ -766,7 +768,7 @@ if dislocker.init_result == "ok":
|
|||
intents = discord.Intents.default()
|
||||
intents.message_content = True
|
||||
bot = Bot(intents=intents)
|
||||
monitor = Monitor(search_time=1, allowable_time=300)
|
||||
monitor = Monitor(search_time=1, allowable_time=60)
|
||||
monitor.start()
|
||||
bot.run(dislocker.server_config['bot']['token'])
|
||||
else:
|
||||
|
|
Loading…
Reference in a new issue