Commit af589602 authored by insert's avatar insert

Added database + notes system as example.

parent 005e0606
token.json
node_modules
\ No newline at end of file
node_modules
database/data/
\ No newline at end of file
const db = needs('database');
module.exports = (msg, args) => {
if (args.length < 1) {
db.get(msg.author.id, "note").then(note => {
msg.channel.send("```\n" + note + "\n```");
}).catch(e => {
msg.reply("You don't have any note! Do `;note <note>` to set it.");
});
return;
}
db.put(msg.author.id, "note", args.join(' ')).then(() => {
msg.reply("Successfully set your note!");
}).catch(e => {
msg.reply("Oops! An error occurred! " + e);
});
};
\ No newline at end of file
const fs = require('fs');
const path = require('path');
const levelup = require('levelup');
const leveldown = require('leveldown');
if (!fs.existsSync('./database/data')) fs.mkdirSync('./database/data');
module.exports = {
put: (id, key, value) => {
return new Promise((resolve, reject) => {
let db = levelup(leveldown(path.resolve('./database/data/' + id)))
db.put(key, value).then(resolve).catch(reject);
db.close();
});
},
get: (id, key) => {
return new Promise((resolve, reject) => {
let db = levelup(leveldown(path.resolve('./database/data/' + id)))
db.get(key).then(resolve).catch(reject);
db.close();
});
},
del: (id, key) => {
return new Promise((resolve, reject) => {
let db = levelup(leveldown(path.resolve('./database/data/' + id)))
db.del(key).then(resolve).catch(reject);
db.close();
});
}
};
\ No newline at end of file
const discord = require('discord.js');
const chalk = require('chalk');
const client = new discord.Client();
const database = require('./database');
const services = require('./services');
const libs = require('./libs');
const fs = require('fs');
......@@ -18,7 +19,7 @@ console.log(chalk`
`.replace(/#/g, chalk.bgMagenta(' ')));
global.components = {discord, client, services, libs};
global.components = {discord, client, database, services, libs};
global.needs = (component) => {
if (Object.keys(components).indexOf(component) < 0) throw new Error('Not a valid component!');
return components[component];
......
This diff is collapsed.
......@@ -20,6 +20,8 @@
"dependencies": {
"chalk": "^2.4.1",
"discord.js": "^11.3.2",
"leveldown": "^4.0.1",
"levelup": "^3.1.0",
"node-opus": "^0.3.0",
"request": "^2.87.0"
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment