From 5d7f4fecbae6d48c8d763be2aac3186c46e1f209 Mon Sep 17 00:00:00 2001 From: markokajzer Date: Thu, 29 Dec 2016 04:28:55 +0900 Subject: [PATCH] Added command to rename sounds --- CHANGELOG.md | 6 +++++- README.md | 17 +++++++++-------- package.json | 2 +- src/MessageHandler.js | 3 +++ src/Util.js | 28 ++++++++++++++++++++-------- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc6accf5..b18eb958 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 94d8781c..96280b5f 100644 --- a/README.md +++ b/README.md @@ -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 -! Play the specified sound -!random Play random sounds -!stop Stop playing and clear queue -!add Add the attached sound -!remove Remove specified sound +!commands Show this message +!sounds Show available sounds +!mostplayed Show 15 most used sounds +! Play the specified sound +!random Play random sounds +!stop Stop playing and clear queue +!add Add the attached sound +!rename Rename specified sound +!remove Remove specified sound ``` ### Adding sounds diff --git a/package.json b/package.json index 0a7898b7..6530df84 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/MessageHandler.js b/src/MessageHandler.js index 2d412aea..c4f3b635 100644 --- a/src/MessageHandler.js +++ b/src/MessageHandler.js @@ -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') { diff --git a/src/Util.js b/src/Util.js index 51f17c08..eb0c1a68 100644 --- a/src/Util.js +++ b/src/Util.js @@ -18,14 +18,15 @@ class Util { commandsList() { return [ '```', - '!commands Show this message', - '!sounds Show available sounds', - '!mostplayed Show 15 most used sounds', - '! Play the specified sound', - '!random Play random sound', - '!stop Stop playing and clear queue', - '!add Add the attached sound', - '!remove Remove specified sound', + '!commands Show this message', + '!sounds Show available sounds', + '!mostplayed Show 15 most used sounds', + '! Play the specified sound', + '!random Play random sound', + '!stop Stop playing and clear queue', + '!add Add the attached sound', + '!rename Rename specified sound', + '!remove Remove specified sound', '```' ].join('\n'); } @@ -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 {