Removing all /commands

This commit is contained in:
= 2021-06-30 18:59:24 -04:00
parent 60f2ebbc2a
commit 3bdfbf0e44
5 changed files with 98 additions and 75 deletions

20
commands/gif.js Normal file
View File

@ -0,0 +1,20 @@
const giphy = require('giphy-api')(process.env.giphyAPIKey);
module.exports = {
name: 'gif',
description: 'Send a GIF',
execute(message, file) {
const client = message.client;
if (!client.gifs.has(file.name)) {
giphy.search(file.name, (err, res) => {
if (res.data[0] != undefined) {
message.channel.send(file.name + ' requested by ' + message.author.username + '\n' + res.data[0].embed_url).then().catch(console.error);
} else {
message.channel.send('I was unable to find a gif of ' + file.name);
}
if (err) console.error(err);
});
} else {
message.channel.send(file.name + ' requested by ' + message.author.username + '\n' + client.gifs.get(file.name).embed_url);
}
}
}

15
commands/pasta.js Normal file
View File

@ -0,0 +1,15 @@
module.exports = {
name: 'pasta',
description: 'Send a copypasta.',
execute(message, file) {
const client = message.client;
const replyHeader = `\'${file.name}\' requested by: ${message.author.username}\n`;
let replyBody = '';
if (!client.pastas.has(file.name)) {
replyBody = 'Sorry I couldn\'t find that pasta.';
} else {
replyBody = client.pastas.get(file.name).content;
}
message.channel.send(replyHeader + replyBody);
}
}

19
commands/spongebob.js Normal file
View File

@ -0,0 +1,19 @@
module.exports = {
name: 'spongebob',
description: 'SpOnGeBoB-iFy AnYtHiNg AuToMaTiCaLly',
execute(message, file) {
const replyHeader = `Requested by: ${message.author.username}\n`;
let flipper = 0;
let newText = '';
for (const letter of file.name) {
if (flipper == 0) {
newText = newText + letter.toUpperCase();
flipper = 1;
} else {
newText = newText + letter;
flipper = 0;
}
}
message.channel.send(replyHeader + newText);
}
}

View File

@ -30,20 +30,30 @@ module.exports = {
}
if (debug) console.log(client.pastas);
},
getExtension(args) {
const finalWord = args[args.length - 1];
const file = finalWord.split('.');
getFileInfo(content) {
const finalPeriod = content.search(/\.(?:.(?!\\))+$/gim);
if (finalPeriod < 0) return false;
const extension = content.slice(finalPeriod).replace('.','').toLowerCase();
const filename = content.slice(0,finalPeriod).toLowerCase();
const file = {
'name': filename,
'extension': extension
};
console.log(finalPeriod, file);
return file;
},
extCheck(content) {
const lastFour = content.slice(-4);
switch (lastFour) {
case '.gif':
return 'gif';
case '.jpg':
return 'jpg';
case '.pst':
return 'pst';
extIsValid(extension) {
switch (extension) {
case 'gif':
return true;
case 'jpg':
return false;
case 'pasta':
return true;
case 'admin':
return true;
case 'spongebob':
return true;
default:
return false;
}

View File

@ -20,77 +20,36 @@ client.once('ready', () => {
functions.getCommandFiles(client);
functions.getGifFiles(client);
functions.getPastaFiles(client);
client.channels.fetch(logChannel)
.then(channel => {
channel.send(bootMessage)
.then()
.catch(err => console.error(err));
})
.catch(err => console.error(err));
// client.channels.fetch(logChannel)
// .then(channel => {
// channel.send(bootMessage)
// .then()
// .catch(err => console.error(err));
// })
// .catch(err => console.error(err));
});
client.login(process.env.TOKEN);
client.on('message', message => {
const args = message.content.trim().split(/ +/);
// TODO this will surely break something when trying to use non-filename commands
const file = functions.getExtension(args);
// If the message is from a bot, or doesn't have the prefix or a file extension, stop here.
if ((!message.content.startsWith(prefix) && file[1] == undefined) || message.author.bot) return;
// Get the filename and extension as an array
// TODO Rename this function to something more appropriate
const file = functions.getFileInfo(message.content);
if (!file) return;
// If the message is from a bot, or doesn't have a valid file extension, stop here.
if (functions.extIsValid(file.extension) == false || message.author.bot) return;
// If the message starts with the prefix,
if (message.content.startsWith(prefix)) {
// Extract the command
const command = args.shift().toLowerCase().slice(prefix.length);
if (debug) console.log(args);
// If the command collection doesn't contain the given command, stop here.
if (!client.commands.has(command)) return;
if (!client.commands.has(file.extension)) return;
try {
// Attempt to execute the command
client.commands.get(command).execute(message, args);
client.commands.get(file.extension).execute(message, file);
} catch (error) {
// Log errors and let the user know something went wrong.
console.error(error);
message.channel.send('There was an error trying to execute that command.');
}
}
// If there is a file extension
if (file[1] != undefined) {
const query = message.content.slice(0, -4);
switch (file[1]) {
case 'gif':
if (debug) console.log(query);
if (!client.gifs.has(file[0])) {
giphy.search(query, (err, res) => {
if (res.data[0] != undefined) {
message.channel.send(query + ' requested by ' + message.author.username + '\n' + res.data[0].embed_url).then().catch(console.error);
} else {
message.channel.send('I was unable to find a gif of ' + query);
}
if (err) console.error(err);
});
} else {
message.channel.send(query + ' requested by ' + message.author.username + '\n' + client.gifs.get(query).embed_url);
}
break;
case 'pasta':
// const pastaName = args[0].splice(args[0].search(/\.(?:.(?!\\))+$/gim))
if (debug) console.log(file[0]);
if (!client.pastas.has(file[0])) {
message.reply('Sorry I couldn\'t find that gif.');
} else {
message.channel.send(client.pastas.get(file[0]).content, { split: { char: ' ' } });
}
break;
default:
break;
}
}
// Try to delete the requester's message
if (message.deletable) {