Changing extension handling
This commit is contained in:
parent
232244068a
commit
52327a897d
@ -23,9 +23,9 @@ module.exports = {
|
|||||||
if (debug) console.log(client.gifs);
|
if (debug) console.log(client.gifs);
|
||||||
},
|
},
|
||||||
getPastaFiles(client) {
|
getPastaFiles(client) {
|
||||||
client.pasta = new Discord.Collection();
|
client.pastas = new Discord.Collection();
|
||||||
for (const file of pastaFiles) {
|
for (const file of pastaFiles) {
|
||||||
const pasta = require(`./pasta/${file}`);
|
const pasta = require(`./pastas/${file}`);
|
||||||
client.pastas.set(pasta.name, pasta);
|
client.pastas.set(pasta.name, pasta);
|
||||||
}
|
}
|
||||||
if (debug) console.log(client.pastas);
|
if (debug) console.log(client.pastas);
|
||||||
@ -33,7 +33,7 @@ module.exports = {
|
|||||||
getExtension(args) {
|
getExtension(args) {
|
||||||
const finalWord = args.pop();
|
const finalWord = args.pop();
|
||||||
const file = finalWord.split('.');
|
const file = finalWord.split('.');
|
||||||
return file[1];
|
return file;
|
||||||
},
|
},
|
||||||
extCheck(content) {
|
extCheck(content) {
|
||||||
const lastFour = content.slice(-4);
|
const lastFour = content.slice(-4);
|
||||||
|
33
index.js
33
index.js
@ -26,30 +26,38 @@ client.login(process.env.TOKEN);
|
|||||||
|
|
||||||
client.on('message', message => {
|
client.on('message', message => {
|
||||||
const args = message.content.trim().split(/ +/);
|
const args = message.content.trim().split(/ +/);
|
||||||
const extension = functions.getExtension(args);
|
// TODO this will surely break something when trying to use non-filename commands
|
||||||
if ((!message.content.startsWith(prefix) && extension != undefined) || message.author.bot) return;
|
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;
|
||||||
|
|
||||||
|
// If the message starts with the prefix,
|
||||||
if (message.content.startsWith(prefix)) {
|
if (message.content.startsWith(prefix)) {
|
||||||
|
// Extract the command
|
||||||
const command = args.shift().toLowerCase().slice(prefix.length);
|
const command = args.shift().toLowerCase().slice(prefix.length);
|
||||||
|
|
||||||
if (debug) console.log(args);
|
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(command)) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Attempt to execute the command
|
||||||
client.commands.get(command).execute(message, args);
|
client.commands.get(command).execute(message, args);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
// 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.');
|
||||||
message.guild.owner
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there is a file extension
|
||||||
|
if (file[1] != undefined) {
|
||||||
const query = message.content.slice(0, -4);
|
const query = message.content.slice(0, -4);
|
||||||
switch (extension) {
|
switch (file[1]) {
|
||||||
case '.gif':
|
case 'gif':
|
||||||
if (debug) console.log(query);
|
if (debug) console.log(query);
|
||||||
|
|
||||||
if (!client.gifs.has(query)) {
|
if (!client.gifs.has(file[0])) {
|
||||||
giphy.search(query, (err, res) => {
|
giphy.search(query, (err, res) => {
|
||||||
if (res.data[0] != undefined) {
|
if (res.data[0] != undefined) {
|
||||||
message.channel.send(res.data[0].embed_url).then().catch(console.error);
|
message.channel.send(res.data[0].embed_url).then().catch(console.error);
|
||||||
@ -62,17 +70,20 @@ client.on('message', message => {
|
|||||||
message.channel.send(client.gifs.get(query).embed_url);
|
message.channel.send(client.gifs.get(query).embed_url);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '.pasta':
|
case 'pasta':
|
||||||
const pastaName = args[0].splice(args[0].search(/\.(?:.(?!\\))+$/gim))
|
// const pastaName = args[0].splice(args[0].search(/\.(?:.(?!\\))+$/gim))
|
||||||
if (debug) console.log(query);
|
if (debug) console.log(file[0]);
|
||||||
|
|
||||||
if (!client.pastas.has(query)) {
|
if (!client.pastas.has(file[0])) {
|
||||||
message.reply('Sorry I couldn\'t find that gif.');
|
message.reply('Sorry I couldn\'t find that gif.');
|
||||||
} else {
|
} else {
|
||||||
message.channel.send(client.pastas.get(query).content);
|
message.channel.send(client.pastas.get(file[0]).content);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user