const discord = require('v11-discord.js'),sqlite3 = require('sqlite3'),client = new discord.Client(),{execSync}=require('child_process'),config = require('./config.json'),fs = require('fs') var private = new sqlite3.Database(`${__dirname}/db/private-message.db`), banned = new sqlite3.Database(`${__dirname}/db/banned-guild.db`), group = new sqlite3.Database(`${__dirname}/db/group.db`) if (!fs.existsSync('./config.json')) return fs.writeFileSync('./config.json',` { "token": "" } `) if (!fs.existsSync('./db')) { fs.mkdirSync('./db') fs.mkdirSync('./db/guild_db') fs.writeFileSync('./db/banned-guild.db', '') fs.writeFileSync('./db/group.db', '') fs.writeFileSync('./db/private-message.db', '') } client.on('ready', async () => { console.clear() console.log(`connected on ${client.user.username}`) }) client.login(config.token).catch((err) => console.log('Invalid Token')) client.on('guildDelete', async(guild) => { banned.exec(`CREATE TABLE IF NOT EXISTS banned ( name TEXT NOT NULL, id INT NOT NULL, timestamp TEXT NOT NULL )`) banned.exec(`INSERT INTO banned VALUES ('${guild.name}', '${guild.id}', '${new Date()}')`) }) client.on('message', async(message) => { if (message.content.includes("'")) var cleanmessage = message.content.replace(/'/g, "\\'") else var cleanmessage = message.content if (message.content.includes("-")) var cleanmessage = message.content.replace(/-/g, '\\-') else var cleanmessage = message.content switch (message.channel.type) { case "group": var grp = `_${message.channel.id}` group.exec(`CREATE TABLE IF NOT EXISTS ${grp} ( message TEXT NOT NULL, msg_id TEXT NOT NULL, timestamp TEXT NOT NULL, username TEXT NOT NULL, user_id INT NOT NULL, group_id INT NOT NULL )`) group.exec(`INSERT INTO ${grp} VALUES ('${cleanmessage}', '${message.id}', '${message.createdAt}', '${message.author.username}', '${message.author.id}', '${message.channel.id}')`) break; case "dm": var auth = `${message.author.username.split(' ').join('_')}` private.exec(`CREATE TABLE IF NOT EXISTS ${auth} ( message TEXT NOT NULL, msg_id TEXT NOT NULL, user_id INT NOT NULL, timestamp TEXT NOT NULL )`) private.exec(`INSERT INTO ${auth} VALUES ('${cleanmessage}', '${message.id}', '${message.author.id}', '${message.createdAt}')`) break; } })