added database

This commit is contained in:
alex 2021-05-18 23:57:43 -04:00
parent 66c9560430
commit 7bd99acf36
5 changed files with 696 additions and 10 deletions

8
components/db.ts Normal file
View File

@ -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')

BIN
db/bot.db Normal file

Binary file not shown.

View File

@ -3,6 +3,7 @@ dotenv.config()
import Discord = require('discord.js')
import _ = require('lodash')
import { db } from './components/db'
const NOTIF_CHANNEL_ID: string = process.env.NOTIF_CHANNEL_ID
const BOT_TOKEN: string = process.env.BOT_TOKEN
@ -30,6 +31,23 @@ const handleCommand = async (message, command, args) => {
switch(command) {
case 'ping':
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;
}
}

View File

@ -13,6 +13,7 @@
"discord.js": "^12.5.3",
"dotenv": "^8.2.0",
"lodash": "^4.17.21",
"sqlite3": "^5.0.2",
"typescript": "^4.2.4"
},
"devDependencies": {

679
yarn.lock

File diff suppressed because it is too large Load Diff