Dislocker/dislocker.py

83 lines
2.6 KiB
Python
Raw Normal View History

2024-06-04 09:36:29 +09:00
import json
import discord
import os
2024-06-04 13:26:28 +09:00
import sqlite3
2024-06-04 09:36:29 +09:00
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):
2024-06-04 13:26:28 +09:00
if not os.path.isfile("./db/dislocker.db"):
initial = 1
else:
initial = 0
self.db = sqlite3.connect("./db/dislocker.db")
if initial == 1:
self.initial()
def initial(self):
cursor = self.db.cursor()
initial_sql_web_auth = "CREATE TABLE web_auth (id INTEGER PRIMARY KEY AUTOINCREMENT, username VARCHAR(10) NOT NULL, password VARCHAR(32) NOT NULL);"
cursor.execute(initial_sql_web_auth)
initial_sql_discord_user = "CREATE TABLE discord_user (id INTEGER PRIMARY KEY AUTOINCREMENT, discord_username VARCHAR(32) NOT NULL, discord_userid VARCHAR(18) NOT NULL);"
cursor.execute(initial_sql_discord_user)
initial_sql_insert_web_admin = "INSERT INTO discord_user (username, password) VALUES ('admin', 'admin');"
cursor.execute(initial_sql_insert_web_admin)
self.db.commit()
2024-06-04 09:36:29 +09:00
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"])