Move variable delcaration, error checking ode and update code of the sta<tus command into the correct place
@@ -57,12 +57,13 @@ func statusToString(status discordgo.Status) string {
// Execute runs the command piping its output into the supplied writer.
func (status *Status) Execute(writer io.Writer, parameters []string) {
- var settingStatusError error
- var updatedSettings *discordgo.Settings
if len(parameters) == 0 {
fmt.Fprintf(writer, "Current status: %s \n", statusToString(status.session.State.Settings.Status))
} else if len(parameters) == 1 {
+ var settingStatusError error
+ var updatedSettings *discordgo.Settings
+
switch strings.ToLower(parameters[0]) {
case "online", "available":
updatedSettings, settingStatusError = status.session.UserUpdateStatus(discordgo.StatusOnline)
@@ -75,9 +76,6 @@ func (status *Status) Execute(writer io.Writer, parameters []string) {
default:
status.PrintHelp(writer)
}
- } else {
- status.PrintHelp(writer)
- }
if settingStatusError != nil {
fmt.Fprintf(writer, "Error setting status: '%s'\n", settingStatusError.Error())
@@ -85,6 +83,10 @@ func (status *Status) Execute(writer io.Writer, parameters []string) {
fmt.Fprintf(writer, "Setting status to '%s'\n", statusToString(updatedSettings.Status))
status.session.State.Settings = updatedSettings
}
+ } else {
+ status.PrintHelp(writer)
+ }
+
}
// Name represents this commands indentifier.
