Skip to content

Commit

Permalink
Added prefix as a configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
markokajzer committed Sep 9, 2017
1 parent 61c1f63 commit d7ec554
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ rules:

no-case-declarations:
- off

no-param-reassign:
- error
- props: false
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.0 (2017-09-11)

+ Added prefix configuration

## 0.9.0 (2017-09-10)

+ Added ignoring of users via ID
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ Users can be ignore from using **any** command by the `!ignore <user>` command w

## Configuration

The bots prefix can be configured via `prefix`.

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 and create a new file `default.json` with your desired configuration inside the `config` folder.

To add an avatar to your bot, add a file called `avatar.png` to the `config/` folder and restart the bot. To remove the avatar, delete `avatar.png` and restart the bot.

Check `config/default-example.json` for an example config and create a new file `default.json` with your desired configuration inside the `config` folder.
1 change: 1 addition & 0 deletions config/default-example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"client_id": "YOUR_CLIENT/APPLICATION_ID",
"token": "YOUR_APP_BOT_USER_TOKEN",
"prefix": "!",
"extensions": [".mp3", ".wav"],
"size": 1000000,
"deleteMessages": false
Expand Down
28 changes: 16 additions & 12 deletions src/SoundBot.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class SoundBot extends Discord.Client {
constructor() {
super();

this.prefix = config.get('prefix');
this.queue = [];
this._addEventListeners();
}
Expand All @@ -22,8 +23,10 @@ class SoundBot extends Discord.Client {

_messageListener(message) {
if (message.channel instanceof Discord.DMChannel) return; // Abort when DM
if (!message.content.startsWith('!')) return; // Abort when not prefix
if (!message.content.startsWith(this.prefix)) return; // Abort when not prefix
if (Util.userIgnored(message.author.id)) return;

message.content = message.content.substring(this.prefix.length);
this.handle(message);
}

Expand All @@ -34,28 +37,28 @@ class SoundBot extends Discord.Client {
handle(message) {
const [command, ...input] = message.content.split(' ');
switch (command) {
case '!commands':
case 'commands':
message.author.send(Util.getListOfCommands());
break;
case '!sounds':
case 'sounds':
message.author.send(Util.getSounds().map(sound => sound));
break;
case '!mostplayed':
case 'mostplayed':
message.channel.send(Util.getMostPlayedSounds());
break;
case '!add':
case 'add':
if (message.attachments) Util.addSounds(message.attachments, message.channel);
break;
case '!rename':
case 'rename':
Util.renameSound(input, message.channel);
break;
case '!remove':
case 'remove':
Util.removeSound(input, message.channel);
break;
case '!ignore':
case 'ignore':
Util.ignoreUser(input, message);
break;
case '!unignore':
case 'unignore':
Util.unignoreUser(input, message);
break;
default:
Expand All @@ -74,16 +77,17 @@ class SoundBot extends Discord.Client {
}

switch (message.content) {
case '!stop':
case 'stop':
voiceChannel.leave();
this.queue = [];
break;
case '!random':
case 'random':
const random = sounds[Math.floor(Math.random() * sounds.length)];
this.addToQueue(voiceChannel.id, random, message);
break;
default:
const sound = message.content.substring(1);
const sound = message.content;
console.log(sound);
if (sounds.includes(sound)) {
this.addToQueue(voiceChannel.id, sound, message);
if (!this._currentlyPlaying()) this.playSoundQueue();
Expand Down
24 changes: 13 additions & 11 deletions src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,19 @@ class Util {
getListOfCommands() {
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',
'!rename <old> <new> Rename specified sound',
'!remove <sound> Remove specified sound',
'!ignore <user> Ignore specified user',
'!unignore <user> Unignore specified user',
`Use the prefix "${config.get('prefix')}" with the following commands:`,
'',
'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',
'ignore <user> Ignore specified user',
'unignore <user> Unignore specified user',
'```'
].join('\n');
}
Expand Down

0 comments on commit d7ec554

Please sign in to comment.