84 lines
No EOL
2.5 KiB
Python
84 lines
No EOL
2.5 KiB
Python
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 isinstance(message.channel, discord.DMChannel):
|
|
await message.channel.send("DMを確認")
|
|
|
|
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
|
|
|
|
#cert = Cert()
|
|
|
|
config_dir_path = "./confg/"
|
|
db_config_path = config_dir_path + "db.json"
|
|
if not os.path.isfile(db_config_path):
|
|
if not os.path.isdir(config_dir_path):
|
|
os.mkdir(config_dir_path)
|
|
|
|
db_config = {
|
|
"host": "localhost",
|
|
"db": "dislocker",
|
|
"username": "user",
|
|
"password": "example_pass"
|
|
}
|
|
with open(db_config_path, "w") as w:
|
|
json.dump(db_config, w, indent=4)
|
|
elif os.path.isfile(db_config_path):
|
|
with open(db_config_path, "r") as r:
|
|
db_config = json.load(r)
|
|
|
|
bot_config_path = config_dir_path + "bot.json"
|
|
if not os.path.isfile(bot_config_path):
|
|
if not os.path.isdir(config_dir_path):
|
|
os.mkdir(config_dir_path)
|
|
|
|
bot_config = {
|
|
"token": "TYPE HERE BOTS TOKEN KEY"
|
|
}
|
|
with open(bot_config_path, "w") as w:
|
|
json.dump(bot_config, w, indent=4)
|
|
|
|
elif os.path.isfile(bot_config_path):
|
|
with open(bot_config_path, "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"]) |