無駄なreturnをなくす
This commit is contained in:
parent
d03d5ec4ef
commit
de96b457eb
1 changed files with 16 additions and 10 deletions
26
dislocker.py
26
dislocker.py
|
@ -37,20 +37,17 @@ class Bot(discord.Client):
|
|||
#ユーザーデータがなかったら(未登録の場合)
|
||||
if not user_record[0]:
|
||||
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:
|
||||
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:
|
||||
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))
|
||||
|
@ -62,7 +59,8 @@ 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])}
|
||||
return result
|
||||
|
||||
return result
|
||||
|
||||
def stop(self, **kwrags):
|
||||
discord_user_id = str(kwrags["user_id"])
|
||||
|
@ -73,14 +71,15 @@ class Bot(discord.Client):
|
|||
pc_usage_history_record = cursor.fetchall()
|
||||
if not pc_usage_history_record[0][5] == None:
|
||||
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()
|
||||
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):
|
||||
print("ログイン成功")
|
||||
|
@ -96,15 +95,22 @@ class Bot(discord.Client):
|
|||
#メッセージの要素が2つ以下の場合は拒否
|
||||
if len(msg_split) <= 2:
|
||||
await message.channel.send("PC番号、もしくはデバイス番号が入力されていません。")
|
||||
#メッセージの要素が3つ(コマンド、PC番号、デバイス番号)の場合
|
||||
elif len(msg_split) == 3:
|
||||
#メッセージの要素が3つ以上の場合
|
||||
elif len(msg_split) >= 3:
|
||||
#番号が数字であることを確認
|
||||
if msg_split[1].isdigit() and msg_split[2].isdigit():
|
||||
#PC番号が1以上10以下であることを確認
|
||||
if int(msg_split[1]) <= 10 and int(msg_split[1]) >= 1:
|
||||
register = self.register(user_id=message.author.id, pc_number=msg_split[1], device_number=msg_split[2])
|
||||
if len(msg_split) == 3:
|
||||
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":
|
||||
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"]}を使用しています')
|
||||
elif register["result"] == "user_data_not_found":
|
||||
await message.channel.send("ユーザーとして登録されていないようです。管理者に問い合わせてください。")
|
||||
|
|
Loading…
Reference in a new issue