Initial Refactor *UNUSABLE*

This commit is contained in:
= 2021-06-27 19:41:25 -04:00
parent e554ba7cf8
commit abe1097c0c
9 changed files with 133 additions and 60 deletions

43
commands/help.js Normal file
View File

@ -0,0 +1,43 @@
const { prefix } = require('../config.json');
module.exports = {
name: 'help',
description: 'Shows the help page.',
execute(message, args) {
const data = [];
const { commands } = message.client;
if (!args.length) {
data.push('Here\'s a list of all my commands:');
data.push(commands.map(command => command.name).join(', '));
data.push(`\nYou can send \`${prefix}help [command name]\` to get info on a specific command!`);
return message.author.send(data, { split: true })
.then(() => {
if (message.channel.type === 'dm') return;
message.reply('I\'ve sent you a DM with all my commands!');
})
.catch(error => {
console.error(`Could not send help DM to ${message.author.tag}.\n`, error);
message.reply('it seems like I can\'t DM you! Do you have DMs disabled?');
});
}
const name = args[0].toLowerCase();
const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name));
if (!command) {
return message.reply('that\'s not a valid command!');
}
data.push(`**Name:** ${command.name}`);
if (command.aliases) data.push(`**Aliases:** ${command.aliases.join(', ')}`);
if (command.description) data.push(`**Description:** ${command.description}`);
if (command.usage) data.push(`**Usage:** ${prefix}${command.name} ${command.usage}`);
data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`);
message.channel.send(data, { split: true });
},
};

7
commands/log-message.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
name: "log-message",
description: "Logs the message to console for debugging purposes.",
execute(message, args) {
console.log(message);
}
}

7
commands/ping.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
name: 'ping',
description: 'Ping!',
execute(message, args) {
message.channel.send('Pong.');
}
}

9
commands/request.js Normal file
View File

@ -0,0 +1,9 @@
module.exports = {
name: 'request',
description: 'Submit a request to the bot developer.',
execute(message, args) {
const request = args.join(' ');
message.channel.send('Your request has been submitted:\n```\n' + request + '\n```');
message.client.users.fetch(process.env.ownerID).then(user => {user.send('New request or feedback:\n```\n' + request + '\n```');}).catch(error => { console.error(error);} );
}
}

7
commands/template Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
name: "",
description: "",
execute(message, args) {
message.channel.send("");
}
}

7
commands/truth.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
name: "truth",
description: "The truth about MHFS",
execute(message, args) {
message.channel.send("https://www.twitch.tv/hochmania/clip/EsteemedSlickDootStinkyCheese-hncmP8aIP8_WQb_a?filter=clips&range=all&sort=time");
}
}

9
commands/wrongbad.js Normal file
View File

@ -0,0 +1,9 @@
module.exports = {
name: "wrongbad",
description: "",
execute(message, args) {
const wrongbad = "<:wrongbad:853304921969393684>";
message.channel.send("");
}
}

4
config.json Normal file
View File

@ -0,0 +1,4 @@
{
"prefix": "/",
"serverID": "760701839427108874"
}

View File

@ -1,80 +1,60 @@
/* eslint-disable brace-style */ /* eslint-disable brace-style */
// Variable Assignment // Variable Assignment
const fs = require('fs');
const dotenv = require('dotenv'); const dotenv = require('dotenv');
dotenv.config();
const Discord = require('discord.js'); const Discord = require('discord.js');
const client = new Discord.Client(); const client = new Discord.Client();
const giphy = require('giphy-api')(process.env.giphyAPIKey); client.commands = new Discord.Collection();
const debug = false; const debug = true;
const links = require('./links.json'); const config = require('./config.json');
const { prefix, serverID } = require('./config.json');
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
// const owner = process.env.ownerID;
dotenv.config(); function getCommandFiles() {
const owner = process.env.ownerID; for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
if (debug) console.log(client.commands);
}
if (debug) { function extCheck(content) {
console.log(links); const lastFour = content.slice(-4);
switch (lastFour) {
case '.gif':
return 'gif';
case '.jpg':
return 'jpg';
default:
return false;
}
} }
client.once('ready', () => { client.once('ready', () => {
console.log('Ready'); console.log('Ready');
client.guilds.fetch(serverID)
.then(guild => client.user.setActivity('Nod Simulator 2021', {type: "PLAYING"}))
.catch(console.error);
getCommandFiles();
}); });
client.login(process.env.TOKEN); client.login(process.env.TOKEN);
client.on('message', message => { client.on('message', message => {
if (message.author.bot) return; if (debug) console.log(extCheck(message.content));
if (!message.content.startsWith(prefix) || message.author.bot || !extCheck(message.content)) return;
const pre = message.content.slice(0, -4); const args = message.content.slice(prefix.length).trim().split(/ +/);
const ext = message.content.slice(-4); const command = args.shift().toLowerCase();
let gifFound = false;
if (!client.commands.has(command)) return;
switch (ext) {
case '.gif':
if (debug) {
console.log('pre: ' + pre);
console.log('ext: ' + ext);
}
for (let index = 0; index < links.gifs.length; index++) {
const gif = links.gifs[index];
if (gif.name == pre) {
message.channel.send(gif.embed_url);
gifFound = true;
}
}
if (gifFound == false) {
try { try {
giphy.search(pre, function(err, res) { client.commands.get(command).execute(message, args);
if (res.data[0] != undefined) {
message.channel.send(res.data[0].embed_url);
} else {
message.channel.send('Sorry, I was unable to find a gif of ' + pre + '.');
}
if (err) {
console.log(err);
}
});
} catch (error) { } catch (error) {
console.log(error); console.error(error);
} message.reply('There was an error trying to execute that command.');
}
break;
// Admin Commands
case '.adm':
if (message.member.id == process.env.ownerID) {
switch (pre) {
case 'kill':
client.destroy();
process.exit();
break;
default:
break;
}
}
break;
case '.req':
message.channel.send('Feedback Submitted: ' + pre);
client.users.fetch(owner).then(user => { user.send('Feedback/Request: ' + pre);});
break;
default:
break;
} }
}); });