109 lines
2.5 KiB
Go
109 lines
2.5 KiB
Go
package command
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/diamondburned/arikawa/v3/api"
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
"github.com/diamondburned/arikawa/v3/utils/json/option"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func init() {
|
|
Commands["issue"] = Issue
|
|
}
|
|
|
|
// Issue is the command for getting a forge.Issue by its number
|
|
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("")
|
|
}
|
|
},
|
|
}
|