ability to cancel savegif
This commit is contained in:
parent
0a86548264
commit
2e71b114f2
@ -6,7 +6,7 @@ const tenor = require('tenorjs').client({
|
|||||||
"DateFormat": "D/MM/YYYY - H:mm:ss A" // Change this accordingly
|
"DateFormat": "D/MM/YYYY - H:mm:ss A" // Change this accordingly
|
||||||
});
|
});
|
||||||
const functions = require('../functions');
|
const functions = require('../functions');
|
||||||
const { emoji } = require('../config.json');
|
const { emoji } = require('../src/strings.json');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'savegif',
|
name: 'savegif',
|
||||||
@ -32,15 +32,17 @@ module.exports = {
|
|||||||
// Send the first GIF result as an Embed
|
// Send the first GIF result as an Embed
|
||||||
channel.send(embed)
|
channel.send(embed)
|
||||||
.then(selfMessage => {
|
.then(selfMessage => {
|
||||||
// Add reactions to go back, forward, and confirm GIF choice.
|
// Add reactions to go back, forward, cancel and confirm GIF choice.
|
||||||
// React order is important so these are done in a chain
|
// React order is important so these are done in a chain
|
||||||
selfMessage.react(emoji.previous).then(() => {
|
selfMessage.react(emoji.previous).then(() => {
|
||||||
selfMessage.react(emoji.confirm).then(() => {
|
selfMessage.react(emoji.confirm).then(() => {
|
||||||
selfMessage.react(emoji.next);
|
selfMessage.react(emoji.next).then(() => {
|
||||||
|
selfMessage.react(emoji.cancel);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const filter = (reaction, user) => {
|
const filter = (reaction, user) => {
|
||||||
return ((reaction.emoji.name == emoji.next) || (reaction.emoji.name == emoji.confirm) || (reaction.emoji.name == emoji.previous)) && user.id == message.author.id;
|
return ((reaction.emoji.name == emoji.next) || (reaction.emoji.name == emoji.confirm) || (reaction.emoji.name == emoji.previous) || (reaction.emoji.name == emoji.cancel)) && user.id == message.author.id;
|
||||||
}
|
}
|
||||||
const collector = selfMessage.createReactionCollector(filter, { time: 120000 });
|
const collector = selfMessage.createReactionCollector(filter, { time: 120000 });
|
||||||
|
|
||||||
@ -60,8 +62,19 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case emoji.confirm:
|
case emoji.confirm:
|
||||||
channel.send('GIF Selected. What should I save the GIF as? (don\'t include the `.gif`)')
|
channel.send('GIF Selected. What should I save the GIF as? (don\'t include the `.gif`)\nReact with ' + emoji.cancel + ' to cancel.')
|
||||||
.then(nameQueryMessage => {
|
.then(nameQueryMessage => {
|
||||||
|
nameQueryMessage.react(emoji.cancel);
|
||||||
|
const cancelReactFilter = (reaction, user) => {
|
||||||
|
return (reaction.emoji.name == emoji.cancel) && (user.id == message.author.id);
|
||||||
|
}
|
||||||
|
const cancelReactCollector = nameQueryMessage.createReactionCollector(cancelReactFilter, { time: 20000, max: 1 });
|
||||||
|
|
||||||
|
cancelReactCollector.on('collect', (reaction, user) => {
|
||||||
|
nameCollector.stop('cancel');
|
||||||
|
if (selfMessage.deletable) selfMessage.delete();
|
||||||
|
if (nameQueryMessage.deletable) nameQueryMessage.delete();
|
||||||
|
})
|
||||||
const nameCollectorFilter = nameMessage => nameMessage.author == message.author;
|
const nameCollectorFilter = nameMessage => nameMessage.author == message.author;
|
||||||
const nameCollector = nameQueryMessage.channel.createMessageCollector(nameCollectorFilter, { time: 30000, max: 1 });
|
const nameCollector = nameQueryMessage.channel.createMessageCollector(nameCollectorFilter, { time: 30000, max: 1 });
|
||||||
|
|
||||||
@ -69,7 +82,17 @@ module.exports = {
|
|||||||
channel.send('The GIF has been saved as: ' + nameMessage.content + '.gif');
|
channel.send('The GIF has been saved as: ' + nameMessage.content + '.gif');
|
||||||
functions.saveGif(message, nameMessage.content, data.embed_url);
|
functions.saveGif(message, nameMessage.content, data.embed_url);
|
||||||
});
|
});
|
||||||
|
nameCollector.on('end', (collected, reason) => {
|
||||||
|
switch (reason) {
|
||||||
|
case 'cancel':
|
||||||
|
channel.send('The action has been canceled.');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
collector.stop("confirm");
|
||||||
break;
|
break;
|
||||||
case emoji.previous:
|
case emoji.previous:
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
@ -84,10 +107,26 @@ module.exports = {
|
|||||||
selfMessage.edit(embed);
|
selfMessage.edit(embed);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case emoji.cancel:
|
||||||
|
collector.stop('cancel');
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
channel.send('There was an error, sorry.');
|
channel.send('There was an error, sorry.');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
collector.on('end', (collected, reason) => {
|
||||||
|
switch (reason) {
|
||||||
|
case 'cancel':
|
||||||
|
selfMessage.delete();
|
||||||
|
channel.send('The action has been canceled.');
|
||||||
|
break;
|
||||||
|
case 'messageDelete':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}).catch(err => console.error(err));
|
}).catch(err => console.error(err));
|
||||||
})
|
})
|
||||||
|
4
gifs/test.js
Normal file
4
gifs/test.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
module.exports = {
|
||||||
|
name: 'test',
|
||||||
|
embed_url: 'https://media.tenor.com/images/0f097ed319d498c2bda3d87ba4f6ff10/tenor.gif'
|
||||||
|
}
|
@ -9,5 +9,12 @@
|
|||||||
"You're gonna be doing a lot of doobie rollin' when you're living in a ran down by the river!",
|
"You're gonna be doing a lot of doobie rollin' when you're living in a ran down by the river!",
|
||||||
"You'll have plenty of time to live in a van down by the river... when you're living in a van down by the river!",
|
"You'll have plenty of time to live in a van down by the river... when you're living in a van down by the river!",
|
||||||
"Roll, roll, roll my joint, pick out the seeds and stems"
|
"Roll, roll, roll my joint, pick out the seeds and stems"
|
||||||
]
|
],
|
||||||
|
"emoji": {
|
||||||
|
"joint": "<:joint:862082955902976000>",
|
||||||
|
"next": "⏭️",
|
||||||
|
"previous": "⏮️",
|
||||||
|
"confirm": "☑️",
|
||||||
|
"cancel": "❌"
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user