無駄なreturnをなくす
This commit is contained in:
parent
d03d5ec4ef
commit
de96b457eb
1 changed files with 16 additions and 10 deletions
20
dislocker.py
20
dislocker.py
|
@ -37,20 +37,17 @@ class Bot(discord.Client):
|
||||||
#ユーザーデータがなかったら(未登録の場合)
|
#ユーザーデータがなかったら(未登録の場合)
|
||||||
if not user_record[0]:
|
if not user_record[0]:
|
||||||
result = {"result": "user_data_not_found"}
|
result = {"result": "user_data_not_found"}
|
||||||
return result
|
|
||||||
#ユーザーデータが見つかった場合(登録済みの場合)
|
#ユーザーデータが見つかった場合(登録済みの場合)
|
||||||
elif user_record[0]:
|
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],))
|
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[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])}
|
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:
|
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,))
|
cursor.execute("SELECT * FROM pc_list WHERE pc_number=%s ORDER BY id DESC LIMIT 1", (pc_number,))
|
||||||
pc_list_record = cursor.fetchall()
|
pc_list_record = cursor.fetchall()
|
||||||
if not pc_list_record[0][1] == None:
|
if not pc_list_record[0][1] == None:
|
||||||
result = {"result": "pc_already_in_use_by_other"}
|
result = {"result": "pc_already_in_use_by_other"}
|
||||||
return result
|
|
||||||
elif pc_list_record[0][1] == None:
|
elif pc_list_record[0][1] == None:
|
||||||
if detail == 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))
|
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))
|
||||||
|
@ -62,6 +59,7 @@ class Bot(discord.Client):
|
||||||
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password_hash, pc_number))
|
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password_hash, pc_number))
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
result = {"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
|
return result
|
||||||
|
|
||||||
def stop(self, **kwrags):
|
def stop(self, **kwrags):
|
||||||
|
@ -73,13 +71,14 @@ class Bot(discord.Client):
|
||||||
pc_usage_history_record = cursor.fetchall()
|
pc_usage_history_record = cursor.fetchall()
|
||||||
if not pc_usage_history_record[0][5] == None:
|
if not pc_usage_history_record[0][5] == None:
|
||||||
result = {"result": "unused"}
|
result = {"result": "unused"}
|
||||||
return result
|
|
||||||
elif pc_usage_history_record[0][5] == None:
|
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_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
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
|
@ -96,15 +95,22 @@ class Bot(discord.Client):
|
||||||
#メッセージの要素が2つ以下の場合は拒否
|
#メッセージの要素が2つ以下の場合は拒否
|
||||||
if len(msg_split) <= 2:
|
if len(msg_split) <= 2:
|
||||||
await message.channel.send("PC番号、もしくはデバイス番号が入力されていません。")
|
await message.channel.send("PC番号、もしくはデバイス番号が入力されていません。")
|
||||||
#メッセージの要素が3つ(コマンド、PC番号、デバイス番号)の場合
|
#メッセージの要素が3つ以上の場合
|
||||||
elif len(msg_split) == 3:
|
elif len(msg_split) >= 3:
|
||||||
#番号が数字であることを確認
|
#番号が数字であることを確認
|
||||||
if msg_split[1].isdigit() and msg_split[2].isdigit():
|
if msg_split[1].isdigit() and msg_split[2].isdigit():
|
||||||
#PC番号が1以上10以下であることを確認
|
#PC番号が1以上10以下であることを確認
|
||||||
if int(msg_split[1]) <= 10 and int(msg_split[1]) >= 1:
|
if int(msg_split[1]) <= 10 and int(msg_split[1]) >= 1:
|
||||||
|
if len(msg_split) == 3:
|
||||||
register = self.register(user_id=message.author.id, pc_number=msg_split[1], device_number=msg_split[2])
|
register = self.register(user_id=message.author.id, pc_number=msg_split[1], device_number=msg_split[2])
|
||||||
|
elif len(msg_split) == 4:
|
||||||
|
register = self.register(user_id=message.author.id, pc_number=msg_split[1], device_number=msg_split[2], detail=msg_split[3])
|
||||||
|
|
||||||
if register["result"] == "ok":
|
if register["result"] == "ok":
|
||||||
await message.channel.send(f"使用が開始されました。\nパスワード | {register["password"]}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n")
|
if len(msg_split) == 3:
|
||||||
|
await message.channel.send(f"使用が開始されました。\nパスワード | {register["password"]}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}")
|
||||||
|
elif len(msg_split) == 4:
|
||||||
|
await message.channel.send(f"使用が開始されました。\nパスワード | {register["password"]}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n使用目的 | {msg_split[3]}")
|
||||||
await self.get_channel(bot_config["log_channel_id"]).send(f'{register["name"]} さんがPC{register["pc_number"]}を使用しています')
|
await self.get_channel(bot_config["log_channel_id"]).send(f'{register["name"]} さんがPC{register["pc_number"]}を使用しています')
|
||||||
elif register["result"] == "user_data_not_found":
|
elif register["result"] == "user_data_not_found":
|
||||||
await message.channel.send("ユーザーとして登録されていないようです。管理者に問い合わせてください。")
|
await message.channel.send("ユーザーとして登録されていないようです。管理者に問い合わせてください。")
|
||||||
|
|
Loading…
Reference in a new issue