added database
This commit is contained in:
parent
66c9560430
commit
7bd99acf36
|
@ -0,0 +1,8 @@
|
||||||
|
import sqlite3 = require('sqlite3')
|
||||||
|
export const db = new sqlite3.Database('./db/bot.db', (err) =>{
|
||||||
|
if(err){
|
||||||
|
console.log(err.message)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
db.run('CREATE TABLE IF NOT EXISTS saved_data (msg_id INTEGER PRIMARY KEY,data TEXT NOT NULL);')
|
||||||
|
console.log('connected to db')
|
18
index.ts
18
index.ts
|
@ -3,6 +3,7 @@ dotenv.config()
|
||||||
|
|
||||||
import Discord = require('discord.js')
|
import Discord = require('discord.js')
|
||||||
import _ = require('lodash')
|
import _ = require('lodash')
|
||||||
|
import { db } from './components/db'
|
||||||
|
|
||||||
const NOTIF_CHANNEL_ID: string = process.env.NOTIF_CHANNEL_ID
|
const NOTIF_CHANNEL_ID: string = process.env.NOTIF_CHANNEL_ID
|
||||||
const BOT_TOKEN: string = process.env.BOT_TOKEN
|
const BOT_TOKEN: string = process.env.BOT_TOKEN
|
||||||
|
@ -30,6 +31,23 @@ const handleCommand = async (message, command, args) => {
|
||||||
switch(command) {
|
switch(command) {
|
||||||
case 'ping':
|
case 'ping':
|
||||||
await message.channel.send('pong')
|
await message.channel.send('pong')
|
||||||
|
break
|
||||||
|
|
||||||
|
//dev testing commands
|
||||||
|
case 'save':
|
||||||
|
if(args.length<1){
|
||||||
|
await message.channel.send('no args')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
db.run('INSERT INTO saved_data (msg_id,data)'+
|
||||||
|
'VALUES(?,?)', message.id, args[0])
|
||||||
|
await message.channel.send('saved "'+args[0]+'" with id '+message.id)
|
||||||
|
break
|
||||||
|
case 'dump':
|
||||||
|
db.each('SELECT * FROM saved_data', async (err, rows) =>{
|
||||||
|
await message.channel.send(JSON.stringify(rows))
|
||||||
|
})
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
"discord.js": "^12.5.3",
|
"discord.js": "^12.5.3",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
"sqlite3": "^5.0.2",
|
||||||
"typescript": "^4.2.4"
|
"typescript": "^4.2.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
Loading…
Reference in New Issue