Implemented register command

This commit is contained in:
Matthieu Grieger 2016-07-10 21:09:54 -07:00
parent 32167c1294
commit 0a4d0aead1
8 changed files with 88 additions and 2 deletions

View file

@ -3,6 +3,7 @@ MumbleDJ Changelog
### July 10, 2016 -- `v3.1.0` ### 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. * 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` ### July 1, 2016 -- `v3.0.11`
* Potential fix for an issue with IP SANs on PEM certs. * Potential fix for an issue with IP SANs on PEM certs.

View file

@ -252,6 +252,13 @@ Keep in mind that values that contain commas (such as `"SuperUser,Matt"`) will b
* __Admin-only by default__: No * __Admin-only by default__: No
* __Example__: `!pause` * __Example__: `!pause`
### register
* __Description__: Registers the bot on the server.
* __Default Aliases__: register, reg
* __Arguments__: None
* __Admin-only by default__: Yes
* __Example__: `!register`
### reload ### reload
* __Description__: Reloads the configuration file. * __Description__: Reloads the configuration file.
* __Default Aliases__: reload, r * __Default Aliases__: reload, r

File diff suppressed because one or more lines are too long

View file

@ -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.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.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.aliases", []string{"reload", "r"})
viper.SetDefault("commands.reload.is_admin", true) viper.SetDefault("commands.reload.is_admin", true)
viper.SetDefault("commands.reload.description", "Reloads the configuration file.") viper.SetDefault("commands.reload.description", "Reloads the configuration file.")

View file

@ -35,6 +35,7 @@ func init() {
new(NumCachedCommand), new(NumCachedCommand),
new(NumTracksCommand), new(NumTracksCommand),
new(PauseCommand), new(PauseCommand),
new(RegisterCommand),
new(ReloadCommand), new(ReloadCommand),
new(ResetCommand), new(ResetCommand),
new(ResumeCommand), new(ResumeCommand),

53
commands/register.go Normal file
View file

@ -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
}

View file

@ -0,0 +1,8 @@
/*
* MumbleDJ
* By Matthieu Grieger
* commands/register_test.go
* Copyright (c) 2016 Matthieu Grieger (MIT License)
*/
package commands

View file

@ -306,6 +306,16 @@ commands:
no_audio_error: "Either the audio is already paused, or there are no tracks in the queue." 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." 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: reload:
aliases: aliases:
- "reload" - "reload"