Removing all /commands
This commit is contained in:
parent
60f2ebbc2a
commit
3bdfbf0e44
20
commands/gif.js
Normal file
20
commands/gif.js
Normal 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
15
commands/pasta.js
Normal 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
19
commands/spongebob.js
Normal 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);
|
||||
}
|
||||
}
|
34
functions.js
34
functions.js
@ -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;
|
||||
}
|
||||
|
85
index.js
85
index.js
@ -20,76 +20,35 @@ 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 the command collection doesn't contain the given command, stop here.
|
||||
if (!client.commands.has(file.extension)) return;
|
||||
|
||||
if (debug) console.log(args);
|
||||
// If the command collection doesn't contain the given command, stop here.
|
||||
if (!client.commands.has(command)) return;
|
||||
|
||||
try {
|
||||
// Attempt to execute the command
|
||||
client.commands.get(command).execute(message, args);
|
||||
} 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 {
|
||||
// Attempt to execute the command
|
||||
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.');
|
||||
}
|
||||
|
||||
// Try to delete the requester's message
|
||||
|
Loading…
Reference in New Issue
Block a user