Skip to content

Commit

Permalink
Added command to rename sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
markokajzer committed Dec 28, 2016
1 parent 9b16c06 commit 5d7f4fe
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 0.4.0 (2016-11-07)
## 0.5.0 (2016-12-29)

+ Added `!rename` command

## 0.4.0 (2016-12-23)

+ Added `!add` command which saves an attached .mp3 file and adds it to sounds

Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ Click on the link and allow your bot to join one of your Discord servers.
Type `!commands` to print the following list of available commands.

```
!commands Show this message
!sounds Show available sounds
!mostplayed Show 15 most used sounds
!<sound> Play the specified sound
!random Play random sounds
!stop Stop playing and clear queue
!add Add the attached sound
!remove <sound> Remove specified sound
!commands Show this message
!sounds Show available sounds
!mostplayed Show 15 most used sounds
!<sound> Play the specified sound
!random Play random sounds
!stop Stop playing and clear queue
!add Add the attached sound
!rename <old> <new> Rename specified sound
!remove <sound> Remove specified sound
```

### Adding sounds
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dicord_soundbot",
"version": "0.4.0",
"version": "0.5.0",
"description": "A Discord Bot to play sounds",
"main": "bot.js",
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions src/MessageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class MessageHandler {
} else if (message.content.startsWith('!remove ')) {
const sound = message.content.replace('!remove ', '');
Util.removeSound(sound, message.channel);
} else if (message.content.startsWith('!rename ')) {
const [oldsound, newsound] = message.content.replace('!rename ', '').split(' ');
Util.renameSound(oldsound, newsound, message.channel);
} else {
const sounds = Util.getSounds();
if (message.content === '!sounds') {
Expand Down
28 changes: 20 additions & 8 deletions src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ class Util {
commandsList() {
return [
'```',
'!commands Show this message',
'!sounds Show available sounds',
'!mostplayed Show 15 most used sounds',
'!<sound> Play the specified sound',
'!random Play random sound',
'!stop Stop playing and clear queue',
'!add Add the attached sound',
'!remove <sound> Remove specified sound',
'!commands Show this message',
'!sounds Show available sounds',
'!mostplayed Show 15 most used sounds',
'!<sound> Play the specified sound',
'!random Play random sound',
'!stop Stop playing and clear queue',
'!add Add the attached sound',
'!rename <old> <new> Rename specified sound',
'!remove <sound> Remove specified sound',
'```'
].join('\n');
}
Expand Down Expand Up @@ -86,6 +87,17 @@ class Util {
});
}

renameSound(oldName, newName, channel) {
const oldFile = `sounds/${oldName}.mp3`;
const newFile = `sounds/${newName}.mp3`;
try {
fs.renameSync(oldFile, newFile);
channel.sendMessage(`${oldName} renamed to ${newName}!`);
} catch (error) {
channel.sendMessage(`${oldName} not found!`);
}
}

removeSound(sound, channel) {
const file = `sounds/${sound}.mp3`;
try {
Expand Down

0 comments on commit 5d7f4fe

Please sign in to comment.