package message import ( "github.com/bwmarrin/discordgo" "TerraOceanBot/discord/config" ) type Embed struct { *discordgo.MessageEmbed } func NewEmbed() *Embed { return &Embed{&discordgo.MessageEmbed{}} } func InitNewEmbed(title, description string, colour int) *Embed { return NewEmbed().SetTitle(title).SetDescription(description).SetColour(colour) } func InitNewErrorEmbed(description string) *Embed { e := NewEmbed() e.Color = 0xE00000 e.Title = "发生错误!An error has occurred!" e.Description = description return e } func (e *Embed) SetTitle(title string) *Embed { e.Title = title return e } func (e *Embed) SetColour(colour int) *Embed { e.Color = colour return e } func (e *Embed) SetDescription(description string) *Embed { e.Description = description return e } func (e *Embed) AddField(name, value string) *Embed { e.Fields = append(e.Fields, &discordgo.MessageEmbedField{ Name: name, Value: value, }) return e } func (e *Embed) AddInlineField(name, value string) *Embed { e.Fields = append(e.Fields, &discordgo.MessageEmbedField{ Name: name, Value: value, Inline: true, }) return e } func (e *Embed) UpdateVoteStatus(isPositive bool) *Embed { if isPositive { return e.SetColour(config.VotePassColour).SetTitle(config.VotePassTitle) } return e.SetColour(config.VoteRejectColour).SetTitle(config.VoteRejectTitle) } func (e *Embed) Build() *discordgo.MessageEmbed { return e.MessageEmbed } func (e *Embed) Send(s *discordgo.Session, channelID string) (*discordgo.Message, error) { return s.ChannelMessageSendEmbed(channelID, e.Build()) } func (e *Embed) SendPM(s *discordgo.Session, userID string) (*discordgo.Message, error) { channel, err := s.UserChannelCreate(userID) if err != nil { AuditError(s, "", err) return nil, err } return e.Send(s, channel.ID) } func (e *Embed) Edit(s *discordgo.Session, channelID, messageID string) { s.ChannelMessageEditEmbed(channelID, messageID, e.Build()) }