package modules 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()) }