import json import discord import os import sqlite3 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): 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 web_auth (username, password) VALUES ('admin', 'admin');" cursor.execute(initial_sql_insert_web_admin) self.db.commit() def register(self, username, userid): cursor = self.db.cursor() insert_sql = "INSERT INTO user_list (discord_username, discord_userid) VALUES (?, ?);" 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 = ? AND password = ? " 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() 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"])