go: Move embed creation and audit functions into its own package

pull/12/head
Luther Wen Xu 2019-10-13 20:38:00 +07:00
parent d58e32f2b4
commit 6211334d91
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
14 changed files with 178 additions and 155 deletions

@ -1,12 +1,11 @@
package backend package backend
import ( import (
"fmt"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"TerraOceanBot/db" "TerraOceanBot/db"
"TerraOceanBot/discord/config" "TerraOceanBot/discord/config"
"TerraOceanBot/discord/message"
"TerraOceanBot/server" "TerraOceanBot/server"
) )
@ -27,8 +26,7 @@ func UpdateVoiceChannelState(s *discordgo.Session) {
continue continue
} }
if err != nil { if err != nil {
//TODO Use auditError() once it's moved to its own package. message.AuditError(s, "", err)
fmt.Println(err)
continue continue
} }
server.ConnectUser(username) server.ConnectUser(username)
@ -36,14 +34,13 @@ func UpdateVoiceChannelState(s *discordgo.Session) {
} }
} }
func VoiceStateUpdate(vs *discordgo.VoiceState) { func VoiceStateUpdate(s *discordgo.Session, vs *discordgo.VoiceState) {
username, err := db.GetMinecraftUsername(vs.UserID) username, err := db.GetMinecraftUsername(vs.UserID)
if err == db.ErrNotFound { if err == db.ErrNotFound {
return return
} }
if err != nil { if err != nil {
//TODO Use auditError() once it's moved to its own package. message.AuditError(s, "", err)
fmt.Println(err)
return return
} }
if vs.GuildID != config.GuildID { if vs.GuildID != config.GuildID {

@ -32,5 +32,5 @@ func ProcessVote(s *discordgo.Session, m *discordgo.MessageCreate) {
} }
func ProcessVoiceStateUpdate(s *discordgo.Session, vs *discordgo.VoiceStateUpdate) { func ProcessVoiceStateUpdate(s *discordgo.Session, vs *discordgo.VoiceStateUpdate) {
backend.VoiceStateUpdate(vs.VoiceState) backend.VoiceStateUpdate(s, vs.VoiceState)
} }

@ -0,0 +1,42 @@
package message
import (
"runtime/debug"
"github.com/bwmarrin/discordgo"
"TerraOceanBot/discord/config"
)
func AuditInfo(s *discordgo.Session, message string) {
InitNewEmbed(config.AuditInfoTitle, message, config.AuditInfoColour).
Send(s, config.AuditChannel)
}
func AuditError(s *discordgo.Session, sourceChannel string, err error) {
if sourceChannel != "" {
InitNewErrorEmbed(config.InternalErrorDescription).
Send(s, sourceChannel)
}
sendError(s, config.AuditChannel, err)
}
func AuditErrorPM(s *discordgo.Session, sourceUser string, err error) {
channel, channelErr := s.UserChannelCreate(sourceUser)
if channelErr != nil {
AuditError(s, "", channelErr)
AuditError(s, "", err)
return
}
AuditError(s, channel.ID, err)
}
func sendError(s *discordgo.Session, channelID string, err error) {
stack := string(debug.Stack())
if len(stack) > 1000 {
stack = stack[:1000] + "..."
}
InitNewErrorEmbed(err.Error()).
AddField(config.ErrorStack, stack).
Send(s, channelID)
}

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

@ -7,6 +7,7 @@ import (
"TerraOceanBot/discord/backend" "TerraOceanBot/discord/backend"
"TerraOceanBot/discord/config" "TerraOceanBot/discord/config"
"TerraOceanBot/discord/message"
) )
//adminID is my Discord user ID (chanbakjsd#7968). //adminID is my Discord user ID (chanbakjsd#7968).
@ -26,10 +27,10 @@ var sendAs = adminOnly(enforceArgumentCount(config.SendAsUsage, 3,
func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) { func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
msg, err := s.ChannelMessageSend(command[1], command[2]) msg, err := s.ChannelMessageSend(command[1], command[2])
if err != nil { if err != nil {
sendError(s, m.ChannelID, err) message.AuditError(s, m.ChannelID, err)
return return
} }
initNewEmbed(config.SuccessTitle, config.SendAsSuccessfulDescription, config.SuccessColour). message.InitNewEmbed(config.SuccessTitle, config.SendAsSuccessfulDescription, config.SuccessColour).
AddField(config.SendAsSuccessfulMessageID, msg.ID). AddField(config.SendAsSuccessfulMessageID, msg.ID).
Send(s, m.ChannelID) Send(s, m.ChannelID)
}, },
@ -40,10 +41,10 @@ var editAs = adminOnly(enforceArgumentCount(config.EditAsUsage, 4,
func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) { func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
_, err := s.ChannelMessageEdit(command[1], command[2], command[3]) _, err := s.ChannelMessageEdit(command[1], command[2], command[3])
if err != nil { if err != nil {
sendError(s, m.ChannelID, err) message.AuditError(s, m.ChannelID, err)
return return
} }
initNewEmbed(config.SuccessTitle, config.EditAsSuccessfulDescription, config.SuccessColour). message.InitNewEmbed(config.SuccessTitle, config.EditAsSuccessfulDescription, config.SuccessColour).
Send(s, m.ChannelID) Send(s, m.ChannelID)
}, },
)) ))
@ -52,15 +53,15 @@ var viewTrustLevel = adminOnly(func(s *discordgo.Session, m *discordgo.MessageCr
if len(command) > 1 { if len(command) > 1 {
value, err := backend.GetTrust(s, command[1]) value, err := backend.GetTrust(s, command[1])
if err != nil { if err != nil {
sendError(s, m.ChannelID, err) message.AuditError(s, m.ChannelID, err)
return return
} }
total, err := backend.GetTotalTrust(s) total, err := backend.GetTotalTrust(s)
if err != nil { if err != nil {
sendError(s, m.ChannelID, err) message.AuditError(s, m.ChannelID, err)
return return
} }
newEmbed().SetColour(config.VTLColour). message.NewEmbed().SetColour(config.VTLColour).
SetTitle(fmt.Sprintf(config.VTLSingleUserTitle, command[1], command[1])). SetTitle(fmt.Sprintf(config.VTLSingleUserTitle, command[1], command[1])).
AddField(config.VTLSingleUserValue, formatFloat(value, 1)). AddField(config.VTLSingleUserValue, formatFloat(value, 1)).
AddField(config.VTLSingleUserServerTotal, formatFloat(total, 1)). AddField(config.VTLSingleUserServerTotal, formatFloat(total, 1)).
@ -71,30 +72,30 @@ var viewTrustLevel = adminOnly(func(s *discordgo.Session, m *discordgo.MessageCr
total, err := backend.GetTotalTrust(s) total, err := backend.GetTotalTrust(s)
if err != nil { if err != nil {
sendError(s, m.ChannelID, err) message.AuditError(s, m.ChannelID, err)
return return
} }
members, err := backend.GetAllMembers(s) members, err := backend.GetAllMembers(s)
if err != nil { if err != nil {
sendError(s, m.ChannelID, err) message.AuditError(s, m.ChannelID, err)
return return
} }
//Generate message //Generate message
message := newEmbed().SetColour(config.VTLColour).SetTitle(config.VTLGlobalTitle) msg := message.NewEmbed().SetColour(config.VTLColour).SetTitle(config.VTLGlobalTitle)
for _, v := range members { for _, v := range members {
value, err := backend.GetTrust(s, v.User.ID) value, err := backend.GetTrust(s, v.User.ID)
if err == backend.ErrNotMember { if err == backend.ErrNotMember {
continue continue
} }
if err != nil { if err != nil {
sendError(s, m.ChannelID, err) message.AuditError(s, m.ChannelID, err)
return return
} }
message.AddInlineField( msg.AddInlineField(
v.User.Username+"#"+v.User.Discriminator, v.User.Username+"#"+v.User.Discriminator,
fmt.Sprintf(config.VTLGlobalFieldFormat, value, total, value/total*100), fmt.Sprintf(config.VTLGlobalFieldFormat, value, total, value/total*100),
) )
} }
message.Send(s, m.ChannelID) msg.Send(s, m.ChannelID)
}) })

@ -8,6 +8,7 @@ import (
"TerraOceanBot/db" "TerraOceanBot/db"
"TerraOceanBot/discord/config" "TerraOceanBot/discord/config"
"TerraOceanBot/discord/message"
"TerraOceanBot/server" "TerraOceanBot/server"
) )
@ -22,7 +23,7 @@ var createInvite = enforceDM(memberFilter(true, enforceArgumentCount(
config.InviteUsage, 2, config.InviteUsage, 2,
func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) { func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
if strings.ContainsRune(command[1], ' ') { if strings.ContainsRune(command[1], ' ') {
initNewEmbed(config.ErrorInviteTitle, config.ErrorInviteCodeContainsSpace, config.ErrorColour). message.InitNewEmbed(config.ErrorInviteTitle, config.ErrorInviteCodeContainsSpace, config.ErrorColour).
Send(s, m.ChannelID) Send(s, m.ChannelID)
return return
} }
@ -32,20 +33,20 @@ var createInvite = enforceDM(memberFilter(true, enforceArgumentCount(
case db.ErrAlreadyExists: case db.ErrAlreadyExists:
owner, _ := db.GetInviteOwner(command[1]) owner, _ := db.GetInviteOwner(command[1])
if owner == m.Author.ID { if owner == m.Author.ID {
initNewEmbed(config.InviteSuccessTitle, config.InviteSuccessAlreadyOwn, config.SuccessColour). message.InitNewEmbed(config.InviteSuccessTitle, config.InviteSuccessAlreadyOwn, config.SuccessColour).
Send(s, m.ChannelID) Send(s, m.ChannelID)
return return
} }
initNewEmbed(config.ErrorInviteTitle, config.ErrorInviteOwnedByOthers, config.ErrorColour). message.InitNewEmbed(config.ErrorInviteTitle, config.ErrorInviteOwnedByOthers, config.ErrorColour).
Send(s, m.ChannelID) Send(s, m.ChannelID)
case db.ErrInviteUsed: case db.ErrInviteUsed:
initNewEmbed(config.ErrorInviteTitle, config.ErrorInviteExistAndUsed, config.ErrorColour). message.InitNewEmbed(config.ErrorInviteTitle, config.ErrorInviteExistAndUsed, config.ErrorColour).
Send(s, m.ChannelID) Send(s, m.ChannelID)
case nil: case nil:
initNewEmbed(config.InviteSuccessTitle, config.InviteSuccessNew, config.SuccessColour). message.InitNewEmbed(config.InviteSuccessTitle, config.InviteSuccessNew, config.SuccessColour).
Send(s, m.ChannelID) Send(s, m.ChannelID)
default: default:
auditErrorPM(s, m.Author.ID, err) message.AuditErrorPM(s, m.Author.ID, err)
} }
}, },
))) )))
@ -55,24 +56,24 @@ var checkUseInvite = enforceDM(memberFilter(false, enforceArgumentCount(
func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) { func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
inviter, err := db.GetInviteOwner(command[1]) inviter, err := db.GetInviteOwner(command[1])
if err == db.ErrInviteUsed { if err == db.ErrInviteUsed {
initNewEmbed(config.ErrorValidateTitle, config.ErrorValidationCodeReuse, config.ErrorColour). message.InitNewEmbed(config.ErrorValidateTitle, config.ErrorValidationCodeReuse, config.ErrorColour).
Send(s, m.ChannelID) Send(s, m.ChannelID)
return return
} }
if err == db.ErrNotFound { if err == db.ErrNotFound {
initNewEmbed(config.ErrorValidateTitle, config.ErrorValidationCodeNotExist, config.ErrorColour). message.InitNewEmbed(config.ErrorValidateTitle, config.ErrorValidationCodeNotExist, config.ErrorColour).
SendPM(s, m.ChannelID) SendPM(s, m.ChannelID)
return return
} }
if err != nil { if err != nil {
auditError(s, m.ChannelID, err) message.AuditError(s, m.ChannelID, err)
return return
} }
db.UseInvite(command[1]) db.UseInvite(command[1])
member, err := s.GuildMember(config.GuildID, inviter) member, err := s.GuildMember(config.GuildID, inviter)
if err != nil { if err != nil {
auditErrorPM(s, m.ChannelID, err) message.AuditErrorPM(s, m.ChannelID, err)
return return
} }
@ -83,18 +84,18 @@ var checkUseInvite = enforceDM(memberFilter(false, enforceArgumentCount(
} }
} }
if !isMember { if !isMember {
initNewEmbed(config.ErrorValidateTitle, config.ErrorValidationCodeNotOwnedByMember, config.ErrorColour). message.InitNewEmbed(config.ErrorValidateTitle, config.ErrorValidationCodeNotOwnedByMember, config.ErrorColour).
SendPM(s, m.ChannelID) SendPM(s, m.ChannelID)
return return
} }
channel, err := s.UserChannelCreate(inviter) channel, err := s.UserChannelCreate(inviter)
if err != nil { if err != nil {
initNewEmbed(config.ErrorValidateTitle, config.ErrorValidationCodeCreatorDisabledPM, config.ErrorColour). message.InitNewEmbed(config.ErrorValidateTitle, config.ErrorValidationCodeCreatorDisabledPM, config.ErrorColour).
SendPM(s, m.ChannelID) SendPM(s, m.ChannelID)
return return
} }
msg, err := initNewEmbed( msg, err := message.InitNewEmbed(
config.ValidateConfirmationTitle, config.ValidateConfirmationTitle,
config.ValidateConfirmationDescription, config.ValidateConfirmationDescription,
config.ValidateConfirmationColour, config.ValidateConfirmationColour,
@ -102,7 +103,7 @@ var checkUseInvite = enforceDM(memberFilter(false, enforceArgumentCount(
AddField(config.ValidateConfirmationInviteCode, command[1]). AddField(config.ValidateConfirmationInviteCode, command[1]).
Send(s, channel.ID) Send(s, channel.ID)
if err != nil { if err != nil {
auditErrorPM(s, m.ChannelID, err) message.AuditErrorPM(s, m.ChannelID, err)
return return
} }
pendingInviteConfirmation[msg.ID] = invite{ pendingInviteConfirmation[msg.ID] = invite{
@ -111,7 +112,7 @@ var checkUseInvite = enforceDM(memberFilter(false, enforceArgumentCount(
} }
s.MessageReactionAdd(channel.ID, msg.ID, emojiCheck) s.MessageReactionAdd(channel.ID, msg.ID, emojiCheck)
s.MessageReactionAdd(channel.ID, msg.ID, emojiX) s.MessageReactionAdd(channel.ID, msg.ID, emojiX)
initNewEmbed(config.SuccessTitle, config.ValidateSuccess, config.SuccessColour). message.InitNewEmbed(config.SuccessTitle, config.ValidateSuccess, config.SuccessColour).
SendPM(s, m.ChannelID) SendPM(s, m.ChannelID)
}, },
))) )))
@ -129,12 +130,12 @@ func CheckForInvite(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
switch r.Emoji.Name { switch r.Emoji.Name {
case emojiX: case emojiX:
initNewEmbed( message.InitNewEmbed(
config.ValidateConfirmationRejectCreatorTitle, config.ValidateConfirmationRejectCreatorTitle,
config.ValidateConfirmationRejectCreatorDescription, config.ValidateConfirmationRejectCreatorDescription,
config.ErrorColour, config.ErrorColour,
).SendPM(s, r.UserID) ).SendPM(s, r.UserID)
initNewEmbed( message.InitNewEmbed(
config.ValidateConfirmationRejectRejecteeTitle, config.ValidateConfirmationRejectRejecteeTitle,
config.ValidateConfirmationRejectRejecteeDescription, config.ValidateConfirmationRejectRejecteeDescription,
config.ErrorColour, config.ErrorColour,
@ -145,12 +146,12 @@ func CheckForInvite(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
return return
} }
initNewEmbed( message.InitNewEmbed(
config.ValidateConfirmationAcceptCreatorTitle, config.ValidateConfirmationAcceptCreatorTitle,
config.ValidateConfirmationAcceptCreatorDescription, config.ValidateConfirmationAcceptCreatorDescription,
config.ErrorColour, config.ErrorColour,
).SendPM(s, r.UserID) ).SendPM(s, r.UserID)
initNewEmbed( message.InitNewEmbed(
config.ValidateConfirmationAcceptAccepteeTitle, config.ValidateConfirmationAcceptAccepteeTitle,
config.ValidateConfirmationAcceptAccepteeDescription, config.ValidateConfirmationAcceptAccepteeDescription,
config.ErrorColour, config.ErrorColour,
@ -158,15 +159,15 @@ func CheckForInvite(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
msg, err := s.ChannelMessageSend(config.VoteChannel, "正在准备新的一个投票…… Preparing for the next vote...") msg, err := s.ChannelMessageSend(config.VoteChannel, "正在准备新的一个投票…… Preparing for the next vote...")
if err != nil { if err != nil {
auditErrorPM(s, r.UserID, err) message.AuditErrorPM(s, r.UserID, err)
return return
} }
id, err := db.CreateInviteVote(msg.ID, invite.User, invite.Reason) id, err := db.CreateInviteVote(msg.ID, invite.User, invite.Reason)
if err != nil { if err != nil {
auditErrorPM(s, r.UserID, err) message.AuditErrorPM(s, r.UserID, err)
return return
} }
auditInfo(s, fmt.Sprintf("Vote ID %d has been created by <@%s>.", id, r.UserID)) message.AuditInfo(s, fmt.Sprintf("Vote ID %d has been created by <@%s>.", id, r.UserID))
s.ChannelMessageEdit(config.VoteChannel, msg.ID, "") s.ChannelMessageEdit(config.VoteChannel, msg.ID, "")
createInviteEmbed(id, invite.User+":"+invite.Reason).Edit(s, config.VoteChannel, msg.ID) createInviteEmbed(id, invite.User+":"+invite.Reason).Edit(s, config.VoteChannel, msg.ID)
s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiX) s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiX)

@ -2,13 +2,13 @@ package modules
import ( import (
"fmt" "fmt"
"runtime"
"strconv" "strconv"
"strings" "strings"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"TerraOceanBot/discord/config" "TerraOceanBot/discord/config"
"TerraOceanBot/discord/message"
) )
func enforceDM(passOn CommandHandler) CommandHandler { func enforceDM(passOn CommandHandler) CommandHandler {
@ -16,7 +16,7 @@ func enforceDM(passOn CommandHandler) CommandHandler {
if m.GuildID != "" { if m.GuildID != "" {
//This command can only be used in DM to protect the invite creator. //This command can only be used in DM to protect the invite creator.
s.ChannelMessageDelete(m.ChannelID, m.ID) s.ChannelMessageDelete(m.ChannelID, m.ID)
initNewEmbed( message.InitNewEmbed(
config.ErrorMustDMTitle, config.ErrorMustDMTitle,
fmt.Sprintf(config.ErrorMustDMDescription, m.Author.ID, m.Author.ID), fmt.Sprintf(config.ErrorMustDMDescription, m.Author.ID, m.Author.ID),
config.ErrorColour, config.ErrorColour,
@ -31,7 +31,7 @@ func memberFilter(mustBeMember bool, passOn CommandHandler) CommandHandler {
return func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) { return func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
member, err := s.GuildMember(config.GuildID, m.Author.ID) member, err := s.GuildMember(config.GuildID, m.Author.ID)
if err != nil { if err != nil {
initNewEmbed(config.PermissionErrorTitle, config.ErrorCannotFindMember, config.ErrorColour). message.InitNewEmbed(config.PermissionErrorTitle, config.ErrorCannotFindMember, config.ErrorColour).
Send(s, m.ChannelID) Send(s, m.ChannelID)
return return
} }
@ -40,14 +40,14 @@ func memberFilter(mustBeMember bool, passOn CommandHandler) CommandHandler {
if mustBeMember { if mustBeMember {
passOn(s, m, command) passOn(s, m, command)
} else { } else {
initNewEmbed(config.PermissionErrorTitle, config.ErrorMustNotBeMember, config.ErrorColour). message.InitNewEmbed(config.PermissionErrorTitle, config.ErrorMustNotBeMember, config.ErrorColour).
Send(s, m.ChannelID) Send(s, m.ChannelID)
} }
return return
} }
} }
if mustBeMember { if mustBeMember {
initNewEmbed(config.PermissionErrorTitle, config.ErrorMustBeMember, config.ErrorColour). message.InitNewEmbed(config.PermissionErrorTitle, config.ErrorMustBeMember, config.ErrorColour).
Send(s, m.ChannelID) Send(s, m.ChannelID)
} else { } else {
passOn(s, m, command) passOn(s, m, command)
@ -58,7 +58,7 @@ func memberFilter(mustBeMember bool, passOn CommandHandler) CommandHandler {
func enforceArgumentCount(usage string, count int, passOn CommandHandler) CommandHandler { func enforceArgumentCount(usage string, count int, passOn CommandHandler) CommandHandler {
return func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) { return func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
if len(command) < count { if len(command) < count {
initNewEmbed(config.UsageTitle, usage, config.UsageColour). message.InitNewEmbed(config.UsageTitle, usage, config.UsageColour).
Send(s, m.ChannelID) Send(s, m.ChannelID)
return return
} }
@ -67,41 +67,6 @@ func enforceArgumentCount(usage string, count int, passOn CommandHandler) Comman
} }
} }
func sendError(s *discordgo.Session, channelID string, err error) {
stackCache := make([]byte, 512)
count := runtime.Stack(stackCache, false)
stack := string(stackCache[:count])
if count == 512 {
stack += "..."
}
initNewErrorEmbed(err.Error()).
AddField(config.ErrorStack, stack).
Send(s, channelID)
}
func auditInfo(s *discordgo.Session, message string) {
initNewEmbed(config.AuditInfoTitle, message, config.AuditInfoColour).
Send(s, config.AuditChannel)
}
func auditError(s *discordgo.Session, sourceChannel string, err error) {
if sourceChannel != "" {
initNewErrorEmbed(config.InternalErrorDescription).
Send(s, sourceChannel)
}
sendError(s, config.AuditChannel, err)
}
func auditErrorPM(s *discordgo.Session, sourceUser string, err error) {
channel, channelErr := s.UserChannelCreate(sourceUser)
if channelErr != nil {
auditError(s, "", channelErr)
auditError(s, "", err)
return
}
auditError(s, channel.ID, err)
}
func formatFloat(n float64, precision int) string { func formatFloat(n float64, precision int) string {
return strconv.FormatFloat(n, 'f', precision, 64) return strconv.FormatFloat(n, 'f', precision, 64)
} }

@ -6,6 +6,7 @@ import (
"TerraOceanBot/db" "TerraOceanBot/db"
"TerraOceanBot/discord/backend" "TerraOceanBot/discord/backend"
"TerraOceanBot/discord/config" "TerraOceanBot/discord/config"
"TerraOceanBot/discord/message"
"TerraOceanBot/server" "TerraOceanBot/server"
) )
@ -20,15 +21,15 @@ var updateMinecraftUsername = memberFilter(true, enforceArgumentCount(
processUsernameUpdate(s, m.Author.ID, m.ChannelID, command[1]) processUsernameUpdate(s, m.Author.ID, m.ChannelID, command[1])
return return
} }
auditError(s, m.ChannelID, err) message.AuditError(s, m.ChannelID, err)
return return
} }
if oldUsername == command[1] { if oldUsername == command[1] {
initNewEmbed(config.SetMCUsernameErrorTitle, config.ErrorSetMCUsernameDuplicate, config.ErrorColour). message.InitNewEmbed(config.SetMCUsernameErrorTitle, config.ErrorSetMCUsernameDuplicate, config.ErrorColour).
Send(s, m.ChannelID) Send(s, m.ChannelID)
return return
} }
msg, err := initNewEmbed( msg, err := message.InitNewEmbed(
config.SetMCUsernameConfirmTitle, config.SetMCUsernameConfirmTitle,
config.SetMCUsernameConfirmDescription, config.SetMCUsernameConfirmDescription,
config.SetMCUsernameConfirmColour, config.SetMCUsernameConfirmColour,
@ -36,7 +37,7 @@ var updateMinecraftUsername = memberFilter(true, enforceArgumentCount(
AddField(config.SetMCUsernameConfirmNewUsername, command[1]). AddField(config.SetMCUsernameConfirmNewUsername, command[1]).
SendPM(s, m.Author.ID) SendPM(s, m.Author.ID)
if err != nil { if err != nil {
auditError(s, m.ChannelID, err) message.AuditError(s, m.ChannelID, err)
} }
minecraftConfirmReact[msg.ID] = command[1] minecraftConfirmReact[msg.ID] = command[1]
s.MessageReactionAdd(msg.ChannelID, msg.ID, emojiCheck) s.MessageReactionAdd(msg.ChannelID, msg.ID, emojiCheck)
@ -59,8 +60,11 @@ func ConfirmMinecraftUsername(s *discordgo.Session, r *discordgo.MessageReaction
switch r.Emoji.Name { switch r.Emoji.Name {
case emojiCheck: case emojiCheck:
case emojiX: case emojiX:
initNewEmbed(config.SetMCUsernameConfirmDeniedTitle, config.SetMCUsernameConfirmDeniedDescription, config.SuccessColour). message.InitNewEmbed(
Send(s, r.ChannelID) config.SetMCUsernameConfirmDeniedTitle,
config.SetMCUsernameConfirmDeniedDescription,
config.SuccessColour,
).Send(s, r.ChannelID)
return return
} }
@ -71,7 +75,7 @@ func processUsernameUpdate(s *discordgo.Session, discordID, channelID, newUserna
oldUsername, oldErr := db.GetMinecraftUsername(discordID) oldUsername, oldErr := db.GetMinecraftUsername(discordID)
err := db.SetMinecraftUsername(discordID, newUsername) err := db.SetMinecraftUsername(discordID, newUsername)
if err == db.ErrAlreadyExists { if err == db.ErrAlreadyExists {
initNewEmbed( message.InitNewEmbed(
config.SetMCUsernameErrorTitle, config.SetMCUsernameErrorTitle,
config.ErrorSetMCUsernameAlreadyOwned, config.ErrorSetMCUsernameAlreadyOwned,
config.ErrorColour, config.ErrorColour,
@ -84,7 +88,7 @@ func processUsernameUpdate(s *discordgo.Session, discordID, channelID, newUserna
server.WhitelistRemove(oldUsername) server.WhitelistRemove(oldUsername)
} }
initNewEmbed( message.InitNewEmbed(
config.SetMCUsernameSuccessTitle, config.SetMCUsernameSuccessTitle,
config.SetMCUsernameSuccessDescription, config.SetMCUsernameSuccessDescription,
config.SuccessColour, config.SuccessColour,

@ -7,6 +7,7 @@ import (
"TerraOceanBot/db" "TerraOceanBot/db"
"TerraOceanBot/discord/backend" "TerraOceanBot/discord/backend"
"TerraOceanBot/discord/message"
) )
var trustMessage = make(map[string]string) var trustMessage = make(map[string]string)
@ -24,32 +25,35 @@ var changeTrust = enforceDM(memberFilter(true,
return return
} }
if err != nil { if err != nil {
auditError(s, m.ChannelID, err) message.AuditError(s, m.ChannelID, err)
return return
} }
message, err := s.ChannelMessageSendEmbed( msg, err := s.ChannelMessageSendEmbed(
m.ChannelID, m.ChannelID,
createTrustEmbed(member.User.Username+"#"+member.User.Discriminator, member.Nick), createTrustEmbed(member.User.Username+"#"+member.User.Discriminator, member.Nick),
) )
if err != nil { if err != nil {
auditError(s, m.ChannelID, err) message.AuditError(s, m.ChannelID, err)
return return
} }
trustMessage[message.ID] = member.User.ID trustMessage[msg.ID] = member.User.ID
s.MessageReactionAdd(m.ChannelID, message.ID, emojiOne) s.MessageReactionAdd(m.ChannelID, msg.ID, emojiOne)
s.MessageReactionAdd(m.ChannelID, message.ID, emojiTwo) s.MessageReactionAdd(m.ChannelID, msg.ID, emojiTwo)
s.MessageReactionAdd(m.ChannelID, message.ID, emojiThree) s.MessageReactionAdd(m.ChannelID, msg.ID, emojiThree)
s.MessageReactionAdd(m.ChannelID, message.ID, emojiFour) s.MessageReactionAdd(m.ChannelID, msg.ID, emojiFour)
s.MessageReactionAdd(m.ChannelID, message.ID, emojiFive) s.MessageReactionAdd(m.ChannelID, msg.ID, emojiFive)
s.MessageReactionAdd(m.ChannelID, message.ID, emojiCheck) s.MessageReactionAdd(m.ChannelID, msg.ID, emojiCheck)
}, },
)) ))
func createTrustEmbed(username, nick string) *discordgo.MessageEmbed { func createTrustEmbed(username, nick string) *discordgo.MessageEmbed {
embed := newEmbed().SetColour(0x00FFFF).SetTitle("更新玩家评分Update Player Score").AddField("ID", username) embed := message.NewEmbed().
SetColour(0x00FFFF).
SetTitle("更新玩家评分Update Player Score").
AddField("ID", username)
if nick != "" { if nick != "" {
embed.AddField("昵称Nickname", nick) embed.AddField("昵称Nickname", nick)
} }
@ -84,17 +88,18 @@ func CheckForTrustUpdate(s *discordgo.Session, r *discordgo.MessageReactionAdd)
case emojiCheck: case emojiCheck:
value = db.NuclearOptionVote value = db.NuclearOptionVote
default: default:
auditInfo(s, "Reaction "+r.Emoji.Name+" was added to trust message ID "+r.MessageID) message.AuditInfo(s, "Reaction "+r.Emoji.Name+" was added to trust message ID "+r.MessageID)
return return
} }
err := backend.UpdateTrust(r.UserID, target, value) err := backend.UpdateTrust(r.UserID, target, value)
if err == db.ErrRecentlyChanged { if err == db.ErrRecentlyChanged {
//TODO Move to embed.
s.ChannelMessageSend(r.ChannelID, "你在一个月内有设定过该名玩家的分数。你这次的更动没有被记录。\nYou have changed your score for this player within the last month. Your change was not recorded.") s.ChannelMessageSend(r.ChannelID, "你在一个月内有设定过该名玩家的分数。你这次的更动没有被记录。\nYou have changed your score for this player within the last month. Your change was not recorded.")
return return
} }
if err != nil { if err != nil {
auditError(s, r.ChannelID, err) message.AuditError(s, r.ChannelID, err)
return return
} }

@ -1,10 +1,14 @@
package modules package modules
import "github.com/bwmarrin/discordgo" import (
"github.com/bwmarrin/discordgo"
"TerraOceanBot/discord/message"
)
type voteType struct { type voteType struct {
//TODO Add FormatName(name string) to clean up vote name //TODO Add FormatName(name string) to clean up vote name
EmbedBuilder func(id int, name string) *embed EmbedBuilder func(id int, name string) *message.Embed
ResultHandler func(s *discordgo.Session, id int, name string, isPositive bool) ResultHandler func(s *discordgo.Session, id int, name string, isPositive bool)
} }

@ -6,10 +6,11 @@ import (
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"TerraOceanBot/discord/config" "TerraOceanBot/discord/config"
"TerraOceanBot/discord/message"
) )
func createCustomEmbed(id int, name string) *embed { func createCustomEmbed(id int, name string) *message.Embed {
return initNewEmbed(config.CustomVoteTitle, "", config.CustomVoteColour). return message.InitNewEmbed(config.CustomVoteTitle, "", config.CustomVoteColour).
AddField(config.CustomVoteVoteID, strconv.Itoa(id)). AddField(config.CustomVoteVoteID, strconv.Itoa(id)).
AddField(config.CustomVoteContent, name) AddField(config.CustomVoteContent, name)
} }

@ -10,11 +10,12 @@ import (
"TerraOceanBot/db" "TerraOceanBot/db"
"TerraOceanBot/discord/backend" "TerraOceanBot/discord/backend"
"TerraOceanBot/discord/config" "TerraOceanBot/discord/config"
"TerraOceanBot/discord/message"
) )
func createInviteEmbed(id int, name string) *embed { func createInviteEmbed(id int, name string) *message.Embed {
list := strings.SplitN(name, ":", 2) list := strings.SplitN(name, ":", 2)
return initNewEmbed(config.EntryVoteTitle, "", config.EntryVoteColour). return message.InitNewEmbed(config.EntryVoteTitle, "", config.EntryVoteColour).
AddField(config.EntryVoteVoteID, strconv.Itoa(id)). AddField(config.EntryVoteVoteID, strconv.Itoa(id)).
AddField(config.EntryVoteApplicant, "<@"+list[0]+">"). AddField(config.EntryVoteApplicant, "<@"+list[0]+">").
AddField(config.EntryVoteReason, list[1]) AddField(config.EntryVoteReason, list[1])
@ -23,28 +24,28 @@ func createInviteEmbed(id int, name string) *embed {
func handleInviteResult(s *discordgo.Session, id int, name string, isPositive bool) { func handleInviteResult(s *discordgo.Session, id int, name string, isPositive bool) {
list := strings.SplitN(name, ":", 2) list := strings.SplitN(name, ":", 2)
if !isPositive { if !isPositive {
initNewEmbed(config.EntryVoteRejectNotificationTitle, config.EntryVoteRejectNotificationContent, config.ErrorColour). message.InitNewEmbed(config.EntryVoteRejectNotificationTitle, config.EntryVoteRejectNotificationContent, config.ErrorColour).
SendPM(s, list[0]) SendPM(s, list[0])
return return
} }
member, err := backend.GetMemberFromUserFriendlyName(s, list[0]) member, err := backend.GetMemberFromUserFriendlyName(s, list[0])
if err != nil { if err != nil {
auditError(s, "", err) message.AuditError(s, "", err)
return return
} }
err = s.GuildMemberRoleAdd(config.GuildID, member.User.ID, config.MemberRoleID) err = s.GuildMemberRoleAdd(config.GuildID, member.User.ID, config.MemberRoleID)
if err != nil { if err != nil {
auditError(s, "", err) message.AuditError(s, "", err)
return return
} }
initNewEmbed( message.InitNewEmbed(
config.EntryVoteSuccessWelcomeTitle, config.EntryVoteSuccessWelcomeTitle,
fmt.Sprintf(config.EntryVoteSuccessWelcomeDescription, member.User.ID, member.User.ID), fmt.Sprintf(config.EntryVoteSuccessWelcomeDescription, member.User.ID, member.User.ID),
config.SuccessColour, config.SuccessColour,
).Send(s, config.AnnounceInviteChannel) ).Send(s, config.AnnounceInviteChannel)
choices, err := db.GetAllVoteChoices(id) choices, err := db.GetAllVoteChoices(id)
if err != nil { if err != nil {
auditError(s, "", err) message.AuditError(s, "", err)
return return
} }
for _, choice := range choices { for _, choice := range choices {

@ -9,6 +9,7 @@ import (
"TerraOceanBot/db" "TerraOceanBot/db"
"TerraOceanBot/discord/config" "TerraOceanBot/discord/config"
"TerraOceanBot/discord/message"
"TerraOceanBot/server" "TerraOceanBot/server"
) )
@ -31,7 +32,7 @@ func CheckForVote(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
return return
} }
if err != nil { if err != nil {
auditError(s, r.ChannelID, err) message.AuditError(s, r.ChannelID, err)
return return
} }
@ -54,19 +55,19 @@ func CheckForVote(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
case emojiCheck: case emojiCheck:
value = db.NuclearOptionVote value = db.NuclearOptionVote
default: default:
auditInfo(s, "Reaction "+r.Emoji.Name+" was added to vote #"+strconv.Itoa(voteID)) message.AuditInfo(s, "Reaction "+r.Emoji.Name+" was added to vote #"+strconv.Itoa(voteID))
return return
} }
err = db.UpdateVote(voteID, r.UserID, value) err = db.UpdateVote(voteID, r.UserID, value)
if err == db.ErrForceRejectionVoteReuse { if err == db.ErrForceRejectionVoteReuse {
initNewEmbed(config.VoteErrorTitle, config.ErrorForceRejectionReuse, config.ErrorColour). message.InitNewEmbed(config.VoteErrorTitle, config.ErrorForceRejectionReuse, config.ErrorColour).
SendPM(s, r.UserID) SendPM(s, r.UserID)
return return
} }
if err == db.ErrVoteIsOver { if err == db.ErrVoteIsOver {
initNewEmbed(config.VoteErrorTitle, config.ErrorVoteHasEnded, config.ErrorColour). message.InitNewEmbed(config.VoteErrorTitle, config.ErrorVoteHasEnded, config.ErrorColour).
SendPM(s, r.UserID) SendPM(s, r.UserID)
return return
} }
@ -77,16 +78,16 @@ func CheckForVote(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
} }
if err != nil { if err != nil {
auditErrorPM(s, r.UserID, err) message.AuditErrorPM(s, r.UserID, err)
return return
} }
initNewEmbed(config.VoteSuccessfulTitle, "", config.SuccessColour). message.InitNewEmbed(config.VoteSuccessfulTitle, "", config.SuccessColour).
AddField(config.VoteSuccessfulVoteID, strconv.Itoa(voteID)). AddField(config.VoteSuccessfulVoteID, strconv.Itoa(voteID)).
AddField(config.VoteSuccessfulVoteName, voteName). AddField(config.VoteSuccessfulVoteName, voteName).
AddField(config.VoteSuccessfulDetectedVote, r.Emoji.Name). AddField(config.VoteSuccessfulDetectedVote, r.Emoji.Name).
SendPM(s, r.UserID) SendPM(s, r.UserID)
auditInfo(s, fmt.Sprintf("<@%s> has chosen %s for vote ID %d.", r.UserID, r.Emoji.Name, voteID)) message.AuditInfo(s, fmt.Sprintf("<@%s> has chosen %s for vote ID %d.", r.UserID, r.Emoji.Name, voteID))
checkForVoteResult(s, voteID) checkForVoteResult(s, voteID)
} }
@ -97,7 +98,7 @@ func VoteSuggestion(s *discordgo.Session, m *discordgo.MessageCreate) {
args := strings.SplitN(m.Content, " ", 2) args := strings.SplitN(m.Content, " ", 2)
if len(args) == 1 { if len(args) == 1 {
initNewEmbed( message.InitNewEmbed(
config.VoteSuggestionErrorTitle, config.VoteSuggestionErrorTitle,
config.ErrorVoteSuggestionNotEnoughInfo+config.VoteSuggestionNote, config.ErrorVoteSuggestionNotEnoughInfo+config.VoteSuggestionNote,
config.ErrorColour, config.ErrorColour,
@ -105,7 +106,7 @@ func VoteSuggestion(s *discordgo.Session, m *discordgo.MessageCreate) {
return return
} }
if len(args[1]) > 500 { if len(args[1]) > 500 {
initNewEmbed( message.InitNewEmbed(
config.VoteSuggestionErrorTitle, config.VoteSuggestionErrorTitle,
config.ErrorVoteSuggestionTooLong+config.VoteSuggestionNote, config.ErrorVoteSuggestionTooLong+config.VoteSuggestionNote,
config.ErrorColour, config.ErrorColour,
@ -117,15 +118,15 @@ func VoteSuggestion(s *discordgo.Session, m *discordgo.MessageCreate) {
case "custom": case "custom":
msg, err := s.ChannelMessageSend(config.VoteChannel, "正在准备新的一个投票…… Preparing for the next vote...") msg, err := s.ChannelMessageSend(config.VoteChannel, "正在准备新的一个投票…… Preparing for the next vote...")
if err != nil { if err != nil {
auditErrorPM(s, m.Author.ID, err) message.AuditErrorPM(s, m.Author.ID, err)
return return
} }
id, err := db.CreateCustomVote(msg.ID, args[1]) id, err := db.CreateCustomVote(msg.ID, args[1])
if err != nil { if err != nil {
auditErrorPM(s, m.Author.ID, err) message.AuditErrorPM(s, m.Author.ID, err)
return return
} }
auditInfo(s, fmt.Sprintf("Vote ID %d has been created by <@%s>.", id, m.Author.ID)) message.AuditInfo(s, fmt.Sprintf("Vote ID %d has been created by <@%s>.", id, m.Author.ID))
s.ChannelMessageEdit(config.VoteChannel, msg.ID, "") s.ChannelMessageEdit(config.VoteChannel, msg.ID, "")
createCustomEmbed(id, args[1]).Edit(s, config.VoteChannel, msg.ID) createCustomEmbed(id, args[1]).Edit(s, config.VoteChannel, msg.ID)
s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiOne) s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiOne)
@ -135,7 +136,7 @@ func VoteSuggestion(s *discordgo.Session, m *discordgo.MessageCreate) {
s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiFive) s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiFive)
server.VoteNotification() server.VoteNotification()
default: default:
initNewEmbed( message.InitNewEmbed(
config.VoteSuggestionErrorTitle, config.VoteSuggestionErrorTitle,
fmt.Sprintf(config.ErrorVoteSuggestionUnknownType, args[1])+config.VoteSuggestionNote, fmt.Sprintf(config.ErrorVoteSuggestionUnknownType, args[1])+config.VoteSuggestionNote,
config.ErrorColour, config.ErrorColour,

@ -10,6 +10,7 @@ import (
"TerraOceanBot/db" "TerraOceanBot/db"
"TerraOceanBot/discord/backend" "TerraOceanBot/discord/backend"
"TerraOceanBot/discord/config" "TerraOceanBot/discord/config"
"TerraOceanBot/discord/message"
) )
type confirmedResult struct { type confirmedResult struct {
@ -24,9 +25,9 @@ func ListenToVoteFinishes(s *discordgo.Session) {
for { for {
voteMutex.Lock() voteMutex.Lock()
for _, v := range toAnnounceResultList { for _, v := range toAnnounceResultList {
auditInfo(s, fmt.Sprintf("Announcing the result of vote %d.", v.VoteID)) message.AuditInfo(s, fmt.Sprintf("Announcing the result of vote %d.", v.VoteID))
if err := db.FinishVote(v.VoteID); err != nil { if err := db.FinishVote(v.VoteID); err != nil {
auditError(s, "", err) message.AuditError(s, "", err)
continue continue
} }
voteType, _ := db.GetVoteType(v.VoteID) voteType, _ := db.GetVoteType(v.VoteID)
@ -44,7 +45,7 @@ func ListenToVoteFinishes(s *discordgo.Session) {
func checkForVoteResult(s *discordgo.Session, id int) { func checkForVoteResult(s *discordgo.Session, id int) {
votes, err := db.GetAllVoteChoices(id) votes, err := db.GetAllVoteChoices(id)
if err != nil { if err != nil {
auditError(s, "", err) message.AuditError(s, "", err)
return return
} }
var currentScore, totalTrust float64 var currentScore, totalTrust float64
@ -55,7 +56,7 @@ func checkForVoteResult(s *discordgo.Session, id int) {
} }
trust, err := backend.GetTrust(s, vote.UserID) trust, err := backend.GetTrust(s, vote.UserID)
if err != nil { if err != nil {
auditError(s, "", err) message.AuditError(s, "", err)
return return
} }
currentScore += float64(vote.Value) * trust currentScore += float64(vote.Value) * trust
@ -64,7 +65,7 @@ func checkForVoteResult(s *discordgo.Session, id int) {
totalGlobalTrust, err := backend.GetTotalTrust(s) totalGlobalTrust, err := backend.GetTotalTrust(s)
if err != nil { if err != nil {
auditError(s, "", err) message.AuditError(s, "", err)
return return
} }
remainingTrust := totalGlobalTrust - totalTrust remainingTrust := totalGlobalTrust - totalTrust
@ -81,7 +82,7 @@ func checkForVoteResult(s *discordgo.Session, id int) {
return return
} }
} }
auditInfo(s, fmt.Sprintf("Rejection of vote ID %d has been confirmed.", id)) message.AuditInfo(s, fmt.Sprintf("Rejection of vote ID %d has been confirmed.", id))
toAnnounceResultList = append(toAnnounceResultList, confirmedResult{ toAnnounceResultList = append(toAnnounceResultList, confirmedResult{
VoteID: id, VoteID: id,
IsPositive: false, IsPositive: false,
@ -98,7 +99,7 @@ func checkForVoteResult(s *discordgo.Session, id int) {
return return
} }
} }
auditInfo(s, fmt.Sprintf("Acceptance of vote ID %d has been confirmed.", id)) message.AuditInfo(s, fmt.Sprintf("Acceptance of vote ID %d has been confirmed.", id))
toAnnounceResultList = append(toAnnounceResultList, confirmedResult{ toAnnounceResultList = append(toAnnounceResultList, confirmedResult{
VoteID: id, VoteID: id,
IsPositive: true, IsPositive: true,