-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembeds.js
61 lines (57 loc) · 2.14 KB
/
embeds.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const { EmbedBuilder } = require('discord.js');
async function playing (queue, track){
const { back, leave, skip } = require('./music-logic.js');
const play = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle(track.title)
.setURL(track.url)
.setAuthor({ name: track.author })
.setThumbnail(track.thumbnail)
.addFields(
{ name: 'Time', value: track.duration.toString(), inline: true },
{ name: 'Views', value: track.views.toString(), inline: true },
)
.setTimestamp()
.setFooter({ text: track.id, iconURL: queue.metadata.message.guild.members.me.displayAvatarURL()});
let time,array,seconds;
time = track.duration;
array = time.split(":");
if (array.lenght === 3)
seconds = (parseInt(array[0], 10) * 60 * 60) + (parseInt(array[1], 10) * 60) + parseInt(array[2], 10)
else
seconds = (parseInt(array[0], 10) * 60) + parseInt(array[1], 10)
queue.metadata.channel.send({embeds: [play]}).then(msg => {
const filter = (reaction, user) => {
return ['⏪', '⏹️', '⏭️'].includes(reaction.emoji.name) && user.id;
}
msg.react('⏪')
.then(() => msg.react('⏹️'))
.then(() => msg.react('⏭️'))
.then(() => setTimeout(async function() {
msg.awaitReactions({ filter, max: 1, time: seconds * 1000 + 1000, errors: ['time'] }).then(collected => {
const reaction = collected.first();
switch (reaction.emoji.name){
case '⏪':
back(msg)
msg.reactions.removeAll().catch(error => console.error('Failed to clear reactions:', error));
break;
case '⏹️':
leave(msg)
msg.reactions.removeAll().catch(error => console.error('Failed to clear reactions:', error));
break;
case '⏭️':
skip(msg)
msg.reactions.removeAll().catch(error => console.error('Failed to clear reactions:', error));
break;
}
})
}, 500)) //delay because .then is not waiting for react to finish sending
//todo dodaj pause tako sto ces da colllectujes vise reakcija a ne samo prvu
.catch(() => {
msg.reactions.removeAll().catch(error => console.error('Failed to clear reactions:', error));
})
});
}
module.exports = {
currentlyplaying : playing
}