Skip to content

Commit

Permalink
✨ Add back command
Browse files Browse the repository at this point in the history
  • Loading branch information
Androz2091 committed Jan 3, 2021
1 parent 79f8d6f commit 3f87609
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 15 deletions.
106 changes: 106 additions & 0 deletions commands/Music/back.js
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;
31 changes: 16 additions & 15 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ Here's the list of Atlanta commands. This one contains more than **110 commands*
| **unmute** | Unmute the mentioned member! | unmute [@member] | 3 seconds |
| **warn** | Warn a member in private messages | warn [@member] [reason] | 3 seconds |

### Music (11 commands)

| Name | Description | Usage | Cooldown |
| ----------- | ------------------------------------------------- | ------------------ | --------- |
| **back** | DESCRIPTION | USAGE | 5 seconds |
| **filter** | Enable or disable a filter! | filter [filter] | 5 seconds |
| **filters** | Send the list of all the filters and their status | filters | 5 seconds |
| **lyrics** | Shows the song lyrics | lyrics [song-name] | 5 seconds |
| **np** | Shows information about the current song! | np | 5 seconds |
| **pause** | Pause the current song! | pause | 5 seconds |
| **play** | Plays music for you! | play [song] | 5 seconds |
| **queue** | Shows the server queue | queue | 5 seconds |
| **resume** | Resume the current song! | resume | 5 seconds |
| **skip** | Skip the current song | skip | 5 seconds |
| **stop** | Stop the music | stop | 5 seconds |

### Fun (10 commands)

| Name | Description | Usage | Cooldown |
Expand All @@ -135,21 +151,6 @@ Here's the list of Atlanta commands. This one contains more than **110 commands*
*This is a fun command, not to be taken seriously* | lovecalc [@member1] (@member2) | 1 seconds |
| **number** | Find the right number! | number | 5 seconds |

### Music (10 commands)

| Name | Description | Usage | Cooldown |
| ----------- | ------------------------------------------------- | ------------------ | --------- |
| **filter** | Enable or disable a filter! | filter [filter] | 5 seconds |
| **filters** | Send the list of all the filters and their status | filters | 5 seconds |
| **lyrics** | Shows the song lyrics | lyrics [song-name] | 5 seconds |
| **np** | Shows information about the current song! | np | 5 seconds |
| **pause** | Pause the current song! | pause | 5 seconds |
| **play** | Plays music for you! | play [song] | 5 seconds |
| **queue** | Shows the server queue | queue | 5 seconds |
| **resume** | Resume the current song! | resume | 5 seconds |
| **skip** | Skip the current song | skip | 5 seconds |
| **stop** | Stop the music | stop | 5 seconds |

### Owner (3 commands)

| Name | Description | Usage | Cooldown |
Expand Down
8 changes: 8 additions & 0 deletions languages/en-US/music/back.json
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!"
}

0 comments on commit 3f87609

Please sign in to comment.