Browse Source

Commands for everyone

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

20
discordMessage.go

@ -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))
}
}
}
} }
} }
} }

9
types.go

@ -17,10 +17,11 @@ 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
Help string RequiresAdmin bool
Keywords []string Help string
Exec func(BotCommand) bool Keywords []string
Exec func(BotCommand) bool
} }
// Config struct used for bot // Config struct used for bot

Loading…
Cancel
Save