dev build
This commit is contained in:
commit
b0262c9a98
57
index.js
Normal file
57
index.js
Normal file
@ -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;
|
||||
}
|
||||
})
|
10
package.json
Normal file
10
package.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"nodemon": "^2.0.18",
|
||||
"sqlite3": "^5.0.8",
|
||||
"v11-discord.js": "^11.5.8"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "nodemon index"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user