Add ability to upload modules to the bot via discord
* Remove unused dependencies * Add basic downloading of modules * Add valid-url as dependency * Add loading/reloading of netmodules * Add support for help on netmodules * Add whitelist for netmodules
This commit is contained in:
parent
88100600b9
commit
d636b39d7a
6 changed files with 126 additions and 127 deletions
|
@ -5,9 +5,19 @@ const Discord = require('discord.js');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'help',
|
name: 'help',
|
||||||
description: 'List all available commands.',
|
description: 'List all available commands.',
|
||||||
execute({message, args, prefix}) {
|
execute({ message, args, prefix }) {
|
||||||
var commands = " "
|
var commands = " "
|
||||||
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
|
let commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
|
||||||
|
let x = 0
|
||||||
|
if (args[0] == "netload") {
|
||||||
|
commandFiles = fs.readdirSync('./netload').filter(file => file.endsWith('.js'));
|
||||||
|
if (commandFiles.length == 0) {
|
||||||
|
message.channel.send("There are no netmodules currently loaded.")
|
||||||
|
x = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (x == 1) return;
|
||||||
|
|
||||||
const embed = new Discord.MessageEmbed()
|
const embed = new Discord.MessageEmbed()
|
||||||
.setColor(15780145)
|
.setColor(15780145)
|
||||||
|
@ -20,12 +30,12 @@ module.exports = {
|
||||||
const command = require(`./${file}`);
|
const command = require(`./${file}`);
|
||||||
|
|
||||||
|
|
||||||
if(args[0] == "admin"){
|
if (args[0] == "admin") {
|
||||||
if (command.admin && !command.disabled)
|
if (command.admin && !command.disabled)
|
||||||
commands = commands + `${prefix}${command.name} | ${command.description}\n`
|
commands = commands + `${prefix}${command.name} | ${command.description}\n`
|
||||||
}else
|
} else
|
||||||
if(!command.admin && !command.disabled)
|
if (!command.admin && !command.disabled)
|
||||||
commands = commands + `${prefix}${command.name} | ${command.description}\n`
|
commands = commands + `${prefix}${command.name} | ${command.description}\n`
|
||||||
}
|
}
|
||||||
embed.addFields(
|
embed.addFields(
|
||||||
{ name: "General", value: commands },
|
{ name: "General", value: commands },
|
||||||
|
|
64
commands/netload.js
Normal file
64
commands/netload.js
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
const https = require('https');
|
||||||
|
const fs = require('fs')
|
||||||
|
const netloadDir = "./netload"
|
||||||
|
const validUrl = require('valid-url');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'netload',
|
||||||
|
description: 'Load a module from the internet',
|
||||||
|
execute({ message, args, prefix, client, owners }) {
|
||||||
|
const json = fs.readFileSync('netmoduleWhitelist.json', 'utf8');
|
||||||
|
let whitelist = JSON.parse(json)
|
||||||
|
if (json.indexOf(message.author.id.toString()) == -1) {
|
||||||
|
message.channel.send("You do not have permissions to use this command.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args[0] == "whitelist" && owners.indexOf(message.author.id.toString()) >= 0) {
|
||||||
|
whitelist.push(args[1])
|
||||||
|
fs.writeFileSync("netmoduleWhitelist.json", JSON.stringify(whitelist))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!args[0] && message.attachments.size == 0) {
|
||||||
|
message.channel.send(`You have to either specify a url or upload a file via the command.\nTo get an example file, execute \`${prefix}netload example\``)
|
||||||
|
return;
|
||||||
|
|
||||||
|
} if (args[0] == "example") {
|
||||||
|
message.channel.send({ files: [{ attachment: "./commands/.example" }] })
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let url, fileName;
|
||||||
|
if (message.attachments.size > 0) {
|
||||||
|
url = message.attachments.first().url
|
||||||
|
fileName = message.attachments.first().name
|
||||||
|
} else {
|
||||||
|
url = args[0]
|
||||||
|
if (!validUrl.isUri(url)) {
|
||||||
|
message.channel.send("This does not look like a valid url")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fileName = args[0].split("/")[args[0].split("/").length - 1]
|
||||||
|
}
|
||||||
|
if (fs.existsSync(`${netloadDir}/${fileName}`)) {
|
||||||
|
message.channel.send(`A module with this filename(${fileName}) already exists.`)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
https.get(url, (res) => {
|
||||||
|
res.on('data', (d) => {
|
||||||
|
fs.writeFileSync(`${netloadDir}/${fileName}`, d);
|
||||||
|
loadNetModules(client);
|
||||||
|
});
|
||||||
|
|
||||||
|
}).on('error', (e) => {
|
||||||
|
message.channel.send("Error download file.");
|
||||||
|
console.log(e)
|
||||||
|
});
|
||||||
|
|
||||||
|
let loadNetModules = require('../util/loadNetModules');
|
||||||
|
loadNetModules(client)
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
129
package-lock.json
generated
129
package-lock.json
generated
|
@ -11,7 +11,7 @@
|
||||||
"discord.js": "^12.5.1",
|
"discord.js": "^12.5.1",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"parse-ms": "^2.1.0",
|
"parse-ms": "^2.1.0",
|
||||||
"thesaurize": "^1.0.11"
|
"valid-url": "^1.0.9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@discordjs/collection": {
|
"node_modules/@discordjs/collection": {
|
||||||
|
@ -290,24 +290,6 @@
|
||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/fs-extra": {
|
|
||||||
"version": "8.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
|
|
||||||
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
|
|
||||||
"dependencies": {
|
|
||||||
"graceful-fs": "^4.2.0",
|
|
||||||
"jsonfile": "^4.0.0",
|
|
||||||
"universalify": "^0.1.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=6 <7 || >=8"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/graceful-fs": {
|
|
||||||
"version": "4.2.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
|
|
||||||
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ=="
|
|
||||||
},
|
|
||||||
"node_modules/http-errors": {
|
"node_modules/http-errors": {
|
||||||
"version": "1.7.2",
|
"version": "1.7.2",
|
||||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
|
||||||
|
@ -347,19 +329,6 @@
|
||||||
"node": ">= 0.10"
|
"node": ">= 0.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/jsonfile": {
|
|
||||||
"version": "4.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
|
|
||||||
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
|
|
||||||
"dependencies": {
|
|
||||||
"graceful-fs": "^4.1.6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/lodash": {
|
|
||||||
"version": "4.17.21",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
|
||||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
|
||||||
},
|
|
||||||
"node_modules/media-typer": {
|
"node_modules/media-typer": {
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||||
|
@ -464,14 +433,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
||||||
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
||||||
},
|
},
|
||||||
"node_modules/pluralize": {
|
|
||||||
"version": "7.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/pluralize/-/pluralize-7.0.0.tgz",
|
|
||||||
"integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/prism-media": {
|
"node_modules/prism-media": {
|
||||||
"version": "1.2.5",
|
"version": "1.2.5",
|
||||||
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.5.tgz",
|
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.5.tgz",
|
||||||
|
@ -589,22 +550,6 @@
|
||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/thesaurize": {
|
|
||||||
"version": "1.0.11",
|
|
||||||
"resolved": "https://registry.npmjs.org/thesaurize/-/thesaurize-1.0.11.tgz",
|
|
||||||
"integrity": "sha512-xrJ5ayc02wquyeTBQ8l1RlFo7YOBY0jjyKUJOYuHgoWtS1I9GKOoVWsaYV3GTsErvAokslYnvQ/a5G7vsmVXSg==",
|
|
||||||
"dependencies": {
|
|
||||||
"fs-extra": "^8.0.0",
|
|
||||||
"lodash": "^4.17.11",
|
|
||||||
"pluralize": "^7.0.0",
|
|
||||||
"thesaurus": "0.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/thesaurus": {
|
|
||||||
"version": "0.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/thesaurus/-/thesaurus-0.0.0.tgz",
|
|
||||||
"integrity": "sha1-CjszVvwdgYxsFsI/Vrp/PFolyQU="
|
|
||||||
},
|
|
||||||
"node_modules/toidentifier": {
|
"node_modules/toidentifier": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
|
||||||
|
@ -630,14 +575,6 @@
|
||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/universalify": {
|
|
||||||
"version": "0.1.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
|
|
||||||
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/unpipe": {
|
"node_modules/unpipe": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||||
|
@ -654,6 +591,11 @@
|
||||||
"node": ">= 0.4.0"
|
"node": ">= 0.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/valid-url": {
|
||||||
|
"version": "1.0.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/valid-url/-/valid-url-1.0.9.tgz",
|
||||||
|
"integrity": "sha1-HBRHm0DxOXp1eC8RXkCGRHQzogA="
|
||||||
|
},
|
||||||
"node_modules/vary": {
|
"node_modules/vary": {
|
||||||
"version": "1.1.2",
|
"version": "1.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
||||||
|
@ -891,21 +833,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
|
||||||
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
|
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
|
||||||
},
|
},
|
||||||
"fs-extra": {
|
|
||||||
"version": "8.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz",
|
|
||||||
"integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==",
|
|
||||||
"requires": {
|
|
||||||
"graceful-fs": "^4.2.0",
|
|
||||||
"jsonfile": "^4.0.0",
|
|
||||||
"universalify": "^0.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"graceful-fs": {
|
|
||||||
"version": "4.2.6",
|
|
||||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
|
|
||||||
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ=="
|
|
||||||
},
|
|
||||||
"http-errors": {
|
"http-errors": {
|
||||||
"version": "1.7.2",
|
"version": "1.7.2",
|
||||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
|
||||||
|
@ -936,19 +863,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
|
||||||
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g=="
|
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g=="
|
||||||
},
|
},
|
||||||
"jsonfile": {
|
|
||||||
"version": "4.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
|
|
||||||
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
|
|
||||||
"requires": {
|
|
||||||
"graceful-fs": "^4.1.6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"lodash": {
|
|
||||||
"version": "4.17.21",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
|
||||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
|
||||||
},
|
|
||||||
"media-typer": {
|
"media-typer": {
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||||
|
@ -1020,11 +934,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
|
||||||
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
|
||||||
},
|
},
|
||||||
"pluralize": {
|
|
||||||
"version": "7.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/pluralize/-/pluralize-7.0.0.tgz",
|
|
||||||
"integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow=="
|
|
||||||
},
|
|
||||||
"prism-media": {
|
"prism-media": {
|
||||||
"version": "1.2.5",
|
"version": "1.2.5",
|
||||||
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.5.tgz",
|
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.5.tgz",
|
||||||
|
@ -1123,22 +1032,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
|
||||||
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
|
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
|
||||||
},
|
},
|
||||||
"thesaurize": {
|
|
||||||
"version": "1.0.11",
|
|
||||||
"resolved": "https://registry.npmjs.org/thesaurize/-/thesaurize-1.0.11.tgz",
|
|
||||||
"integrity": "sha512-xrJ5ayc02wquyeTBQ8l1RlFo7YOBY0jjyKUJOYuHgoWtS1I9GKOoVWsaYV3GTsErvAokslYnvQ/a5G7vsmVXSg==",
|
|
||||||
"requires": {
|
|
||||||
"fs-extra": "^8.0.0",
|
|
||||||
"lodash": "^4.17.11",
|
|
||||||
"pluralize": "^7.0.0",
|
|
||||||
"thesaurus": "0.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"thesaurus": {
|
|
||||||
"version": "0.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/thesaurus/-/thesaurus-0.0.0.tgz",
|
|
||||||
"integrity": "sha1-CjszVvwdgYxsFsI/Vrp/PFolyQU="
|
|
||||||
},
|
|
||||||
"toidentifier": {
|
"toidentifier": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
|
||||||
|
@ -1158,11 +1051,6 @@
|
||||||
"mime-types": "~2.1.24"
|
"mime-types": "~2.1.24"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"universalify": {
|
|
||||||
"version": "0.1.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
|
|
||||||
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
|
|
||||||
},
|
|
||||||
"unpipe": {
|
"unpipe": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||||
|
@ -1173,6 +1061,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
|
||||||
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
|
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
|
||||||
},
|
},
|
||||||
|
"valid-url": {
|
||||||
|
"version": "1.0.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/valid-url/-/valid-url-1.0.9.tgz",
|
||||||
|
"integrity": "sha1-HBRHm0DxOXp1eC8RXkCGRHQzogA="
|
||||||
|
},
|
||||||
"vary": {
|
"vary": {
|
||||||
"version": "1.1.2",
|
"version": "1.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"discord.js": "^12.5.1",
|
"discord.js": "^12.5.1",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"parse-ms": "^2.1.0",
|
"parse-ms": "^2.1.0",
|
||||||
"thesaurize": "^1.0.11"
|
"valid-url": "^1.0.9"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
|
17
server.js
17
server.js
|
@ -12,10 +12,13 @@ const {
|
||||||
|
|
||||||
client.commands = new Discord.Collection();
|
client.commands = new Discord.Collection();
|
||||||
client.serverPrefixes = new Discord.Collection();
|
client.serverPrefixes = new Discord.Collection();
|
||||||
|
client.netmodules = new Discord.Collection();
|
||||||
|
|
||||||
var reloadCommands = require("./util/reloadCommands.js");
|
var reloadCommands = require("./util/reloadCommands.js");
|
||||||
const loadServerPrefixes = require('./util/loadServerPrefixes');
|
const loadServerPrefixes = require('./util/loadServerPrefixes');
|
||||||
|
const loadNetModules = require('./util/loadNetModules');
|
||||||
reloadCommands(client)
|
reloadCommands(client)
|
||||||
|
loadNetModules(client)
|
||||||
|
|
||||||
client.once('ready', () => {
|
client.once('ready', () => {
|
||||||
console.log('Ready!');
|
console.log('Ready!');
|
||||||
|
@ -48,13 +51,23 @@ client.on('message', async message => {
|
||||||
|
|
||||||
const commandName = args.shift().toLowerCase();
|
const commandName = args.shift().toLowerCase();
|
||||||
const command = client.commands.get(commandName);
|
const command = client.commands.get(commandName);
|
||||||
|
const netModule = client.netmodules.get(commandName);
|
||||||
if (!message.guild) return;
|
if (!message.guild) return;
|
||||||
if (message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
if (!message.content.startsWith(prefix)) return;
|
if (!message.content.startsWith(prefix)) return;
|
||||||
if (!command) return;
|
if (!command){
|
||||||
|
if (netModule){
|
||||||
|
try {
|
||||||
|
netModule.execute({message: message, args: args, client: client, prefix: prefix})
|
||||||
|
}catch(e){
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (command.admin && owners.indexOf(message.author.id.toString()) == -1) return;
|
if (command.admin && owners.indexOf(message.author.id.toString()) == -1) return;
|
||||||
try {
|
try {
|
||||||
command.execute({ message: message, args: args, client: client, prefix: prefix})
|
command.execute({ message: message, args: args, client: client, prefix: prefix, owners: owners})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`${error}\n-------`)
|
console.log(`${error}\n-------`)
|
||||||
}
|
}
|
||||||
|
|
19
util/loadNetModules.js
Normal file
19
util/loadNetModules.js
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
const fs = require('fs')
|
||||||
|
const netloadDir = 'netload/'
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = function (client) {
|
||||||
|
if (!fs.existsSync(netloadDir)) fs.mkdirSync(netloadDir);
|
||||||
|
let commandFiles = fs.readdirSync(netloadDir).filter(file => file.endsWith('.js'));
|
||||||
|
if (client.netmodules.size != 0) {
|
||||||
|
for (const i of commandFiles) {
|
||||||
|
delete require.cache[require.resolve(`../${netloadDir}${i}`)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
client.netmodules.clear()
|
||||||
|
for (const file of commandFiles) {
|
||||||
|
const command = require(`../${netloadDir}${file}`);
|
||||||
|
client.netmodules.set(command.name, command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue