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

Commit 0a4d0ae

Browse files
Implemented register command
1 parent 32167c1 commit 0a4d0ae

File tree

8 files changed

+88
-2
lines changed

8 files changed

+88
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ MumbleDJ Changelog
33

44
### July 10, 2016 -- `v3.1.0`
55
* 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.
6+
* Added `!register` command for registering the bot on the server.
67

78
### July 1, 2016 -- `v3.0.11`
89
* Potential fix for an issue with IP SANs on PEM certs.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ Keep in mind that values that contain commas (such as `"SuperUser,Matt"`) will b
252252
* __Admin-only by default__: No
253253
* __Example__: `!pause`
254254

255+
### register
256+
* __Description__: Registers the bot on the server.
257+
* __Default Aliases__: register, reg
258+
* __Arguments__: None
259+
* __Admin-only by default__: Yes
260+
* __Example__: `!register`
261+
255262
### reload
256263
* __Description__: Reloads the configuration file.
257264
* __Default Aliases__: reload, r

bindata.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bot/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ func SetDefaultConfig() {
157157
viper.SetDefault("commands.pause.messages.no_audio_error", "Either the audio is already paused, or there are no tracks in the queue.")
158158
viper.SetDefault("commands.pause.messages.paused", "<b>%s</b> has paused audio playback.")
159159

160+
viper.SetDefault("commands.register.aliases", []string{"register", "reg"})
161+
viper.SetDefault("commands.register.is_admin", true)
162+
viper.SetDefault("commands.register.description", "Registers the bot on the server.")
163+
viper.SetDefault("commands.register.messages.already_registered_error", "I am already registered on the server.")
164+
viper.SetDefault("commands.register.messages.registered", "I am now registered on the server.")
165+
160166
viper.SetDefault("commands.reload.aliases", []string{"reload", "r"})
161167
viper.SetDefault("commands.reload.is_admin", true)
162168
viper.SetDefault("commands.reload.description", "Reloads the configuration file.")

commands/pkg_init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func init() {
3535
new(NumCachedCommand),
3636
new(NumTracksCommand),
3737
new(PauseCommand),
38+
new(RegisterCommand),
3839
new(ReloadCommand),
3940
new(ResetCommand),
4041
new(ResumeCommand),

commands/register.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* MumbleDJ
3+
* By Matthieu Grieger
4+
* commands/register.go
5+
* Copyright (c) 2016 Matthieu Grieger (MIT License)
6+
*/
7+
8+
package commands
9+
10+
import (
11+
"errors"
12+
13+
"github.com/layeh/gumble/gumble"
14+
"github.com/spf13/viper"
15+
)
16+
17+
// RegisterCommand is a command that registers the bot on the server.
18+
type RegisterCommand struct{}
19+
20+
// Aliases returns the current aliases for the command.
21+
func (c *RegisterCommand) Aliases() []string {
22+
return viper.GetStringSlice("commands.register.aliases")
23+
}
24+
25+
// Description returns the description for the command.
26+
func (c *RegisterCommand) Description() string {
27+
return viper.GetString("commands.register.description")
28+
}
29+
30+
// IsAdminCommand returns true if the command is only for admin use, and
31+
// returns false otherwise.
32+
func (c *RegisterCommand) IsAdminCommand() bool {
33+
return viper.GetBool("commands.register.is_admin")
34+
}
35+
36+
// Execute executes the command with the given user and arguments.
37+
// Return value descriptions:
38+
// string: A message to be returned to the user upon successful execution.
39+
// bool: Whether the message should be private or not. true = private,
40+
// false = public (sent to whole channel).
41+
// error: An error message to be returned upon unsuccessful execution.
42+
// If no error has occurred, pass nil instead.
43+
// Example return statement:
44+
// return "This is a private message!", true, nil
45+
func (c *RegisterCommand) Execute(user *gumble.User, args ...string) (string, bool, error) {
46+
if DJ.Client.Self.IsRegistered() {
47+
return "", true, errors.New(viper.GetString("commands.register.messages.already_registered_error"))
48+
}
49+
50+
DJ.Client.Self.Register()
51+
52+
return viper.GetString("commands.register.messages.registered"), true, nil
53+
}

commands/register_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* MumbleDJ
3+
* By Matthieu Grieger
4+
* commands/register_test.go
5+
* Copyright (c) 2016 Matthieu Grieger (MIT License)
6+
*/
7+
8+
package commands

config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ commands:
306306
no_audio_error: "Either the audio is already paused, or there are no tracks in the queue."
307307
paused: "<b>%s</b> has paused audio playback."
308308

309+
register:
310+
aliases:
311+
- "register"
312+
- "reg"
313+
is_admin: true
314+
description: "Registers the bot on the server."
315+
messages:
316+
already_registered_error: "I am already registered on the server."
317+
registered: "I am now registered on the server."
318+
309319
reload:
310320
aliases:
311321
- "reload"

0 commit comments

Comments
 (0)