-
-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79f8d6f
commit 3f87609
Showing
3 changed files
with
130 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
const Command = require("../../base/Command.js"), | ||
Discord = require("discord.js"); | ||
|
||
class Back extends Command { | ||
|
||
constructor (client) { | ||
super(client, { | ||
name: "back", | ||
dirname: __dirname, | ||
enabled: true, | ||
guildOnly: true, | ||
aliases: [ "previous" ], | ||
memberPermissions: [], | ||
botPermissions: [ "SEND_MESSAGES", "EMBED_LINKS" ], | ||
nsfw: false, | ||
ownerOnly: false, | ||
cooldown: 5000 | ||
}); | ||
} | ||
|
||
async run (message, args, data) { | ||
|
||
const queue = this.client.player.getQueue(message); | ||
|
||
const voice = message.member.voice.channel; | ||
if (!voice){ | ||
return message.error("music/play:NO_VOICE_CHANNEL"); | ||
} | ||
|
||
if(!queue){ | ||
return message.error("music/play:NOT_PLAYING"); | ||
} | ||
|
||
if(!queue.previousTracks[0]){ | ||
return message.error("music/back:NO_PREV_SONG"); | ||
} | ||
|
||
const members = voice.members.filter((m) => !m.user.bot); | ||
|
||
const embed = new Discord.MessageEmbed() | ||
.setAuthor(message.translate("music/back:DESCRIPTION")) | ||
.setThumbnail(queue.tracks[0].thumbnail) | ||
.setFooter(data.config.embed.footer) | ||
.setColor(data.config.embed.color); | ||
|
||
const m = await message.channel.send(embed); | ||
|
||
if(members.size > 1){ | ||
|
||
m.react("👍"); | ||
|
||
const mustVote = Math.floor(members.size/2+1); | ||
|
||
embed.setDescription(message.translate("music/back:VOTE_CONTENT", { | ||
songName: queue.tracks[0].name, | ||
voteCount: 0, | ||
requiredCount: mustVote | ||
})); | ||
m.edit(embed); | ||
|
||
const filter = (reaction, user) => { | ||
const member = message.guild.members.cache.get(user.id); | ||
const voiceChannel = member.voice.channel; | ||
if(voiceChannel){ | ||
return voiceChannel.id === voice.id; | ||
} | ||
}; | ||
|
||
const collector = await m.createReactionCollector(filter, { | ||
time: 25000 | ||
}); | ||
|
||
collector.on("collect", (reaction) => { | ||
const haveVoted = reaction.count-1; | ||
if(haveVoted >= mustVote){ | ||
this.client.player.back(message); | ||
embed.setDescription(message.translate("music/back:SUCCESS")); | ||
m.edit(embed); | ||
collector.stop(true); | ||
} else { | ||
embed.setDescription(message.translate("music/back:VOTE_CONTENT", { | ||
songName: queue.tracks[0].title, | ||
voteCount: haveVoted, | ||
requiredCount: mustVote | ||
})); | ||
m.edit(embed); | ||
} | ||
}); | ||
|
||
collector.on("end", (collected, isDone) => { | ||
if(!isDone){ | ||
return message.error("misc:TIMES_UP"); | ||
} | ||
}); | ||
|
||
} else { | ||
this.client.player.back(message); | ||
embed.setDescription(message.translate("music/back:SUCCESS")); | ||
m.edit(embed); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
module.exports = Back; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"DESCRIPTION": "Play back the previous song", | ||
"USAGE": "{{prefix}}back", | ||
"EXAMPLES": "{{prefix}}back", | ||
"NO_NEXT_SONG": "There was no song before this one!", | ||
"VOTE_CONTENT": "Previous song: {{songName}}\nReact with 👍 to play the previous song! {{requiredCount}} more votes are required.", | ||
"SUCCESS": "Playing previous song!" | ||
} |