rename message.go -> ennoblement_msg, cleanup in ennoblement_msg.go

pull/31/head
Dawid Wysokiński 2 years ago
parent 1153829a70
commit 9da466d526

@ -22,6 +22,11 @@ import (
"github.com/tribalwarshelp/dcbot/util/twutil"
)
const (
colorLostVillage = 0xff0000
colorConqueredVillage = 0x00ff00
)
var log = logrus.WithField("package", "cron")
type Config struct {
@ -224,14 +229,13 @@ func (c *Cron) checkEnnoblements() {
g.Observations.Contains(obs.Server, ennoblement.NewOwner.Tribe.ID) {
continue
}
newMsgDataConfig := newMessageConfig{
newMsgDataConfig := newEnnoblementMsgConfig{
host: version.Host,
server: obs.Server,
ennoblement: ennoblement,
t: messageTypeLost,
localizer: localizer,
}
lostVillagesBldr.Append(newMessage(newMsgDataConfig).String())
lostVillagesBldr.Append(newEnnoblementMsg(newMsgDataConfig).String())
}
}
@ -244,21 +248,20 @@ func (c *Cron) checkEnnoblements() {
continue
}
newMsgDataConfig := newMessageConfig{
newMsgDataConfig := newEnnoblementMsgConfig{
host: version.Host,
server: obs.Server,
ennoblement: ennoblement,
t: messageTypeConquer,
localizer: localizer,
}
conqueredVillagesBldr.Append(newMessage(newMsgDataConfig).String())
conqueredVillagesBldr.Append(newEnnoblementMsg(newMsgDataConfig).String())
}
}
}
}
timestamp := time.Now().Format(time.RFC3339)
if g.ConqueredVillagesChannelID != "" && !conqueredVillagesBldr.IsEmpty() {
if !conqueredVillagesBldr.IsEmpty() {
title := localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: message.CronConqueredVillagesTitle,
})
@ -267,12 +270,12 @@ func (c *Cron) checkEnnoblements() {
discord.
NewEmbed().
SetTitle(title).
SetColor(colorConqueredVillages).
SetColor(colorConqueredVillage).
SetFields(conqueredVillagesBldr.ToMessageEmbedFields()).
SetTimestamp(timestamp))
}
if g.LostVillagesChannelID != "" && !lostVillagesBldr.IsEmpty() {
if !lostVillagesBldr.IsEmpty() {
title := localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: message.CronLostVillagesTitle,
})
@ -281,7 +284,7 @@ func (c *Cron) checkEnnoblements() {
discord.
NewEmbed().
SetTitle(title).
SetColor(colorLostVillages).
SetColor(colorLostVillage).
SetFields(lostVillagesBldr.ToMessageEmbedFields()).
SetTimestamp(timestamp))
}

@ -10,17 +10,7 @@ import (
"github.com/tribalwarshelp/dcbot/util/twutil"
)
type messageType string
const (
messageTypeConquer messageType = "conquer"
messageTypeLost messageType = "lost"
colorLostVillages = 0xff0000
colorConqueredVillages = 0x00ff00
)
type checkEnnoblementsMsg struct {
t messageType
type ennoblementMsg struct {
server string
village string
villageURL string
@ -35,17 +25,15 @@ type checkEnnoblementsMsg struct {
localizer *i18n.Localizer
}
type newMessageConfig struct {
t messageType
type newEnnoblementMsgConfig struct {
host string
server string
ennoblement *twmodel.Ennoblement
localizer *i18n.Localizer
}
func newMessage(cfg newMessageConfig) checkEnnoblementsMsg {
data := checkEnnoblementsMsg{
t: cfg.t,
func newEnnoblementMsg(cfg newEnnoblementMsgConfig) ennoblementMsg {
msg := ennoblementMsg{
server: cfg.server,
village: "-",
oldOwnerName: "-",
@ -55,30 +43,30 @@ func newMessage(cfg newMessageConfig) checkEnnoblementsMsg {
localizer: cfg.localizer,
}
if !twutil.IsVillageNil(cfg.ennoblement.Village) {
data.village = cfg.ennoblement.Village.FullName()
data.villageURL = twurlbuilder.BuildVillageURL(cfg.server, cfg.host, cfg.ennoblement.Village.ID)
msg.village = cfg.ennoblement.Village.FullName()
msg.villageURL = twurlbuilder.BuildVillageURL(cfg.server, cfg.host, cfg.ennoblement.Village.ID)
}
if !twutil.IsPlayerNil(cfg.ennoblement.OldOwner) {
data.oldOwnerName = cfg.ennoblement.OldOwner.Name
data.oldOwnerURL = twurlbuilder.BuildPlayerURL(cfg.server, cfg.host, cfg.ennoblement.OldOwner.ID)
msg.oldOwnerName = cfg.ennoblement.OldOwner.Name
msg.oldOwnerURL = twurlbuilder.BuildPlayerURL(cfg.server, cfg.host, cfg.ennoblement.OldOwner.ID)
}
if !twutil.IsPlayerTribeNil(cfg.ennoblement.OldOwner) {
data.oldOwnerTribeTag = cfg.ennoblement.OldOwner.Tribe.Tag
data.oldOwnerTribeURL = twurlbuilder.BuildTribeURL(cfg.server, cfg.host, cfg.ennoblement.OldOwner.Tribe.ID)
msg.oldOwnerTribeTag = cfg.ennoblement.OldOwner.Tribe.Tag
msg.oldOwnerTribeURL = twurlbuilder.BuildTribeURL(cfg.server, cfg.host, cfg.ennoblement.OldOwner.Tribe.ID)
}
if !twutil.IsPlayerNil(cfg.ennoblement.NewOwner) {
data.newOwnerName = cfg.ennoblement.NewOwner.Name
data.newOwnerURL = twurlbuilder.BuildPlayerURL(cfg.server, cfg.host, cfg.ennoblement.NewOwner.ID)
msg.newOwnerName = cfg.ennoblement.NewOwner.Name
msg.newOwnerURL = twurlbuilder.BuildPlayerURL(cfg.server, cfg.host, cfg.ennoblement.NewOwner.ID)
}
if !twutil.IsPlayerTribeNil(cfg.ennoblement.NewOwner) {
data.newOwnerTribeTag = cfg.ennoblement.NewOwner.Tribe.Tag
data.newOwnerTribeURL = twurlbuilder.BuildTribeURL(cfg.server, cfg.host, cfg.ennoblement.NewOwner.Tribe.ID)
msg.newOwnerTribeTag = cfg.ennoblement.NewOwner.Tribe.Tag
msg.newOwnerTribeURL = twurlbuilder.BuildTribeURL(cfg.server, cfg.host, cfg.ennoblement.NewOwner.Tribe.ID)
}
return data
return msg
}
func (msg checkEnnoblementsMsg) String() string {
func (msg ennoblementMsg) String() string {
return msg.localizer.MustLocalize(&i18n.LocalizeConfig{
MessageID: message.CronCheckEnnoblementsMsgLine,
TemplateData: map[string]interface{}{