diff --git a/internal/exts/init.go b/internal/exts/init.go index c43cc8c..71fe8d2 100644 --- a/internal/exts/init.go +++ b/internal/exts/init.go @@ -3,6 +3,7 @@ package exts import ( "github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/geeksbot/internal/exts/guild" + "github.com/dustinpianalto/geeksbot/internal/exts/requests" "github.com/dustinpianalto/geeksbot/internal/exts/utils" ) @@ -23,4 +24,5 @@ func AddCommandHandlers(g *disgoman.CommandManager) { _ = g.AddCommand(utils.PingCommand) _ = g.AddCommand(guild.AddPrefixCommand) _ = g.AddCommand(guild.RemovePrefixCommand) + _ = g.AddCommand(requests.RequestCommand) } diff --git a/internal/exts/requests/requests.go b/internal/exts/requests/requests.go index 646a5b2..4507280 100644 --- a/internal/exts/requests/requests.go +++ b/internal/exts/requests/requests.go @@ -1,8 +1,10 @@ package requests import ( + "fmt" "strconv" "strings" + "time" "github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/geeksbot" @@ -60,4 +62,42 @@ func requestCommandFunc(ctx disgoman.Context, args []string) { discord_utils.SendErrorMessage(ctx, "Error creating the request", err) return } + channels, err := services.ChannelService.GuildChannels(guild) + if err == nil { + var mentionRolesString string + roles, err := services.GuildService.GuildRoles(guild) + if err == nil { + for _, r := range roles { + if r.RoleType == "admin" || r.RoleType == "moderator" { + mentionRolesString += fmt.Sprintf("<@&%s> ", r.ID) + } + } + } + for _, c := range channels { + if c.Admin { + _, _ = ctx.Session.ChannelMessageSend(c.ID, + fmt.Sprintf("%s\n"+ + "New Request ID %d "+ + "%s has requested assistance: \n"+ + "```\n%s\n```\n"+ + "Requested At: %s\n"+ + "In: %s", + mentionRolesString, + request.ID, + ctx.Message.Author.Mention, + request.Content, + request.RequestedAt.UTC().Format(time.UnixDate), + ctx.Channel.Mention(), + ), + ) + } + } + } + _, err = ctx.Send(fmt.Sprintf("%s The admin have recieved your request.\n "+ + "If you would like to close or add a comment to this request please reference ID `%v`", + ctx.Message.Author.Mention, request.ID, + )) + if err != nil { + discord_utils.SendErrorMessage(ctx, "There was an error sending the message. The request was created.", err) + } }