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);
|
if (debug) console.log(client.pastas);
|
||||||
},
|
},
|
||||||
getExtension(args) {
|
getFileInfo(content) {
|
||||||
const finalWord = args[args.length - 1];
|
const finalPeriod = content.search(/\.(?:.(?!\\))+$/gim);
|
||||||
const file = finalWord.split('.');
|
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;
|
return file;
|
||||||
},
|
},
|
||||||
extCheck(content) {
|
extIsValid(extension) {
|
||||||
const lastFour = content.slice(-4);
|
switch (extension) {
|
||||||
switch (lastFour) {
|
case 'gif':
|
||||||
case '.gif':
|
return true;
|
||||||
return 'gif';
|
case 'jpg':
|
||||||
case '.jpg':
|
return false;
|
||||||
return 'jpg';
|
case 'pasta':
|
||||||
case '.pst':
|
return true;
|
||||||
return 'pst';
|
case 'admin':
|
||||||
|
return true;
|
||||||
|
case 'spongebob':
|
||||||
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
71
index.js
71
index.js
@ -20,77 +20,36 @@ client.once('ready', () => {
|
|||||||
functions.getCommandFiles(client);
|
functions.getCommandFiles(client);
|
||||||
functions.getGifFiles(client);
|
functions.getGifFiles(client);
|
||||||
functions.getPastaFiles(client);
|
functions.getPastaFiles(client);
|
||||||
client.channels.fetch(logChannel)
|
// client.channels.fetch(logChannel)
|
||||||
.then(channel => {
|
// .then(channel => {
|
||||||
channel.send(bootMessage)
|
// channel.send(bootMessage)
|
||||||
.then()
|
// .then()
|
||||||
.catch(err => console.error(err));
|
// .catch(err => console.error(err));
|
||||||
})
|
// })
|
||||||
.catch(err => console.error(err));
|
// .catch(err => console.error(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
client.login(process.env.TOKEN);
|
client.login(process.env.TOKEN);
|
||||||
|
|
||||||
client.on('message', message => {
|
client.on('message', message => {
|
||||||
const args = message.content.trim().split(/ +/);
|
// Get the filename and extension as an array
|
||||||
// TODO this will surely break something when trying to use non-filename commands
|
// TODO Rename this function to something more appropriate
|
||||||
const file = functions.getExtension(args);
|
const file = functions.getFileInfo(message.content);
|
||||||
// If the message is from a bot, or doesn't have the prefix or a file extension, stop here.
|
if (!file) return;
|
||||||
if ((!message.content.startsWith(prefix) && file[1] == undefined) || message.author.bot) 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 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 {
|
try {
|
||||||
// Attempt to execute the command
|
// Attempt to execute the command
|
||||||
client.commands.get(command).execute(message, args);
|
client.commands.get(file.extension).execute(message, file);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Log errors and let the user know something went wrong.
|
// Log errors and let the user know something went wrong.
|
||||||
console.error(error);
|
console.error(error);
|
||||||
message.channel.send('There was an error trying to execute that command.');
|
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
|
// Try to delete the requester's message
|
||||||
if (message.deletable) {
|
if (message.deletable) {
|
||||||
|
Loading…
Reference in New Issue
Block a user