返り値を修正
This commit is contained in:
parent
0427c021a0
commit
d03d5ec4ef
1 changed files with 14 additions and 7 deletions
21
dislocker.py
21
dislocker.py
|
@ -36,18 +36,21 @@ class Bot(discord.Client):
|
||||||
user_record = cursor.fetchall()
|
user_record = cursor.fetchall()
|
||||||
#ユーザーデータがなかったら(未登録の場合)
|
#ユーザーデータがなかったら(未登録の場合)
|
||||||
if not user_record[0]:
|
if not user_record[0]:
|
||||||
return {"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:
|
||||||
return {"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:
|
||||||
return {"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))
|
||||||
|
@ -58,7 +61,8 @@ class Bot(discord.Client):
|
||||||
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 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))
|
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password_hash, pc_number))
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
return {"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
|
||||||
|
|
||||||
def stop(self, **kwrags):
|
def stop(self, **kwrags):
|
||||||
discord_user_id = str(kwrags["user_id"])
|
discord_user_id = str(kwrags["user_id"])
|
||||||
|
@ -68,23 +72,26 @@ class Bot(discord.Client):
|
||||||
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 not pc_usage_history_record[0][5] == None:
|
if not pc_usage_history_record[0][5] == None:
|
||||||
return {"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()
|
||||||
return {"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
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
print("ログイン成功")
|
print("ログイン成功")
|
||||||
|
|
||||||
async def on_message(self, message):
|
async def on_message(self, message):
|
||||||
if message.author.bot:
|
if message.author.bot:
|
||||||
return
|
pass
|
||||||
|
|
||||||
if isinstance(message.channel, discord.DMChannel):
|
if isinstance(message.channel, discord.DMChannel):
|
||||||
msg_split = message.content.split()
|
msg_split = message.content.split()
|
||||||
|
print(msg_split)
|
||||||
if msg_split[0] == "/password" or "/start":
|
if msg_split[0] == "/password" or "/start":
|
||||||
#メッセージの要素が2つ以下の場合は拒否
|
#メッセージの要素が2つ以下の場合は拒否
|
||||||
if len(msg_split) <= 2:
|
if len(msg_split) <= 2:
|
||||||
|
|
Loading…
Reference in a new issue