Commands for everyone
This commit is contained in:
@ -13,6 +13,7 @@ import (
|
|||||||
func setupCommands() {
|
func setupCommands() {
|
||||||
reboot := Command{
|
reboot := Command{
|
||||||
Name: "Reboot",
|
Name: "Reboot",
|
||||||
|
RequiresAdmin: true,
|
||||||
Help: "Reboot me, requires token from logs.",
|
Help: "Reboot me, requires token from logs.",
|
||||||
Keywords: []string{"reboot", "re", "restart"},
|
Keywords: []string{"reboot", "re", "restart"},
|
||||||
Exec: Reboot,
|
Exec: Reboot,
|
||||||
@ -21,6 +22,7 @@ func setupCommands() {
|
|||||||
|
|
||||||
bumpset := Command{
|
bumpset := Command{
|
||||||
Name: "BumpSet",
|
Name: "BumpSet",
|
||||||
|
RequiresAdmin: true,
|
||||||
Help: "Set the bump timer (requires time in minutes until next bump).",
|
Help: "Set the bump timer (requires time in minutes until next bump).",
|
||||||
Keywords: []string{"bs", "bumpset", "bumps"},
|
Keywords: []string{"bs", "bumpset", "bumps"},
|
||||||
Exec: BumpSet,
|
Exec: BumpSet,
|
||||||
@ -29,6 +31,7 @@ func setupCommands() {
|
|||||||
|
|
||||||
retrieveVerification := Command{
|
retrieveVerification := Command{
|
||||||
Name: "Retrieve Verification",
|
Name: "Retrieve Verification",
|
||||||
|
RequiresAdmin: true,
|
||||||
Help: "Retrieve verification either by discord ID or by nickname",
|
Help: "Retrieve verification either by discord ID or by nickname",
|
||||||
Keywords: []string{"veri", "verification", "retrieve"},
|
Keywords: []string{"veri", "verification", "retrieve"},
|
||||||
Exec: RetrieveVerification,
|
Exec: RetrieveVerification,
|
||||||
@ -37,6 +40,7 @@ func setupCommands() {
|
|||||||
|
|
||||||
addQuote := Command{
|
addQuote := Command{
|
||||||
Name: "Add Quote",
|
Name: "Add Quote",
|
||||||
|
RequiresAdmin: true,
|
||||||
Keywords: []string{"quote", "addq", "q"},
|
Keywords: []string{"quote", "addq", "q"},
|
||||||
Exec: AddQuote,
|
Exec: AddQuote,
|
||||||
}
|
}
|
||||||
@ -51,6 +55,7 @@ func setupCommands() {
|
|||||||
|
|
||||||
status := Command{
|
status := Command{
|
||||||
Name: "Status",
|
Name: "Status",
|
||||||
|
RequiresAdmin: true,
|
||||||
Keywords: []string{"st", "status", "stats"},
|
Keywords: []string{"st", "status", "stats"},
|
||||||
Exec: Status,
|
Exec: Status,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,15 +52,23 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
if time.Since(config.BumpTime) > 2*time.Hour {
|
if time.Since(config.BumpTime) > 2*time.Hour {
|
||||||
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%+v please say \"!d bump\" without the quotes to bump our server :)", m.Author.Mention()))
|
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("%+v please say \"!d bump\" without the quotes to bump our server :)", m.Author.Mention()))
|
||||||
}
|
}
|
||||||
if m.ChannelID == config.AdminChannel {
|
|
||||||
if strings.HasPrefix(m.Content, s.State.User.Mention()) {
|
if strings.HasPrefix(m.Content, s.State.User.Mention()) {
|
||||||
for _, cmd := range commands {
|
for _, cmd := range commands {
|
||||||
for _, keyword := range cmd.Keywords {
|
for _, keyword := range cmd.Keywords {
|
||||||
if strings.Contains(m.Content, keyword) {
|
if strings.Contains(m.Content, keyword) {
|
||||||
b.Command = keyword
|
b.Command = keyword
|
||||||
|
if !cmd.RequiresAdmin {
|
||||||
if !cmd.Exec(b) {
|
if !cmd.Exec(b) {
|
||||||
s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("There was an error running %+v\n%+v", cmd.Name, cmd.Help))
|
s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("There was an error running %+v\n%+v", cmd.Name, cmd.Help))
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
for role := range m.Member.Roles {
|
||||||
|
if fmt.Sprintf("%+v", role) == config.AdminRole {
|
||||||
|
if !cmd.Exec(b) {
|
||||||
|
s.ChannelMessageSend(config.AdminChannel, fmt.Sprintf("There was an error running %+v\n%+v", cmd.Name, cmd.Help))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
types.go
1
types.go
@ -18,6 +18,7 @@ type BotCommand struct {
|
|||||||
// Command is the type to store commands
|
// Command is the type to store commands
|
||||||
type Command struct {
|
type Command struct {
|
||||||
Name string
|
Name string
|
||||||
|
RequiresAdmin bool
|
||||||
Help string
|
Help string
|
||||||
Keywords []string
|
Keywords []string
|
||||||
Exec func(BotCommand) bool
|
Exec func(BotCommand) bool
|
||||||
|
|||||||
Reference in New Issue
Block a user