Compare commits
No commits in common. "cddceda3c5243795895e35c14d7d63981e0e09f1" and "8d07effbe087301fe327ab77a05051b66e68ea11" have entirely different histories.
cddceda3c5
...
8d07effbe0
6 changed files with 110 additions and 14 deletions
14
README.md
14
README.md
|
@ -1,14 +1,5 @@
|
||||||
# discord_bot
|
# discord_bot
|
||||||
|
|
||||||
|
|
||||||
| name | tests |
|
|
||||||
| -----| ----- |
|
|
||||||
| Github | |
|
|
||||||
|git.silence5k.com (forgejo-runner) | |
|
|
||||||
|
|
||||||
|
|
||||||
##
|
|
||||||
|
|
||||||
A modular discord bot written in javascript, using the [discord.js](https://discord.js.org) library.
|
A modular discord bot written in javascript, using the [discord.js](https://discord.js.org) library.
|
||||||
|
|
||||||
This is my second attempt at making a discord bot.
|
This is my second attempt at making a discord bot.
|
||||||
|
@ -33,8 +24,11 @@ You can also change the global prefix.
|
||||||
You should enter you discord user id, so you can use the admin commands.
|
You should enter you discord user id, so you can use the admin commands.
|
||||||
Every time you want to change something in this file, you have to restart the bot.
|
Every time you want to change something in this file, you have to restart the bot.
|
||||||
|
|
||||||
If the config is ever changed, you need to either delete it and repeat the steps above or take a look at the util/createInitialConfig.js file.
|
If the config is ever changed, you need to either delete it and repeat the steps above or take a look at the util/createInitialConfig.js file
|
||||||
|
|
||||||
|
Netload is a feature that enables the ability to upload .js files via discord to the bot.
|
||||||
|
This feature is not working at the moment.
|
||||||
|
If you want this feature, you have to enable it in ./data/config.json.
|
||||||
|
|
||||||
## Known issues
|
## Known issues
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'exampleName', // Keep it to one word
|
name: 'exampleName', // Keep it to one word
|
||||||
description: 'example description',
|
description: 'example description',
|
||||||
execute({message}) {
|
execute({message}) { //parameters you can use for netload: message, args, client, prefix
|
||||||
//code
|
//code
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -20,9 +20,14 @@ module.exports = {
|
||||||
let num_in_args = false;
|
let num_in_args = false;
|
||||||
let added_commands = 0;
|
let added_commands = 0;
|
||||||
let page = -1;
|
let page = -1;
|
||||||
|
if (args[0] == "netmodules") {
|
||||||
|
commandFiles = fs.readdirSync('../../netload').filter(file => file.endsWith('.js'));
|
||||||
|
if (commandFiles.length == 0) {
|
||||||
|
message.channel.send("There are no netmodules currently loaded.")
|
||||||
|
x = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(!isNaN(parseInt(args[0])) && parseInt(args[0])){
|
}else if(!isNaN(parseInt(args[0])) && parseInt(args[0])){
|
||||||
num_in_args = true;
|
num_in_args = true;
|
||||||
iteration = ( parseInt(args[0]) - 1) * 10;
|
iteration = ( parseInt(args[0]) - 1) * 10;
|
||||||
page = Math.round(parseInt(args[0]))
|
page = Math.round(parseInt(args[0]))
|
||||||
|
|
77
commands/misc/netload.js
Normal file
77
commands/misc/netload.js
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
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',
|
||||||
|
moreHelp: ["Examples:",
|
||||||
|
"Either provide a link to the module, or upload it",
|
||||||
|
"To get an example of how your module should look like, do:",
|
||||||
|
"<prefix>netload example",
|
||||||
|
"You have to be whitelisted to use this command.",
|
||||||
|
"The bot operator also has to have this enabled in the config."
|
||||||
|
],
|
||||||
|
execute({ message, args, prefix, client, owners }) {
|
||||||
|
if (!fs.existsSync('./data/netmoduleWhitelist.json')) {
|
||||||
|
fs.writeFileSync('./data/netmoduleWhitelist.json', "[]")
|
||||||
|
}
|
||||||
|
let json = fs.readFileSync('./data/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("./data/netmoduleWhitelist.json", JSON.stringify(whitelist, null, 4))
|
||||||
|
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") {
|
||||||
|
|
||||||
|
let example = fs.readFileSync('commands/.example')
|
||||||
|
|
||||||
|
message.channel.send(`\`\`\`js\n${example}\n\`\`\``)
|
||||||
|
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);
|
||||||
|
reloadNetModules(client);
|
||||||
|
});
|
||||||
|
|
||||||
|
}).on('error', (e) => {
|
||||||
|
message.channel.send("Error download file.");
|
||||||
|
console.log(e)
|
||||||
|
});
|
||||||
|
|
||||||
|
let reloadNetModules = require('../util/reloadNetModules');
|
||||||
|
reloadNetModules(client)
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -6,7 +6,8 @@ module.exports = function () {
|
||||||
"enableLoginMessage": false,
|
"enableLoginMessage": false,
|
||||||
"loginChannel" : "",
|
"loginChannel" : "",
|
||||||
"loginMessage" : "Bot is online!",
|
"loginMessage" : "Bot is online!",
|
||||||
"owners": []
|
"owners": [],
|
||||||
|
"allowNetload" : false
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!fs.existsSync("./data/")) fs.mkdirSync("./data");
|
if(!fs.existsSync("./data/")) fs.mkdirSync("./data");
|
||||||
|
|
19
util/reloadNetModules.js
Normal file
19
util/reloadNetModules.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
Add a link
Reference in a new issue