Skip to content

Commit

Permalink
Added lastadded command
Browse files Browse the repository at this point in the history
  • Loading branch information
markokajzer committed Dec 20, 2017
1 parent 4c5dcea commit 8c24798
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ rules:
no-param-reassign:
- error
- props: false

arrow-body-style:
- error
- as-needed
- requireReturnForObjectLiteral: true
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.12.0 (2017-12-20)

+ Added `lastadded` command

## 0.11.0 (2017-12-20)

+ Added `stayInChannel` configuration option
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Type `!commands` to print the following list of available commands.
!commands Show this message
!sounds Show available sounds
!mostplayed Show 15 most used sounds
!lastadded Show 5 last added sounds
!<sound> Play the specified sound
!random Play random sounds
!stop Stop playing and clear queue
Expand Down
3 changes: 3 additions & 0 deletions src/SoundBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class SoundBot extends Discord.Client {
case 'mostplayed':
message.channel.send(Util.getMostPlayedSounds());
break;
case 'lastadded':
message.channel.send(['```', ...Util.lastAdded(), '```'].join('\n'));
break;
case 'add':
if (message.attachments) Util.addSounds(message.attachments, message.channel);
break;
Expand Down
19 changes: 18 additions & 1 deletion src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class Util {
_getSoundsWithExtension() {
const files = fs.readdirSync('sounds/');
let sounds = files.filter(sound => config.get('extensions').some(ext => sound.endsWith(ext)));
sounds = sounds.map(sound => ({ name: sound.split('.')[0], extension: sound.split('.')[1] }));
sounds = sounds.map((sound) => {
return { name: sound.split('.')[0], extension: sound.split('.')[1] };
});
return sounds;
}

Expand All @@ -49,6 +51,7 @@ class Util {
'commands Show this message',
'sounds Show available sounds',
'mostplayed Show 15 most used sounds',
'lastadded Show 5 last added sounds',
'<sound> Play the specified sound',
'random Play random sound',
'stop Stop playing and clear queue',
Expand Down Expand Up @@ -116,6 +119,20 @@ class Util {
}).on('error', () => channel.send('Something went wrong!'));
}

lastAdded() {
let sounds = this._getSoundsWithExtension();
sounds = sounds.map((sound) => {
return {
name: sound.name,
creation: fs.statSync(this.getPathForSound(sound.name)).birthtime
};
});
sounds = sounds.sort((a, b) => new Date(b.creation) - new Date(a.creation));
sounds = sounds.slice(0, 5);
return sounds.map(sound => sound.name);
}


renameSound(input, channel) {
if (input.length !== 2) {
channel.send(this.usage.rename);
Expand Down

0 comments on commit 8c24798

Please sign in to comment.