merge fixes and add gitattributes

This commit is contained in:
Alex 2021-05-23 21:18:09 -04:00
parent cd92da309f
commit 6575172376
6 changed files with 109 additions and 98 deletions

2
.gitattributes vendored Normal file
View File

@ -0,0 +1,2 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

View File

@ -1,5 +1,6 @@
import sqlite3 = require('sqlite3')
import { open, Database } from 'sqlite'
import Discord from 'discord.js'
let db : Database | null = null;
@ -13,4 +14,55 @@ export async function openDb () {
}
return db;
}
export async function testDb(message: Discord.Message, command: string, args: string[]){
switch(command){
case 'save':
if (args.length < 1) {
await message.channel.send('no args');
return;
}
await openDb().then((db) => {
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':
await openDb().then(async (db) => {
let flag: boolean = true;
let outEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Database Dump')
.setURL('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
const res = await db.all('SELECT * FROM saved_data');
for(const rows of res){
console.log(rows['msg_id'], rows['data']);
outEmbed = outEmbed.addField(rows['msg_id'], rows['data'], true);
console.log(outEmbed);
}
console.log(outEmbed);
if (flag) {
if (outEmbed.fields.length == 0) {
await message.channel.send('empty');
} else {
await message.channel.send(outEmbed);
}
} else {
await message.channel.send('error');
}
});
break;
case 'clear':
openDb()
.then((db) => {
return db.run('DELETE FROM saved_data');
})
.then(async () => {
await message.channel.send('cleared');
})
.catch();
break;
}
}
console.log('connected to db')

View File

@ -3,7 +3,7 @@ dotenv.config();
import Discord from 'discord.js';
import _ from 'lodash';
import { openDb } from './components/db';
import { openDb, testDb } from './components/db';
import logger from './logger';
const NOTIF_CHANNEL_ID: string = process.env.NOTIF_CHANNEL_ID || '.';
@ -44,54 +44,11 @@ const handleCommand = async (message: Discord.Message, command: string, args: st
case 'ping':
await message.channel.send('pong');
break;
//dev testing commands
case 'save':
if (args.length < 1) {
await message.channel.send('no args');
return;
}
await openDb().then((db) => {
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':
await openDb().then(async (db) => {
let flag: boolean = true;
let outEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Database Dump')
.setURL('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
const res = await db.all('SELECT * FROM saved_data');
for(const rows of res){
console.log(rows['msg_id'], rows['data']);
outEmbed = outEmbed.addField(rows['msg_id'], rows['data'], true);
console.log(outEmbed);
}
console.log(outEmbed);
if (flag) {
if (outEmbed.fields.length == 0) {
await message.channel.send('empty');
} else {
await message.channel.send(outEmbed);
}
} else {
await message.channel.send('error');
}
});
break;
case 'clear':
openDb()
.then((db) => {
return db.run('DELETE FROM saved_data');
})
.then(async () => {
await message.channel.send('cleared');
})
.catch();
break;
//dev testing
if(process.env.NODE_ENV == "dev"){
testDb(message, command, args);
}
}
};

View File

@ -1,40 +1,40 @@
const winston = require('winston');
require('winston-daily-rotate-file');
const dailyRotateTransport = new winston.transports.DailyRotateFile({
filename: '%DATE%.log',
dirname: 'logs',
zippedArchive: true
});
const dailyRotateErrorTransport = new winston.transports.DailyRotateFile({
filename: 'error-%DATE%.log',
dirname: 'logs',
zippedArchive: true,
level: 'error'
});
const consoleTransport = new winston.transports.Console({
format: winston.format.prettyPrint()
});
const logger = winston.createLogger({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.printf(
({ level, message, timestamp }: { level: string; message: string; timestamp: string }) =>
`[${timestamp}] ${level}: ${JSON.stringify(message)}`
)
),
transports: [dailyRotateTransport, dailyRotateErrorTransport]
});
if (process.env.NODE_ENV === 'dev') {
logger.add(
new winston.transports.Console({
format: winston.format.prettyPrint()
})
);
}
export default logger;
const winston = require('winston');
require('winston-daily-rotate-file');
const dailyRotateTransport = new winston.transports.DailyRotateFile({
filename: '%DATE%.log',
dirname: 'logs',
zippedArchive: true
});
const dailyRotateErrorTransport = new winston.transports.DailyRotateFile({
filename: 'error-%DATE%.log',
dirname: 'logs',
zippedArchive: true,
level: 'error'
});
const consoleTransport = new winston.transports.Console({
format: winston.format.prettyPrint()
});
const logger = winston.createLogger({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.printf(
({ level, message, timestamp }: { level: string; message: string; timestamp: string }) =>
`[${timestamp}] ${level}: ${JSON.stringify(message)}`
)
),
transports: [dailyRotateTransport, dailyRotateErrorTransport]
});
if (process.env.NODE_ENV === 'dev') {
logger.add(
new winston.transports.Console({
format: winston.format.prettyPrint()
})
);
}
export default logger;

View File

@ -13,7 +13,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"@types/sqlite3": "^3.1.7",
"concurrently": "^6.1.0",
"discord.js": "^12.5.3",
"dotenv": "^8.2.0",
@ -26,6 +25,7 @@
"winston-daily-rotate-file": "^4.5.5"
},
"devDependencies": {
"@types/sqlite3": "^3.1.7",
"@tsconfig/node14": "^1.0.0",
"@types/lodash": "^4.14.168",
"@types/node": "^15.0.1",

View File

@ -1,9 +1,9 @@
{
"extends": "@tsconfig/node14/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"preserveConstEnums": true,
"esModuleInterop": true
},
"include": ["**/*.ts"]
}
{
"extends": "@tsconfig/node14/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"preserveConstEnums": true,
"esModuleInterop": true
},
"include": ["**/*.ts"]
}