ユーザーとして登録されていないときに停止ボタンを押したときに内部エラーと表示される仕様を変更
定期監視の一部仕様変更
This commit is contained in:
parent
425edead34
commit
2663ad2ff6
1 changed files with 25 additions and 19 deletions
44
dislocker.py
44
dislocker.py
|
@ -212,17 +212,22 @@ class Bot(discord.Client):
|
||||||
cursor = dislocker.db.cursor()
|
cursor = dislocker.db.cursor()
|
||||||
cursor.execute("SELECT * FROM club_member WHERE discord_userid = %s", (discord_user_id,))
|
cursor.execute("SELECT * FROM club_member WHERE discord_userid = %s", (discord_user_id,))
|
||||||
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],))
|
if user_record:
|
||||||
pc_usage_history_record = cursor.fetchall()
|
cursor.execute("SELECT * FROM pc_usage_history WHERE member_id= %s ORDER BY id DESC LIMIT 1", (user_record[0][0],))
|
||||||
if pc_usage_history_record:
|
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:
|
||||||
|
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],))
|
||||||
|
dislocker.db.commit()
|
||||||
|
result = {"result": "ok", "pc_number": str(pc_usage_history_record[0][2]), "name": str(user_record[0][1])}
|
||||||
else:
|
else:
|
||||||
cursor.execute("UPDATE pc_usage_history SET end_use_time = current_timestamp WHERE id = %s", (pc_usage_history_record[0][0],))
|
result = {"result": "unused"}
|
||||||
cursor.execute("UPDATE pc_list SET using_user_id = NULL WHERE pc_number = %s", (pc_usage_history_record[0][2],))
|
else:
|
||||||
cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (pc_usage_history_record[0][2],))
|
result = {"result": "user_data_not_found"}
|
||||||
dislocker.db.commit()
|
|
||||||
result = {"result": "ok", "pc_number": str(pc_usage_history_record[0][2]), "name": str(user_record[0][1])}
|
|
||||||
except:
|
except:
|
||||||
print("停止処理にエラーが発生しました。")
|
print("停止処理にエラーが発生しました。")
|
||||||
result = {"result": "error"}
|
result = {"result": "error"}
|
||||||
|
@ -615,6 +620,8 @@ class Bot(discord.Client):
|
||||||
stop_view = View(timeout=15)
|
stop_view = View(timeout=15)
|
||||||
if pc_stop["result"] == "unused":
|
if pc_stop["result"] == "unused":
|
||||||
await interaction.response.send_message("# :shaking_face: 使用されていないようです...", ephemeral=True)
|
await interaction.response.send_message("# :shaking_face: 使用されていないようです...", ephemeral=True)
|
||||||
|
elif pc_stop["result"] == "user_data_not_found":
|
||||||
|
await interaction.response.send_message("# :dizzy_face: ユーザーとして登録されていないようです。\n最初にサーバーで登録を行ってください。", ephemeral=True)
|
||||||
elif pc_stop["result"] == "ok":
|
elif pc_stop["result"] == "ok":
|
||||||
await interaction.response.send_message(f":white_check_mark: PC番号 {pc_stop["pc_number"]} の使用が終了されました。", ephemeral=True)
|
await interaction.response.send_message(f":white_check_mark: PC番号 {pc_stop["pc_number"]} の使用が終了されました。", ephemeral=True)
|
||||||
await self.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f':negative_squared_cross_mark: {pc_stop["name"]} さんがPC {pc_stop["pc_number"]} の使用を終了しました。')
|
await self.get_channel(dislocker.server_config["bot"]["log_channel_id"]).send(f':negative_squared_cross_mark: {pc_stop["name"]} さんがPC {pc_stop["pc_number"]} の使用を終了しました。')
|
||||||
|
@ -632,17 +639,15 @@ class Bot(discord.Client):
|
||||||
await interaction.response.send_message("# :no_entry: 登録できませんでした。\n内部エラーが発生しています。", ephemeral=True)
|
await interaction.response.send_message("# :no_entry: 登録できませんでした。\n内部エラーが発生しています。", ephemeral=True)
|
||||||
|
|
||||||
class Monitor():
|
class Monitor():
|
||||||
def __init__(self) -> None:
|
def __init__(self, **kwargs) -> None:
|
||||||
pass
|
|
||||||
|
|
||||||
def start(self, **kwargs):
|
|
||||||
self.serach_time = kwargs["search_time"]
|
self.serach_time = kwargs["search_time"]
|
||||||
self.allowable_time = kwargs["allowable_time"]
|
self.allowable_time = kwargs["allowable_time"]
|
||||||
|
|
||||||
|
def start(self, **kwargs):
|
||||||
serach_thread = threading.Thread(target=self.search)
|
serach_thread = threading.Thread(target=self.search)
|
||||||
serach_thread.start()
|
serach_thread.start()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def search(self):
|
def search(self):
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
@ -708,6 +713,7 @@ class Monitor():
|
||||||
print(result["result"])
|
print(result["result"])
|
||||||
time.sleep(self.serach_time)
|
time.sleep(self.serach_time)
|
||||||
|
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
print("自動停止処理中にエラーが発生しました。\nエラー内容")
|
print("自動停止処理中にエラーが発生しました。\nエラー内容")
|
||||||
print(str(error.__class__.__name__))
|
print(str(error.__class__.__name__))
|
||||||
|
@ -760,8 +766,8 @@ if dislocker.init_result == "ok":
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
bot = Bot(intents=intents)
|
bot = Bot(intents=intents)
|
||||||
monitor = Monitor()
|
monitor = Monitor(search_time=1, allowable_time=300)
|
||||||
monitor.start(search_time=10, allowable_time=300)
|
monitor.start()
|
||||||
bot.run(dislocker.server_config['bot']['token'])
|
bot.run(dislocker.server_config['bot']['token'])
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
Loading…
Reference in a new issue