diff --git a/.gitignore b/.gitignore index 5d381cc..8165e1f 100644 --- a/.gitignore +++ b/.gitignore @@ -160,3 +160,4 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +config diff --git a/dislocker.py b/dislocker.py new file mode 100644 index 0000000..01595be --- /dev/null +++ b/dislocker.py @@ -0,0 +1,67 @@ +import json +import discord +import os +import psycopg2 + +class Bot(discord.Client): + async def on_ready(self): + print("ログイン成功") + + async def on_message(self, message): + if message.author.bot: + return + + if message.content == "/hello": + await message.channel.send("こんにちは!!!!") + + if message.content == "/password": + await message.channel.send("gjhioragiopwjhgiopweap") + + +class Cert(): + def __init__(self): + self.db = psycopg2.connect("host=localhost dbname=dislocker user=suti7 password=testing") + + def register(self, username, userid): + cursor = self.db.cursor() + insert_sql = "INSERT INTO user_list (discord_username, discord_userid) VALUES (%s, %s);" + cursor.execute(insert_sql, (username, userid)) + self.db.commit() + + def get_username(self, username, password): + cursor = self.db.cursor() + get_sql = "SELECT * FROM web_auth WHERE username = %s AND password = %s " + cursor.execute(get_sql, (username, password)) + result = cursor.fetchall() + print(result) + if result == []: + return 1 + elif result[0][1] == username and result[0][2] == password: + return 0 + +class Web(flask.Flask): + async def temp(self): + print("") + + +cert = Cert() +print(cert.get_username("suti7", "0126")) + + +bot_config_path = "./config/bot.json" +if not os.path.isfile(bot_config_path): + bot_config = { + "token": "" + } + with open(bot_config_path, "w") as w: + json.dump(bot_config, w, indent=4) + +elif os.path.isfile(bot_config_path): + with open("./config/bot.json", "r") as r: + bot_config = json.load(r) + +intents = discord.Intents.default() +intents.message_content = True + +bot = Bot(intents=intents) +bot.run(bot_config["token"]) \ No newline at end of file diff --git a/docs/データベースセットアップ.txt b/docs/データベースセットアップ.txt new file mode 100644 index 0000000..d719e70 --- /dev/null +++ b/docs/データベースセットアップ.txt @@ -0,0 +1,13 @@ +# ログイン +psql -U suti7 -d dislocker + +CREATE TABLE user +(user_id INTEGER PRIMARY KEY NOT NULL, +discord_id INTEGER NOT NULL, +discord_username VARCHAR(32) NOT NULL, +PRIMARY KEY (user_id)); + +CREATE TABLE user_list (user_id INTEGER NOT NULL, discord_username VARCHAR(32) NOT NULL, discord_userid INTEGER NOT NULL, PRIMARY KEY (user_id)); + +# テーブルを作る +CREATE TABLE web_auth (id SERIAL, username VARCHAR(10) NOT NULL, password VARCHAR(32) NOT NULL, PRIMARY KEY(id)); \ No newline at end of file diff --git a/resource/console.js b/resource/console.js new file mode 100644 index 0000000..53d9dca --- /dev/null +++ b/resource/console.js @@ -0,0 +1,9 @@ +const send_button = document.querySelector("#send_button"); +const success_alert = document.querySelector("#alert_success"); + +const main = function(){ + send_button.addEventListener("click", function(){ + success_alert. + + }) +} \ No newline at end of file diff --git a/resource/damedesu.webp b/resource/damedesu.webp new file mode 100644 index 0000000..adb5b02 Binary files /dev/null and b/resource/damedesu.webp differ diff --git a/templates/dacs.html b/templates/dacs.html new file mode 100644 index 0000000..859f89c --- /dev/null +++ b/templates/dacs.html @@ -0,0 +1,45 @@ + + + 管理コンソール + + + + +
+
+
+
+
+
+

登録

+
+
+
+
+
+
+
+ +

+ +
+
+ +

+ +
+
+

+ +
+
+ +

+ +
+ + + + + + \ No newline at end of file diff --git a/templates/damedesu.html b/templates/damedesu.html new file mode 100644 index 0000000..58e1c5d --- /dev/null +++ b/templates/damedesu.html @@ -0,0 +1,9 @@ + + + + だめです いいえ 帰ってください + + + + + diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..f694639 --- /dev/null +++ b/templates/login.html @@ -0,0 +1,15 @@ + + + + Login + + +
+ + + + + +
+ + diff --git a/test.py b/test.py new file mode 100644 index 0000000..594a38d --- /dev/null +++ b/test.py @@ -0,0 +1,34 @@ +# インストールした discord.py を読み込む +import discord +import secrets +import string + + +# 接続に必要なオブジェクトを生成 +client = discord.Client() + +# 起動時に動作する処理 +@client.event +async def on_ready(): + # 起動したらターミナルにログイン通知が表示される + print('ログインしました') + +# メッセージ受信時に動作する処理 +@client.event +async def on_message(message): + # メッセージ送信者がBotだった場合は無視する + if message.author.bot: + return + # 「/neko」と発言したら「にゃーん」が返る処理 + if message.content == '/neko': + await message.channel.send('にゃーん') + + if message.content == '/password': + await message.channel.send(get_random_password_string(4)) +def get_random_password_string(length): + pass_chars = string.ascii_letters + string.digits + password = ''.join(secrets.choice(pass_chars) for x in range(length)) + return password + +# Botの起動とDiscordサーバーへの接続 +client.run('MTI0NzA1Mzc1NzUxOTM2NDEyNw.Gh5gIt.kz1acBMxphff9mEZLLWrEdEoVD4RJwgBW5P14o') diff --git a/webui.py b/webui.py new file mode 100644 index 0000000..db12a9d --- /dev/null +++ b/webui.py @@ -0,0 +1,89 @@ +from flask import Flask, request, render_template, redirect, url_for +from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user +import psycopg2 + +app = Flask(__name__, static_folder="./resource/") +app.secret_key = 'your_secret_key' +login_manager = LoginManager() +login_manager.init_app(app) + +class Cert(): + def __init__(self): + self.db = psycopg2.connect("host=localhost dbname=dislocker user=suti7 password=testing") + + def register(self, username, userid): + cursor = self.db.cursor() + insert_sql = "INSERT INTO user_list (discord_username, discord_userid) VALUES (%s, %s);" + cursor.execute(insert_sql, (username, userid)) + self.db.commit() + + def login(self, username, password): + cursor = self.db.cursor() + get_sql = "SELECT * FROM web_auth WHERE username = %s AND password = %s " + cursor.execute(get_sql, (username, password)) + result = cursor.fetchall() + print(result) + if result == []: + return 1 + elif result[0][1] == username and result[0][2] == password: + return 0 + +cert = Cert() + +class User(UserMixin): + def __init__(self, id): + self.id = id + + def get_id(self): + return self.id + +@login_manager.user_loader +def load_user(user_id): + return User(user_id) + +@app.route('/login', methods=['GET', 'POST']) +def login(): + if request.method == 'POST': + user_id = request.form.get('user_id') + password = request.form.get('password') + + # ユーザーIDとパスワードの検証を行う + # ここでは省略しますが、実際にはデータベースなどからユーザー情報を取得し、パスワードを検証します + if cert.login(user_id, password) == 0: + user = User(user_id) + login_user(user) + return redirect(url_for('dacs')) + else: + print("WEB UI LOGIN ERROR") + return redirect(url_for("damedesu")) + + return render_template('login.html') + +@app.route('/logout') +@login_required +def logout(): + logout_user() + return redirect(url_for('login')) + +@app.route('/dacs', methods=["GET", "POST"]) +@login_required +def dacs(): + if request.method == "POST": + discord_userid = request.form.get("discord_userid") + discord_username = request.form.get("discord_username") + + cert.register(discord_username, discord_userid) + + return render_template("dacs.html") + +@app.route("/damedesu") +def damedesu(): + return render_template("damedesu.html") + + +@app.route("/") +def hello_world(): + return "

Hello world!

" + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=5000, debug=True) \ No newline at end of file