Browse Source

Commands for everyone

master
Gregory Rudolph 3 years ago
parent
commit
af81e9ddc8
Signed by: rudi
GPG Key ID: EF64F3CBD1A1EBDD
  1. 43
      commands.go
  2. 20
      discordMessage.go
  3. 9
      types.go

43
commands.go

@ -12,33 +12,37 @@ import ( @@ -12,33 +12,37 @@ import (
func setupCommands() {
reboot := Command{
Name: "Reboot",
Help: "Reboot me, requires token from logs.",
Keywords: []string{"reboot", "re", "restart"},
Exec: Reboot,
Name: "Reboot",
RequiresAdmin: true,
Help: "Reboot me, requires token from logs.",
Keywords: []string{"reboot", "re", "restart"},
Exec: Reboot,
}
commands = append(commands, reboot)
bumpset := Command{
Name: "BumpSet",
Help: "Set the bump timer (requires time in minutes until next bump).",
Keywords: []string{"bs", "bumpset", "bumps"},
Exec: BumpSet,
Name: "BumpSet",
RequiresAdmin: true,
Help: "Set the bump timer (requires time in minutes until next bump).",
Keywords: []string{"bs", "bumpset", "bumps"},
Exec: BumpSet,
}
commands = append(commands, bumpset)
retrieveVerification := Command{
Name: "Retrieve Verification",
Help: "Retrieve verification either by discord ID or by nickname",
Keywords: []string{"veri", "verification", "retrieve"},
Exec: RetrieveVerification,
Name: "Retrieve Verification",
RequiresAdmin: true,
Help: "Retrieve verification either by discord ID or by nickname",
Keywords: []string{"veri", "verification", "retrieve"},
Exec: RetrieveVerification,
}
commands = append(commands, retrieveVerification)
addQuote := Command{
Name: "Add Quote",
Keywords: []string{"quote", "addq", "q"},
Exec: AddQuote,
Name: "Add Quote",
RequiresAdmin: true,
Keywords: []string{"quote", "addq", "q"},
Exec: AddQuote,
}
commands = append(commands, addQuote)
@ -50,9 +54,10 @@ func setupCommands() { @@ -50,9 +54,10 @@ func setupCommands() {
commands = append(commands, snap)
status := Command{
Name: "Status",
Keywords: []string{"st", "status", "stats"},
Exec: Status,
Name: "Status",
RequiresAdmin: true,
Keywords: []string{"st", "status", "stats"},
Exec: Status,
}
commands = append(commands, status)
}
@ -163,7 +168,7 @@ func Status(b BotCommand) bool { @@ -163,7 +168,7 @@ func Status(b BotCommand) bool {
status += fmt.Sprintf("%+v for another %+v\n", probationUser.Username, time.Until(join.Add(2*time.Hour)))
}
status += "```"
}else {
} else {
status += "There are no users on probation."
}
b.Session.ChannelMessageSend(config.AdminChannel, status)

20
discordMessage.go

@ -52,15 +52,23 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { @@ -52,15 +52,23 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
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()))
}
if m.ChannelID == config.AdminChannel {
if strings.HasPrefix(m.Content, s.State.User.Mention()) {
for _, cmd := range commands {
for _, keyword := range cmd.Keywords {
if strings.Contains(m.Content, keyword) {
b.Command = keyword
if strings.HasPrefix(m.Content, s.State.User.Mention()) {
for _, cmd := range commands {
for _, keyword := range cmd.Keywords {
if strings.Contains(m.Content, keyword) {
b.Command = keyword
if !cmd.RequiresAdmin {
if !cmd.Exec(b) {
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))
}
}
}
}
}
}

9
types.go

@ -17,10 +17,11 @@ type BotCommand struct { @@ -17,10 +17,11 @@ type BotCommand struct {
// Command is the type to store commands
type Command struct {
Name string
Help string
Keywords []string
Exec func(BotCommand) bool
Name string
RequiresAdmin bool
Help string
Keywords []string
Exec func(BotCommand) bool
}
// Config struct used for bot

Loading…
Cancel
Save