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

Commit fa232ff

Browse files
committed
Helped events.go complexity
1 parent 0355a54 commit fa232ff

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

internal/bot/events.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ func (bot *Bot) onMessage(_ *dg.Session, msg *dg.MessageCreate) {
5252

5353
// args = [<prefix>, <sub-command>]
5454
args := strings.Fields(msg.Content)
55-
isAdmin := bot.isAdmin(msg.Member)
56-
// whether they attempted to run an administrator related command
57-
adminAttempt := false
5855

5956
if len(args) < 2 {
6057
return
@@ -75,32 +72,45 @@ func (bot *Bot) onMessage(_ *dg.Session, msg *dg.MessageCreate) {
7572
bot.client, msg.Message,
7673
strings.Replace(commands, "{prefix}", bot.config.Prefix, -1),
7774
)
75+
default:
76+
bot.onAdminCommand(msg.Message, args)
77+
}
78+
}
79+
80+
func (bot *Bot) onAdminCommand(msg *dg.Message, args []string) {
81+
isAdmin := bot.isAdmin(msg.Member)
82+
83+
// whether they attempted to run an administrator related command
84+
adminAttempt := false
85+
86+
switch args[1] {
7887
/* Administrator Commands */
7988
case "status":
8089
if isAdmin {
81-
bot.cmdStatus(msg.Message)
90+
bot.cmdStatus(msg)
8291
} else {
8392
adminAttempt = true
8493
}
8594
case "lock":
8695
if isAdmin {
8796
bot.locked = true
88-
_, _ = util.Reply(bot.client, msg.Message, "Maintenance mode is now on.")
97+
_, _ = util.Reply(bot.client, msg, "Maintenance mode is now on.")
8998
} else {
9099
adminAttempt = true
91100
}
92101
case "unlock":
93102
if isAdmin {
94103
bot.locked = false
95-
_, _ = util.Reply(bot.client, msg.Message, "Maintenance mode is now off.")
104+
_, _ = util.Reply(bot.client, msg, "Maintenance mode is now off.")
96105
} else {
97106
adminAttempt = true
98107
}
99108
default:
100-
_, _ = util.Reply(bot.client, msg.Message, bot.config.Help)
109+
_, _ = util.Reply(bot.client, msg, bot.config.Help)
101110
}
111+
102112
if adminAttempt {
103-
_, _ = util.Reply(bot.client, msg.Message,
113+
_, _ = util.Reply(bot.client, msg,
104114
"You must be an administrator to run this command.",
105115
)
106116
}

0 commit comments

Comments
 (0)