Compare commits
No commits in common. "f748e48517a6630b2cadc969e86e61fd0ae55b83" and "b01ce7b3738aab207dd3242777a820eef3e52d41" have entirely different histories.
f748e48517
...
b01ce7b373
2 changed files with 7 additions and 54 deletions
58
dislocker.py
58
dislocker.py
|
@ -2,23 +2,12 @@ import json
|
||||||
import discord
|
import discord
|
||||||
import os
|
import os
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import hashlib
|
import datetime
|
||||||
import string
|
|
||||||
import random
|
|
||||||
|
|
||||||
class Bot(discord.Client):
|
class Bot(discord.Client):
|
||||||
def db_connect(self, host, db, port, user, password):
|
def db_connect(self, host, db, port, user, password):
|
||||||
self.db = psycopg2.connect(f"host={host} dbname={db} port={port} user={user} password={password}")
|
self.db = psycopg2.connect(f"host={host} dbname={db} port={port} user={user} password={password}")
|
||||||
|
|
||||||
def password_generate(self, length):
|
|
||||||
numbers = string.digits # (1)
|
|
||||||
password = ''.join(random.choice(numbers) for _ in range(length)) # (2)
|
|
||||||
return str(password)
|
|
||||||
|
|
||||||
def hash_genarate(self, source):
|
|
||||||
hashed = hashlib.md5(source.encode())
|
|
||||||
return hashed.hexdigest()
|
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
print("ログイン成功")
|
print("ログイン成功")
|
||||||
|
|
||||||
|
@ -37,34 +26,17 @@ class Bot(discord.Client):
|
||||||
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():
|
||||||
if int(msg_split[1]) <= 10 and int(msg_split[1]) >= 1:
|
if int(msg_split[1]) <= 10 and int(msg_split[1]) >= 1:
|
||||||
password = self.password_generate(4)
|
|
||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute("SELECT * FROM club_member WHERE discord_userid = %s", (str(message.author.id),))
|
cursor.execute("SELECT * FROM club_member WHERE discord_userid = %s", (str(message.author.id),))
|
||||||
member_info = cursor.fetchall()
|
member_info = cursor.fetchall()
|
||||||
cursor.execute("SELECT * FROM pc_usage_history WHERE member_id=%s ORDER BY id DESC LIMIT 1", (member_info[0][0],))
|
cursor.execute("SELECT * FROM pc_usage_history WHERE member_id=%s ORDER BY id DESC LIMIT 1", (member_info[0][0],))
|
||||||
history_info = cursor.fetchall()
|
history_info = cursor.fetchall()
|
||||||
if len(history_info) == 0:
|
if not history_info[0][5]:
|
||||||
cursor.execute("INSERT INTO pc_usage_history ( member_id, pc_number, device_number, start_use_time ) VALUES ( %s, %s, %s, current_timestamp)", (member_info[0][0], int(msg_split[1]), int(msg_split[2])))
|
|
||||||
self.db.commit()
|
|
||||||
cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (member_info[0][0], msg_split[1]))
|
|
||||||
self.db.commit()
|
|
||||||
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password, msg_split[1]))
|
|
||||||
self.db.commit()
|
|
||||||
|
|
||||||
await message.channel.send(f"使用が開始されました。\nパスワード | {password}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n")
|
|
||||||
await self.get_channel(bot_config["log_channel_id"]).send(f'{member_info[0][2]}がPC{msg_split[1]}を使用しています')
|
|
||||||
|
|
||||||
elif not history_info[0][5]:
|
|
||||||
await message.channel.send(f"もう使用されているようです。解除するには /stop で使用終了をお知らせください。\n使用中のPC番号 | {str(history_info[0][2])}\n使用中のデバイス番号 | {str(history_info[0][3])}\n使用開始時刻 | {str(history_info[0][4])}\n使用目的 | {str(history_info[0][6])}")
|
await message.channel.send(f"もう使用されているようです。解除するには /stop で使用終了をお知らせください。\n使用中のPC番号 | {str(history_info[0][2])}\n使用中のデバイス番号 | {str(history_info[0][3])}\n使用開始時刻 | {str(history_info[0][4])}\n使用目的 | {str(history_info[0][6])}")
|
||||||
else:
|
else:
|
||||||
cursor.execute("INSERT INTO pc_usage_history ( member_id, pc_number, device_number, start_use_time ) VALUES ( %s, %s, %s, current_timestamp)", (member_info[0][0], int(msg_split[1]), int(msg_split[2])))
|
cursor.execute("INSERT INTO pc_usage_history ( member_id, pc_number, device_number, start_use_time ) VALUES ( %s, %s, %s, current_timestamp)", (member_info[0][0], int(msg_split[1]), int(msg_split[2])))
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (member_info[0][0], msg_split[1]))
|
await message.channel.send(f"使用が開始されました。\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n")
|
||||||
self.db.commit()
|
|
||||||
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password, msg_split[1]))
|
|
||||||
self.db.commit()
|
|
||||||
|
|
||||||
await message.channel.send(f"使用が開始されました。\nパスワード | {password}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n")
|
|
||||||
await self.get_channel(bot_config["log_channel_id"]).send(f'{member_info[0][2]}がPC{msg_split[1]}を使用しています')
|
await self.get_channel(bot_config["log_channel_id"]).send(f'{member_info[0][2]}がPC{msg_split[1]}を使用しています')
|
||||||
else:
|
else:
|
||||||
await message.channel.send("パソコンの台数が\n# だめです")
|
await message.channel.send("パソコンの台数が\n# だめです")
|
||||||
|
@ -74,32 +46,17 @@ class Bot(discord.Client):
|
||||||
elif len(msg_split) >= 4:
|
elif len(msg_split) >= 4:
|
||||||
if msg_split[1].isdigit() and msg_split[2].isdigit():
|
if msg_split[1].isdigit() and msg_split[2].isdigit():
|
||||||
if int(msg_split[1]) <= 10 and int(msg_split[1]) >= 1:
|
if int(msg_split[1]) <= 10 and int(msg_split[1]) >= 1:
|
||||||
password = self.password_generate(4)
|
|
||||||
cursor = self.db.cursor()
|
cursor = self.db.cursor()
|
||||||
cursor.execute("SELECT * FROM club_member WHERE discord_userid = %s", (str(message.author.id),))
|
cursor.execute("SELECT * FROM club_member WHERE discord_userid = %s", (str(message.author.id),))
|
||||||
member_info = cursor.fetchall()
|
member_info = cursor.fetchall()
|
||||||
cursor.execute("SELECT * FROM pc_usage_history WHERE member_id=%s ORDER BY id DESC LIMIT 1", (member_info[0][0],))
|
cursor.execute("SELECT * FROM pc_usage_history WHERE member_id=%s ORDER BY id DESC LIMIT 1", (member_info[0][0],))
|
||||||
history_info = cursor.fetchall()
|
history_info = cursor.fetchall()
|
||||||
if len(history_info) == 0:
|
if not history_info[0][5]:
|
||||||
cursor.execute("INSERT INTO pc_usage_history ( member_id, pc_number, device_number, start_use_time ) VALUES ( %s, %s, %s, current_timestamp)", (member_info[0][0], int(msg_split[1]), int(msg_split[2])))
|
|
||||||
self.db.commit()
|
|
||||||
cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (member_info[0][0], msg_split[1]))
|
|
||||||
self.db.commit()
|
|
||||||
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password, msg_split[1]))
|
|
||||||
self.db.commit()
|
|
||||||
|
|
||||||
await message.channel.send(f"使用が開始されました。\nパスワード | {password}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n")
|
|
||||||
await self.get_channel(bot_config["log_channel_id"]).send(f'{member_info[0][2]}がPC{msg_split[1]}を使用しています')
|
|
||||||
elif not history_info[0][5]:
|
|
||||||
await message.channel.send(f"もう使用されているようです。解除するには /stop で使用終了をお知らせください。\n使用中のPC番号 | {str(history_info[0][2])}\n使用中のデバイス番号 | {str(history_info[0][3])}\n使用開始時刻 | {str(history_info[0][4])}\n使用目的 | {str(history_info[0][6])}")
|
await message.channel.send(f"もう使用されているようです。解除するには /stop で使用終了をお知らせください。\n使用中のPC番号 | {str(history_info[0][2])}\n使用中のデバイス番号 | {str(history_info[0][3])}\n使用開始時刻 | {str(history_info[0][4])}\n使用目的 | {str(history_info[0][6])}")
|
||||||
else:
|
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)", (member_info[0][0], int(msg_split[1]), int(msg_split[2]), str(msg_split[3])))
|
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)", (member_info[0][0], int(msg_split[1]), int(msg_split[2]), str(msg_split[3])))
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (member_info[0][0], msg_split[1]))
|
await message.channel.send(f"使用が開始されました。\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n")
|
||||||
self.db.commit()
|
|
||||||
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password, msg_split[1]))
|
|
||||||
self.db.commit()
|
|
||||||
await message.channel.send(f"使用が開始されました。\nパスワード | {password}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n")
|
|
||||||
await self.get_channel(bot_config["log_channel_id"]).send(f'{member_info[0][2]}がPC{msg_split[1]}を使用しています')
|
await self.get_channel(bot_config["log_channel_id"]).send(f'{member_info[0][2]}がPC{msg_split[1]}を使用しています')
|
||||||
else:
|
else:
|
||||||
await message.channel.send("パソコンの台数が\n# だめです")
|
await message.channel.send("パソコンの台数が\n# だめです")
|
||||||
|
@ -118,10 +75,6 @@ class Bot(discord.Client):
|
||||||
else:
|
else:
|
||||||
cursor.execute("UPDATE pc_usage_history SET end_use_time = current_timestamp WHERE id = %s", (history_info[0][0],))
|
cursor.execute("UPDATE pc_usage_history SET end_use_time = current_timestamp WHERE id = %s", (history_info[0][0],))
|
||||||
self.db.commit()
|
self.db.commit()
|
||||||
cursor.execute("UPDATE pc_list SET using_user_id = NULL WHERE pc_number = %s", (history_info[0][2],))
|
|
||||||
self.db.commit()
|
|
||||||
cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (history_info[0][2],))
|
|
||||||
self.db.commit()
|
|
||||||
await message.channel.send(f"使用が終了されました。")
|
await message.channel.send(f"使用が終了されました。")
|
||||||
await self.get_channel(bot_config["log_channel_id"]).send(f'{member_info[0][2]}がPC{history_info[0][2]}の使用を終了しました')
|
await self.get_channel(bot_config["log_channel_id"]).send(f'{member_info[0][2]}がPC{history_info[0][2]}の使用を終了しました')
|
||||||
|
|
||||||
|
@ -133,6 +86,7 @@ class Bot(discord.Client):
|
||||||
else:
|
else:
|
||||||
await message.channel.send("どうしましたか?")
|
await message.channel.send("どうしましたか?")
|
||||||
|
|
||||||
|
#cert = Cert()
|
||||||
|
|
||||||
config_dir_path = "./config/"
|
config_dir_path = "./config/"
|
||||||
db_config_path = config_dir_path + "db.json"
|
db_config_path = config_dir_path + "db.json"
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
psql -U suti7 -d dislocker
|
psql -U suti7 -d dislocker
|
||||||
|
|
||||||
CREATE TABLE club_member (id SERIAL NOT NULL, name VARCHAR(30) NOT NULL, discord_username VARCHAR(32) NOT NULL, discord_userid VARCHAR(18) NOT NULL, PRIMARY KEY (id));
|
CREATE TABLE club_member (id SERIAL NOT NULL, name VARCHAR(30) NOT NULL, discord_username VARCHAR(32) NOT NULL, discord_userid VARCHAR(18) NOT NULL, PRIMARY KEY (id));
|
||||||
CREATE TABLE pc_list (pc_number INTEGER NOT NULL, using_user_id INTEGER, password_hash VARCHAR(32), PRIMARY KEY (pc_number), FOREIGN KEY (using_user_id) REFERENCES club_member(id));
|
CREATE TABLE pc_usage_history (id SERIAL NOT NULL, member_id INTEGER NOT NULL, pc_number INTEGER NOT NULL, device_number INTEGER NOT NULL, start_use_time TIMESTAMP NOT NULL, end_use_time TIMESTAMP, use_detail VARCHAR(30), PRIMARY KEY (id), FOREIGN KEY (member_id) REFERENCES club_member(id));
|
||||||
CREATE TABLE pc_usage_history (id SERIAL NOT NULL, member_id INTEGER NOT NULL, pc_number INTEGER NOT NULL, device_number INTEGER NOT NULL, start_use_time TIMESTAMP NOT NULL, end_use_time TIMESTAMP, use_detail VARCHAR(30), PRIMARY KEY (id), FOREIGN KEY (member_id) REFERENCES club_member(id), FOREIGN KEY (pc_number) REFERENCES pc_list(pc_number));
|
|
||||||
|
|
||||||
INSERTのとき文字列はシングルクォーテーションで囲む!!!
|
INSERTのとき文字列はシングルクォーテーションで囲む!!!
|
Loading…
Reference in a new issue