|
| 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 | +} |
0 commit comments