Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Commands is a map of Command names to their Command Commands = make(map[string]Command) )
View Source
var Commit = Command{ Meta: api.CreateCommandData{ Name: "commit", Description: "Commit information", Type: discord.ChatInputCommand, Options: []discord.CommandOption{ &discord.StringOption{ OptionName: "sha", Description: "The commit SHA (partial or full)", Required: true, }, }, }, Handler: func(ctx *Context) { if err := ctx.State.RespondInteraction(ctx.Event.ID, ctx.Event.Token, deferredInteraction); err != nil { log.Err(err).Msg("") return } sha := ctx.Event.Data.(*discord.CommandInteraction).Options[0].String() commit, err := ctx.Forge.Commit(sha) if err != nil { log.Err(err).Msg("") ctx.DeferredError("could not retrieve commit") return } body := ctx.Forge.ReplaceIssueLinks(commit.Message) if len(body) > 1000 { body = body[:1000] + "..." } embed := discord.Embed{ Author: &discord.EmbedAuthor{ Name: commit.Author.Username, URL: commit.Author.URL, Icon: commit.Author.Image, }, Thumbnail: &discord.EmbedThumbnail{ URL: ctx.Forge.Image(), }, Title: commit.SHA, URL: commit.URL, Description: body, Footer: &discord.EmbedFooter{ Text: "Created", }, Timestamp: discord.NewTimestamp(commit.Time), Fields: []discord.EmbedField{ { Name: "Stats", Value: fmt.Sprintf("%d ++ %d --", commit.Additions, commit.Deletions), Inline: true, }, { Name: "Verified", Value: strconv.FormatBool(commit.Verified), Inline: true, }, }, } data := api.EditInteractionResponseData{ Embeds: &[]discord.Embed{ embed, }, } if _, err := ctx.State.EditInteractionResponse(ctx.App.ID, ctx.Event.Token, data); err != nil { log.Err(err).Msg("") } }, }
Commit is the command for getting a forge.Commit by its SHA
View Source
var Debug = Command{ Meta: api.CreateCommandData{ Name: "debug", Description: "Debugging info", Type: discord.ChatInputCommand, }, Handler: func(ctx *Context) { data := api.InteractionResponse{ Type: api.MessageInteractionWithSource, Data: &api.InteractionResponseData{ Content: option.NewNullableString(debugMessage), }, } if err := ctx.State.RespondInteraction(ctx.Event.ID, ctx.Event.Token, data); err != nil { log.Err(err).Msg("") } }, }
Debug is the debugging command
View Source
var Issue = Command{ Meta: api.CreateCommandData{ Name: "issue", Description: "Issue/PR information", Type: discord.ChatInputCommand, Options: []discord.CommandOption{ &discord.IntegerOption{ OptionName: "num", Description: "The issue/PR number", Min: option.NewInt(1), Required: true, }, }, }, Handler: func(ctx *Context) { if err := ctx.State.RespondInteraction(ctx.Event.ID, ctx.Event.Token, deferredInteraction); err != nil { log.Err(err).Msg("") return } num, err := ctx.Event.Data.(*discord.CommandInteraction).Options[0].IntValue() if err != nil { log.Err(err).Msg("") ctx.DeferredError("could not parse num") return } issue, err := ctx.Forge.Issue(int(num)) if err != nil { log.Err(err).Msg("") ctx.DeferredError("could not retrieve issue/PR") return } body := ctx.Forge.ReplaceIssueLinks(issue.Body) if len(body) > 1000 { body = body[:1000] + "..." } embed := discord.Embed{ Author: &discord.EmbedAuthor{ Name: issue.User.Username, URL: issue.User.URL, Icon: issue.User.Image, }, Thumbnail: &discord.EmbedThumbnail{ URL: ctx.Forge.Image(), }, Title: fmt.Sprintf("%s #%d", issue.Title, num), URL: issue.URL, Description: body, Footer: &discord.EmbedFooter{ Text: "Created", }, Timestamp: discord.NewTimestamp(issue.Created), Fields: []discord.EmbedField{ { Name: "Comments", Value: strconv.Itoa(issue.Comments), Inline: true, }, }, } if len(issue.Labels) > 0 { embed.Fields = append(embed.Fields, discord.EmbedField{ Name: "Labels", Value: fmt.Sprintf("`%s`", strings.Join(issue.Labels, "`, `")), Inline: true, }) } state := issue.State if !issue.Closed.IsZero() { state += fmt.Sprintf(" <t:%d:R>", issue.Closed.Unix()) } embed.Fields = append(embed.Fields, discord.EmbedField{ Name: "State", Value: state, Inline: true, }) data := api.EditInteractionResponseData{ Embeds: &[]discord.Embed{ embed, }, } if _, err := ctx.State.EditInteractionResponse(ctx.App.ID, ctx.Event.Token, data); err != nil { log.Err(err).Msg("") } }, }
Issue is the command for getting a forge.Issue by its number
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct { Meta api.CreateCommandData Handler func(*Context) }
Command is a discord command
type Context ¶
type Context struct { App *discord.Application State *state.State Event *gateway.InteractionCreateEvent Forge Forge }
Context is passed in to each Command.Handler
func (*Context) DeferredError ¶
DeferredError is a quick way to respond to a failed deferred interaction
Click to show internal directories.
Click to hide internal directories.