データベースをSQLiteに変更

This commit is contained in:
suti7yk5032 2024-06-04 13:26:28 +09:00
parent b57b1f8b5c
commit 6d4717e471

View file

@ -1,7 +1,7 @@
import json import json
import discord import discord
import os import os
import psycopg2 import sqlite3
class Bot(discord.Client): class Bot(discord.Client):
async def on_ready(self): async def on_ready(self):
@ -20,8 +20,24 @@ class Bot(discord.Client):
class Cert(): class Cert():
def __init__(self): def __init__(self):
self.db = psycopg2.connect("host=localhost dbname=dislocker user=suti7 password=testing") 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()
def register(self, username, userid): def register(self, username, userid):
cursor = self.db.cursor() cursor = self.db.cursor()
insert_sql = "INSERT INTO user_list (discord_username, discord_userid) VALUES (%s, %s);" insert_sql = "INSERT INTO user_list (discord_username, discord_userid) VALUES (%s, %s);"