Initial work
This commit is contained in:
parent
6e298c9552
commit
19c4e1df3f
11 changed files with 443 additions and 0 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -102,3 +102,9 @@ dist
|
|||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# VylBot-Core Testing Files
|
||||
commands/
|
||||
events/
|
||||
bot.js
|
||||
config.json
|
107
package-lock.json
generated
Normal file
107
package-lock.json
generated
Normal file
|
@ -0,0 +1,107 @@
|
|||
{
|
||||
"name": "vylbot-core",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@discordjs/collection": {
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz",
|
||||
"integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ=="
|
||||
},
|
||||
"@discordjs/form-data": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz",
|
||||
"integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==",
|
||||
"requires": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
}
|
||||
},
|
||||
"abort-controller": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
|
||||
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
|
||||
"requires": {
|
||||
"event-target-shim": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"requires": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
|
||||
},
|
||||
"discord.js": {
|
||||
"version": "12.3.1",
|
||||
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.3.1.tgz",
|
||||
"integrity": "sha512-mSFyV/mbvzH12UXdS4zadmeUf8IMQOo/YdunubG1wWt1xjWvtaJz/s9CGsFD2B5pTw1W/LXxxUbrQjIZ/xlUdw==",
|
||||
"requires": {
|
||||
"@discordjs/collection": "^0.1.6",
|
||||
"@discordjs/form-data": "^3.0.1",
|
||||
"abort-controller": "^3.0.0",
|
||||
"node-fetch": "^2.6.0",
|
||||
"prism-media": "^1.2.2",
|
||||
"setimmediate": "^1.0.5",
|
||||
"tweetnacl": "^1.0.3",
|
||||
"ws": "^7.3.1"
|
||||
}
|
||||
},
|
||||
"event-target-shim": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
|
||||
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ=="
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.44.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz",
|
||||
"integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg=="
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.27",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz",
|
||||
"integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==",
|
||||
"requires": {
|
||||
"mime-db": "1.44.0"
|
||||
}
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
||||
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
|
||||
},
|
||||
"prism-media": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.2.tgz",
|
||||
"integrity": "sha512-I+nkWY212lJ500jLe4tN9tWO7nRiBAVdMv76P9kffZjYhw20raMlW1HSSvS+MLXC9MmbNZCazMrAr+5jEEgTuw=="
|
||||
},
|
||||
"setimmediate": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
|
||||
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
|
||||
},
|
||||
"tweetnacl": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
|
||||
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="
|
||||
},
|
||||
"ws": {
|
||||
"version": "7.3.1",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.3.1.tgz",
|
||||
"integrity": "sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA=="
|
||||
}
|
||||
}
|
||||
}
|
14
package.json
Normal file
14
package.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "vylbot-core",
|
||||
"version": "1.0.0",
|
||||
"description": "A discord client based upon discord.js",
|
||||
"main": "./src/index",
|
||||
"scripts": {
|
||||
"test": "echo \"No Tests Specified\""
|
||||
},
|
||||
"author": "Vylpes",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"discord.js": "^12.3.1"
|
||||
}
|
||||
}
|
46
src/client/client.js
Normal file
46
src/client/client.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
const { Client } = require('discord.js');
|
||||
const { existsSync } = require('fs');
|
||||
|
||||
const events = require('./events');
|
||||
const util = require('./util');
|
||||
|
||||
class client extends Client {
|
||||
constructor(config) {
|
||||
super();
|
||||
this.config = config;
|
||||
this.events = new events();
|
||||
this.util = new util(this);
|
||||
}
|
||||
|
||||
start() {
|
||||
super.on("message", this.events.message);
|
||||
super.on("ready", this.events.ready);
|
||||
super.login(this._config.token);
|
||||
|
||||
this.util.loadEvents();
|
||||
}
|
||||
|
||||
// Config
|
||||
get config() {
|
||||
return this._config;
|
||||
}
|
||||
|
||||
set config(config) {
|
||||
// Validate the config
|
||||
if (this._config) throw "Config has already been set";
|
||||
if (typeof config != "object") throw "Config is not a JSON object";
|
||||
|
||||
if (typeof config.token != "string") throw "Token is not a string";
|
||||
if (typeof config.prefix != "string") throw "Prefix is not a string";
|
||||
|
||||
if (typeof config.commands != "string") throw "Commands is not a string";
|
||||
if (!existsSync(`${process.cwd()}/${config.commands}`)) throw "Commands folder doesn't exist";
|
||||
|
||||
if (typeof config.events != "string") throw "Events is not a string";
|
||||
if (!existsSync(`${process.cwd()}/${config.events}`)) throw "Events folder doesn't exist";
|
||||
|
||||
this._config = config;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = client;
|
21
src/client/events.js
Normal file
21
src/client/events.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
class event {
|
||||
message(message) {
|
||||
if (!message.guild) return;
|
||||
if (message.author.bot) return;
|
||||
|
||||
let prefix = this.config.prefix;
|
||||
|
||||
if (message.content.substring(0, prefix.length).toLowerCase() == prefix.toLowerCase()) {
|
||||
let args = message.content.substring(prefix.length).split(" ");
|
||||
let name = args.shift();
|
||||
|
||||
this.util.loadCommand(name, args, message);
|
||||
}
|
||||
}
|
||||
|
||||
ready() {
|
||||
console.log("Ready");
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = event;
|
58
src/client/util.js
Normal file
58
src/client/util.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
const { stat, readdirSync } = require('fs');
|
||||
const { config } = require('process');
|
||||
|
||||
class util {
|
||||
constructor(client) {
|
||||
this._client = client;
|
||||
}
|
||||
|
||||
loadCommand(name, args, message) {
|
||||
stat(`${process.cwd()}/${this._client.config.commands}/${name}.js`, (err, stat) => {
|
||||
if (err == null) {
|
||||
let commandFile = require(`${process.cwd()}/${this._client.config.commands}/${name}.js`);
|
||||
let command = new commandFile();
|
||||
|
||||
let requiredConfigs = command.requiredConfigs;
|
||||
|
||||
for (let i = 0; i < requiredConfigs.length; i++) {
|
||||
if (!this._client.config[name]) throw `${commandFile.name} requires ${requiredConfigs[i]} in it's configuration`;
|
||||
if (!this._client.config[name][requiredConfigs[i]]) throw `${commandFile.name} requires ${requiredConfigs[i]} in it's configuration`;
|
||||
}
|
||||
|
||||
let requiredRoles = command.roles;
|
||||
|
||||
for (let i = 0; i < requiredRoles.length; i++) {
|
||||
if (!message.member.roles.cache.find(role => role.name == requiredRoles[i])) {
|
||||
message.reply(`You require the \`${requiredRoles[i]}\` role to run this command`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
command[command.run]({
|
||||
"command": name,
|
||||
"arguments": args,
|
||||
"client": this._client,
|
||||
"message": message,
|
||||
"config": config
|
||||
});
|
||||
} else if (err.code === 'ENOENT') {
|
||||
// FILE DOESN'T EXIST
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
loadEvents() {
|
||||
let eventFiles = readdirSync(`${process.cwd()}/${this._client.config.events}/`);
|
||||
|
||||
for (let i = 0; i < eventFiles.length; i++) {
|
||||
let eventName = eventFiles[i].split('.')[0];
|
||||
let file = require(`${process.cwd()}/${this._client.config.events}/${eventName}.js`);
|
||||
|
||||
let event = new file;
|
||||
|
||||
this._client.on(eventName, event[event.run]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = util;
|
7
src/index.js
Normal file
7
src/index.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
const discord = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
client: require('./client/client'),
|
||||
command: require('./type/command'),
|
||||
event: require('./type/event')
|
||||
}
|
107
src/package-lock.json
generated
Normal file
107
src/package-lock.json
generated
Normal file
|
@ -0,0 +1,107 @@
|
|||
{
|
||||
"name": "vylbot-core",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@discordjs/collection": {
|
||||
"version": "0.1.6",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz",
|
||||
"integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ=="
|
||||
},
|
||||
"@discordjs/form-data": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz",
|
||||
"integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==",
|
||||
"requires": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
}
|
||||
},
|
||||
"abort-controller": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
|
||||
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
|
||||
"requires": {
|
||||
"event-target-shim": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"requires": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
|
||||
},
|
||||
"discord.js": {
|
||||
"version": "12.3.1",
|
||||
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.3.1.tgz",
|
||||
"integrity": "sha512-mSFyV/mbvzH12UXdS4zadmeUf8IMQOo/YdunubG1wWt1xjWvtaJz/s9CGsFD2B5pTw1W/LXxxUbrQjIZ/xlUdw==",
|
||||
"requires": {
|
||||
"@discordjs/collection": "^0.1.6",
|
||||
"@discordjs/form-data": "^3.0.1",
|
||||
"abort-controller": "^3.0.0",
|
||||
"node-fetch": "^2.6.0",
|
||||
"prism-media": "^1.2.2",
|
||||
"setimmediate": "^1.0.5",
|
||||
"tweetnacl": "^1.0.3",
|
||||
"ws": "^7.3.1"
|
||||
}
|
||||
},
|
||||
"event-target-shim": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
|
||||
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ=="
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.44.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz",
|
||||
"integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg=="
|
||||
},
|
||||
"mime-types": {
|
||||
"version": "2.1.27",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz",
|
||||
"integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==",
|
||||
"requires": {
|
||||
"mime-db": "1.44.0"
|
||||
}
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
||||
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
|
||||
},
|
||||
"prism-media": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.2.tgz",
|
||||
"integrity": "sha512-I+nkWY212lJ500jLe4tN9tWO7nRiBAVdMv76P9kffZjYhw20raMlW1HSSvS+MLXC9MmbNZCazMrAr+5jEEgTuw=="
|
||||
},
|
||||
"setimmediate": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
|
||||
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
|
||||
},
|
||||
"tweetnacl": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
|
||||
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="
|
||||
},
|
||||
"ws": {
|
||||
"version": "7.3.1",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.3.1.tgz",
|
||||
"integrity": "sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA=="
|
||||
}
|
||||
}
|
||||
}
|
14
src/package.json
Normal file
14
src/package.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "vylbot-core",
|
||||
"version": "1.0.0",
|
||||
"description": "A discord client based upon discord.js",
|
||||
"main": "./src/index",
|
||||
"scripts": {
|
||||
"test": "echo \"No Tests Specified\""
|
||||
},
|
||||
"author": "Vylpes",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"discord.js": "^12.3.1"
|
||||
}
|
||||
}
|
56
src/type/command.js
Normal file
56
src/type/command.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
class command {
|
||||
constructor(run) {
|
||||
this.run = run;
|
||||
}
|
||||
|
||||
// Description
|
||||
get description() {
|
||||
return this._description;
|
||||
}
|
||||
|
||||
set description(description) {
|
||||
this._description = description;
|
||||
}
|
||||
|
||||
// Category
|
||||
get category() {
|
||||
return this._category;
|
||||
}
|
||||
|
||||
set category(category) {
|
||||
this._category = category;
|
||||
}
|
||||
|
||||
// Usage
|
||||
get usage() {
|
||||
return this._usage;
|
||||
}
|
||||
|
||||
set usage(usage) {
|
||||
this._usage = usage;
|
||||
}
|
||||
|
||||
// Roles
|
||||
_roles = [];
|
||||
|
||||
get roles() {
|
||||
return this._roles;
|
||||
}
|
||||
|
||||
set roles(role) {
|
||||
this._roles.push(role);
|
||||
}
|
||||
|
||||
// Config
|
||||
_requiredConfigs = [];
|
||||
|
||||
get requiredConfigs() {
|
||||
return this._requiredConfigs;
|
||||
}
|
||||
|
||||
set requiredConfigs(conf) {
|
||||
this._requiredConfigs.push(conf);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = command;
|
7
src/type/event.js
Normal file
7
src/type/event.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
class event {
|
||||
constructor(run) {
|
||||
this.run = run;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = event;
|
Reference in a new issue