Skip to content

Commit

Permalink
Added possibilty to automatically remove sound request messages
Browse files Browse the repository at this point in the history
  • Loading branch information
markokajzer committed Feb 27, 2017
1 parent fb515ae commit 7636ca4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 0.6.0 (2017-02-26)
## 0.7.0 (2017-02-27)

+ Added possibility to delete `!<sound>` messages after playthrough.

## 0.6.0 (2017-02-27)

+ Made accepted file formats configurable. ([`#3`](https://github.com/markokajzer/discord-soundbot/issues/3))
+ Made accepted file size configurable.
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,12 @@ All sounds will be added to a queue and played in succession. To halt the playba
### Removing sounds

You can delete sounds by typing `!remove <sound>`. The bot will respond with the status of the deletion in the channel of the message.


## Configuration

You can configure the accepted file formats (via the `extensions` array) as well as the size of the accepted files (via the `size` given in bytes).

The bot can also automatically delete `!<sound>` messages for you to reduce channel spam. For this, set `deleteMessages` to `true`.

Check `config/default-example.json` for an example config.
3 changes: 2 additions & 1 deletion config/default-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"client_id": "YOUR_CLIENT/APPLICATION_ID",
"token": "YOUR_APP_BOT_USER_TOKEN",
"extensions": [".mp3", ".wav"],
"size": 1000000
"size": 1000000,
"deleteMessages": false
}
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.6.0",
"version": "0.7.0",
"description": "A Discord Bot to play sounds",
"main": "bot.js",
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/MessageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class MessageHandler {
this.bot.queue = [];
} else if (message.content === '!random') {
const random = sounds[Math.floor(Math.random() * sounds.length)];
this.bot.addToQueue(voiceChannel, random);
this.bot.addToQueue(voiceChannel.id, random, message);
} else {
const sound = message.content.split('!')[1];
if (sounds.includes(sound)) {
this.bot.addToQueue(voiceChannel, sound);
this.bot.addToQueue(voiceChannel.id, sound, message);
if (this.bot.voiceConnections.array().length === 0) this.bot.playSoundQueue();
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/SoundBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class SoundBot extends Discord.Client {
this.messageHandler.handle(message);
}

addToQueue(voiceChannel, sound) {
this.queue.push({ name: sound, channel: voiceChannel.id });
addToQueue(voiceChannel, sound, messageTrigger) {
this.queue.push({ name: sound, channel: voiceChannel, message: messageTrigger });
}

playSoundQueue() {
Expand All @@ -41,6 +41,8 @@ class SoundBot extends Discord.Client {
const dispatcher = connection.playFile(file);
dispatcher.on('end', () => {
Util.updateCount(nextSound.name);
if (config.get('deleteMessages') === true)
nextSound.message.delete();

if (this.queue.length > 0)
this.playSoundQueue();
Expand Down

0 comments on commit 7636ca4

Please sign in to comment.