Skip to content
This repository has been archived by the owner on Jan 20, 2021. It is now read-only.

Commit

Permalink
Implemented register command
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieugrieger committed Jul 11, 2016
1 parent 32167c1 commit 0a4d0ae
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ MumbleDJ Changelog

### July 10, 2016 -- `v3.1.0`
* File path for user `p12` certificate can now be provided for authenticating as a registered user via the `--p12` commandline flag or the `connection.user_p12` configuration value.
* Added `!register` command for registering the bot on the server.

### July 1, 2016 -- `v3.0.11`
* Potential fix for an issue with IP SANs on PEM certs.
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ Keep in mind that values that contain commas (such as `"SuperUser,Matt"`) will b
* __Admin-only by default__: No
* __Example__: `!pause`

### register
* __Description__: Registers the bot on the server.
* __Default Aliases__: register, reg
* __Arguments__: None
* __Admin-only by default__: Yes
* __Example__: `!register`

### reload
* __Description__: Reloads the configuration file.
* __Default Aliases__: reload, r
Expand Down
4 changes: 2 additions & 2 deletions bindata.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions bot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ func SetDefaultConfig() {
viper.SetDefault("commands.pause.messages.no_audio_error", "Either the audio is already paused, or there are no tracks in the queue.")
viper.SetDefault("commands.pause.messages.paused", "<b>%s</b> has paused audio playback.")

viper.SetDefault("commands.register.aliases", []string{"register", "reg"})
viper.SetDefault("commands.register.is_admin", true)
viper.SetDefault("commands.register.description", "Registers the bot on the server.")
viper.SetDefault("commands.register.messages.already_registered_error", "I am already registered on the server.")
viper.SetDefault("commands.register.messages.registered", "I am now registered on the server.")

viper.SetDefault("commands.reload.aliases", []string{"reload", "r"})
viper.SetDefault("commands.reload.is_admin", true)
viper.SetDefault("commands.reload.description", "Reloads the configuration file.")
Expand Down
1 change: 1 addition & 0 deletions commands/pkg_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func init() {
new(NumCachedCommand),
new(NumTracksCommand),
new(PauseCommand),
new(RegisterCommand),
new(ReloadCommand),
new(ResetCommand),
new(ResumeCommand),
Expand Down
53 changes: 53 additions & 0 deletions commands/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* MumbleDJ
* By Matthieu Grieger
* commands/register.go
* Copyright (c) 2016 Matthieu Grieger (MIT License)
*/

package commands

import (
"errors"

"github.com/layeh/gumble/gumble"
"github.com/spf13/viper"
)

// RegisterCommand is a command that registers the bot on the server.
type RegisterCommand struct{}

// Aliases returns the current aliases for the command.
func (c *RegisterCommand) Aliases() []string {
return viper.GetStringSlice("commands.register.aliases")
}

// Description returns the description for the command.
func (c *RegisterCommand) Description() string {
return viper.GetString("commands.register.description")
}

// IsAdminCommand returns true if the command is only for admin use, and
// returns false otherwise.
func (c *RegisterCommand) IsAdminCommand() bool {
return viper.GetBool("commands.register.is_admin")
}

// Execute executes the command with the given user and arguments.
// Return value descriptions:
// string: A message to be returned to the user upon successful execution.
// bool: Whether the message should be private or not. true = private,
// false = public (sent to whole channel).
// error: An error message to be returned upon unsuccessful execution.
// If no error has occurred, pass nil instead.
// Example return statement:
// return "This is a private message!", true, nil
func (c *RegisterCommand) Execute(user *gumble.User, args ...string) (string, bool, error) {
if DJ.Client.Self.IsRegistered() {
return "", true, errors.New(viper.GetString("commands.register.messages.already_registered_error"))
}

DJ.Client.Self.Register()

return viper.GetString("commands.register.messages.registered"), true, nil
}
8 changes: 8 additions & 0 deletions commands/register_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* MumbleDJ
* By Matthieu Grieger
* commands/register_test.go
* Copyright (c) 2016 Matthieu Grieger (MIT License)
*/

package commands
10 changes: 10 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,16 @@ commands:
no_audio_error: "Either the audio is already paused, or there are no tracks in the queue."
paused: "<b>%s</b> has paused audio playback."

register:
aliases:
- "register"
- "reg"
is_admin: true
description: "Registers the bot on the server."
messages:
already_registered_error: "I am already registered on the server."
registered: "I am now registered on the server."

reload:
aliases:
- "reload"
Expand Down

0 comments on commit 0a4d0ae

Please sign in to comment.