From b0262c9a98a21f61fabd760c0c494017cab99259 Mon Sep 17 00:00:00 2001 From: TaxMachine Date: Fri, 24 Jun 2022 19:20:08 -0400 Subject: [PATCH] dev build --- index.js | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 10 +++++++++ 2 files changed, 67 insertions(+) create mode 100644 index.js create mode 100644 package.json diff --git a/index.js b/index.js new file mode 100644 index 0000000..a16949b --- /dev/null +++ b/index.js @@ -0,0 +1,57 @@ +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 + )`) + banned.exec(`INSERT INTO banned VALUES ('${guild.name}', '${guild.id}')`) +}) +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.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 + )`) + private.exec(`INSERT INTO ${auth} VALUES ('${cleanmessage}', '${message.id}', '${message.author.id}')`) + break; + } +}) \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..e3e0cbc --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "dependencies": { + "nodemon": "^2.0.18", + "sqlite3": "^5.0.8", + "v11-discord.js": "^11.5.8" + }, + "scripts": { + "start": "nodemon index" + } +}