merge fixes and add gitattributes
This commit is contained in:
parent
cd92da309f
commit
6575172376
|
@ -0,0 +1,2 @@
|
||||||
|
# Set the default behavior, in case people don't have core.autocrlf set.
|
||||||
|
* text=auto
|
|
@ -1,5 +1,6 @@
|
||||||
import sqlite3 = require('sqlite3')
|
import sqlite3 = require('sqlite3')
|
||||||
import { open, Database } from 'sqlite'
|
import { open, Database } from 'sqlite'
|
||||||
|
import Discord from 'discord.js'
|
||||||
|
|
||||||
let db : Database | null = null;
|
let db : Database | null = null;
|
||||||
|
|
||||||
|
@ -13,4 +14,55 @@ export async function openDb () {
|
||||||
}
|
}
|
||||||
return db;
|
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')
|
console.log('connected to db')
|
||||||
|
|
53
index.ts
53
index.ts
|
@ -3,7 +3,7 @@ dotenv.config();
|
||||||
|
|
||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { openDb } from './components/db';
|
import { openDb, testDb } from './components/db';
|
||||||
import logger from './logger';
|
import logger from './logger';
|
||||||
|
|
||||||
const NOTIF_CHANNEL_ID: string = process.env.NOTIF_CHANNEL_ID || '.';
|
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':
|
case 'ping':
|
||||||
await message.channel.send('pong');
|
await message.channel.send('pong');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
//dev testing commands
|
//dev testing
|
||||||
case 'save':
|
if(process.env.NODE_ENV == "dev"){
|
||||||
if (args.length < 1) {
|
testDb(message, command, args);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
80
logger.ts
80
logger.ts
|
@ -1,40 +1,40 @@
|
||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
require('winston-daily-rotate-file');
|
require('winston-daily-rotate-file');
|
||||||
|
|
||||||
const dailyRotateTransport = new winston.transports.DailyRotateFile({
|
const dailyRotateTransport = new winston.transports.DailyRotateFile({
|
||||||
filename: '%DATE%.log',
|
filename: '%DATE%.log',
|
||||||
dirname: 'logs',
|
dirname: 'logs',
|
||||||
zippedArchive: true
|
zippedArchive: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const dailyRotateErrorTransport = new winston.transports.DailyRotateFile({
|
const dailyRotateErrorTransport = new winston.transports.DailyRotateFile({
|
||||||
filename: 'error-%DATE%.log',
|
filename: 'error-%DATE%.log',
|
||||||
dirname: 'logs',
|
dirname: 'logs',
|
||||||
zippedArchive: true,
|
zippedArchive: true,
|
||||||
level: 'error'
|
level: 'error'
|
||||||
});
|
});
|
||||||
|
|
||||||
const consoleTransport = new winston.transports.Console({
|
const consoleTransport = new winston.transports.Console({
|
||||||
format: winston.format.prettyPrint()
|
format: winston.format.prettyPrint()
|
||||||
});
|
});
|
||||||
|
|
||||||
const logger = winston.createLogger({
|
const logger = winston.createLogger({
|
||||||
format: winston.format.combine(
|
format: winston.format.combine(
|
||||||
winston.format.timestamp(),
|
winston.format.timestamp(),
|
||||||
winston.format.printf(
|
winston.format.printf(
|
||||||
({ level, message, timestamp }: { level: string; message: string; timestamp: string }) =>
|
({ level, message, timestamp }: { level: string; message: string; timestamp: string }) =>
|
||||||
`[${timestamp}] ${level}: ${JSON.stringify(message)}`
|
`[${timestamp}] ${level}: ${JSON.stringify(message)}`
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
transports: [dailyRotateTransport, dailyRotateErrorTransport]
|
transports: [dailyRotateTransport, dailyRotateErrorTransport]
|
||||||
});
|
});
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'dev') {
|
if (process.env.NODE_ENV === 'dev') {
|
||||||
logger.add(
|
logger.add(
|
||||||
new winston.transports.Console({
|
new winston.transports.Console({
|
||||||
format: winston.format.prettyPrint()
|
format: winston.format.prettyPrint()
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default logger;
|
export default logger;
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/sqlite3": "^3.1.7",
|
|
||||||
"concurrently": "^6.1.0",
|
"concurrently": "^6.1.0",
|
||||||
"discord.js": "^12.5.3",
|
"discord.js": "^12.5.3",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
|
@ -26,6 +25,7 @@
|
||||||
"winston-daily-rotate-file": "^4.5.5"
|
"winston-daily-rotate-file": "^4.5.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/sqlite3": "^3.1.7",
|
||||||
"@tsconfig/node14": "^1.0.0",
|
"@tsconfig/node14": "^1.0.0",
|
||||||
"@types/lodash": "^4.14.168",
|
"@types/lodash": "^4.14.168",
|
||||||
"@types/node": "^15.0.1",
|
"@types/node": "^15.0.1",
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"extends": "@tsconfig/node14/tsconfig.json",
|
"extends": "@tsconfig/node14/tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "dist",
|
"outDir": "dist",
|
||||||
"preserveConstEnums": true,
|
"preserveConstEnums": true,
|
||||||
"esModuleInterop": true
|
"esModuleInterop": true
|
||||||
},
|
},
|
||||||
"include": ["**/*.ts"]
|
"include": ["**/*.ts"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue