Skip to content

Commit

Permalink
Update log channels to new configs.
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmacdonald committed Jun 14, 2024
1 parent 34ce505 commit c9e9fa2
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 23 deletions.
2 changes: 1 addition & 1 deletion internal/ban/background.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Start(ctx context.Context, banUsecase domain.BanSteamUsecase, banNetUsecase
name = person.SteamID.String()
}

discordUsecase.SendPayload(domain.ChannelModLog, discord.BanExpiresMessage(ban, person, configUsecase.ExtURL(ban)))
discordUsecase.SendPayload(domain.ChannelBanLog, discord.BanExpiresMessage(ban, person, configUsecase.ExtURL(ban)))

slog.Info("Ban expired",
slog.String("reason", ban.Reason.String()),
Expand Down
2 changes: 1 addition & 1 deletion internal/ban/ban_asn_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s banASN) Unban(ctx context.Context, asnNum string) (bool, error) {
return false, errors.Join(errDrop, domain.ErrDropASNBan)
}

s.discord.SendPayload(domain.ChannelModLog, discord.UnbanASNMessage(asNum))
s.discord.SendPayload(domain.ChannelBanLog, discord.UnbanASNMessage(asNum))

return true, nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/ban/ban_steam_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ func (s banSteamUsecase) Ban(ctx context.Context, curUser domain.PersonInfo, ban
slog.Int64("sid64", banSteam.TargetID.Int64()))
}

s.discord.SendPayload(domain.ChannelModLog, discord.KickPlayerEmbed(target))
s.discord.SendPayload(domain.ChannelBanLog, discord.KickPlayerEmbed(target))
} else if banSteam.BanType == domain.NoComm {
if errSilence := s.state.Silence(ctx, banSteam.TargetID, banSteam.Reason); errSilence != nil && !errors.Is(errSilence, domain.ErrPlayerNotFound) {
slog.Error("Failed to silence player", log.ErrAttr(errSilence),
slog.Int64("sid64", banSteam.TargetID.Int64()))
}

s.discord.SendPayload(domain.ChannelModLog, discord.SilenceEmbed(target))
s.discord.SendPayload(domain.ChannelBanLog, discord.SilenceEmbed(target))
}

return nil
Expand Down Expand Up @@ -186,7 +186,7 @@ func (s banSteamUsecase) Unban(ctx context.Context, targetSID steamid.SteamID, r
return false, errors.Join(err, domain.ErrFetchPerson)
}

s.discord.SendPayload(domain.ChannelModLog, discord.UnbanMessage(s.config, person))
s.discord.SendPayload(domain.ChannelBanLog, discord.UnbanMessage(s.config, person))

return true, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func serveCmd() *cobra.Command { //nolint:maintidx
authUsecase := auth.NewAuthUsecase(auth.NewAuthRepository(db), configUsecase, personUsecase, banUsecase, serversUsecase)
go authUsecase.Start(ctx)

voteUsecase := votes.NewVoteUsecase(votes.NewVoteRepository(db), personUsecase, matchUsecase, discordUsecase, eventBroadcaster)
voteUsecase := votes.NewVoteUsecase(votes.NewVoteRepository(db), personUsecase, matchUsecase, discordUsecase, configUsecase, eventBroadcaster)
go voteUsecase.Start(ctx)

contestUsecase := contest.NewContestUsecase(contest.NewContestRepository(db))
Expand Down
29 changes: 25 additions & 4 deletions internal/discord/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -1148,14 +1148,35 @@ func NotificationMessage(message string, link string) *discordgo.MessageEmbed {
return msgEmbed.Embed().Truncate().MessageEmbed
}

func VoteResultMessage(result domain.VoteResult) *discordgo.MessageEmbed {
func VoteResultMessage(conf domain.Config, result domain.VoteResult, source domain.Person, target domain.Person) *discordgo.MessageEmbed {
avatarSource := domain.NewAvatarLinks(source.AvatarHash)
avatarTarget := domain.NewAvatarLinks(target.AvatarHash)

msgEmbed := NewEmbed("Vote Result")
if result.Success {
msgEmbed.emb.Color = ColourSuccess
} else {
msgEmbed.emb.Color = ColourWarn
}

msgEmbed.emb.Thumbnail = &discordgo.MessageEmbedThumbnail{
URL: avatarTarget.Full(),
}

msgEmbed.emb.Author = &discordgo.MessageEmbedAuthor{
URL: conf.ExtURL(source),
Name: source.PersonaName,
IconURL: avatarSource.Full(),
}

msgEmbed.Embed().
AddField("Initiator", result.SourceID.String()).
AddField("Target", result.TargetID.String()).
AddField("Caller SID", result.SourceID.String()).
AddField("Target", target.PersonaName).
AddField("Target SID", result.TargetID.String()).
AddField("Code", fmt.Sprintf("%d", result.Code)).
AddField("Success", strconv.FormatBool(result.Success)).
AddField("Server", strconv.FormatInt(int64(result.ServerID), 10))
AddField("Server", strconv.FormatInt(int64(result.ServerID), 10)).
InlineAllFields()

return msgEmbed.Embed().Truncate().MessageEmbed
}
Expand Down
2 changes: 1 addition & 1 deletion internal/news/news_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (h newsHandler) onAPIPostNewsCreate() gin.HandlerFunc {
return
}

ctx.JSON(http.StatusCreated, req)
ctx.JSON(http.StatusCreated, entry)

go h.discord.SendPayload(domain.ChannelModLog, discord.NewNewsMessage(req.BodyMD, req.Title))
}
Expand Down
10 changes: 5 additions & 5 deletions internal/report/report_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (h reportHandler) onAPIPostBanState() gin.HandlerFunc {

ctx.JSON(http.StatusOK, report)

h.discord.SendPayload(domain.ChannelModLog, discord.EditBanAppealStatusMessage())
h.discord.SendPayload(domain.ChannelModAppealLog, discord.EditBanAppealStatusMessage())
}
}

Expand Down Expand Up @@ -218,7 +218,7 @@ func (h reportHandler) onAPIPostReportCreate() gin.HandlerFunc {

msg := discord.NewInGameReportResponse(report, conf.ExtURL(report), currentUser, conf.ExtURL(currentUser), demoURL)

h.discord.SendPayload(domain.ChannelModLog, msg)
h.discord.SendPayload(domain.ChannelModAppealLog, msg)
}
}

Expand Down Expand Up @@ -443,7 +443,7 @@ func (h reportHandler) onAPIPostReportMessage() gin.HandlerFunc {

conf := h.config.Config()

h.discord.SendPayload(domain.ChannelModLog,
h.discord.SendPayload(domain.ChannelModAppealLog,
discord.NewReportMessageResponse(msg.MessageMD, conf.ExtURL(report), person, conf.ExtURL(person)))
}
}
Expand Down Expand Up @@ -516,7 +516,7 @@ func (h reportHandler) onAPIEditReportMessage() gin.HandlerFunc {
msg := discord.EditReportMessageResponse(req.BodyMD, existing.MessageMD,
conf.ExtURLRaw("/report/%d", existing.ReportID), curUser, conf.ExtURL(curUser))

h.discord.SendPayload(domain.ChannelModLog, msg)
h.discord.SendPayload(domain.ChannelModAppealLog, msg)
}
}

Expand Down Expand Up @@ -561,6 +561,6 @@ func (h reportHandler) onAPIDeleteReportMessage() gin.HandlerFunc {

conf := h.config.Config()

h.discord.SendPayload(domain.ChannelModLog, discord.DeleteReportMessage(existing, curUser, conf.ExtURL(curUser)))
h.discord.SendPayload(domain.ChannelModAppealLog, discord.DeleteReportMessage(existing, curUser, conf.ExtURL(curUser)))
}
}
28 changes: 21 additions & 7 deletions internal/votes/vote_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@ import (
)

type voteUsecase struct {
repository domain.VoteRepository
persons domain.PersonUsecase
matches domain.MatchUsecase
discord domain.DiscordUsecase
repository domain.VoteRepository
persons domain.PersonUsecase
matches domain.MatchUsecase
discord domain.DiscordUsecase
config domain.ConfigUsecase

broadcaster *fp.Broadcaster[logparse.EventType, logparse.ServerEvent]
}

func NewVoteUsecase(repository domain.VoteRepository, persons domain.PersonUsecase, matched domain.MatchUsecase,
discord domain.DiscordUsecase, broadcaster *fp.Broadcaster[logparse.EventType, logparse.ServerEvent],
discord domain.DiscordUsecase, config domain.ConfigUsecase, broadcaster *fp.Broadcaster[logparse.EventType, logparse.ServerEvent],
) domain.VoteUsecase {
return &voteUsecase{
repository: repository,
persons: persons,
matches: matched,
discord: discord,
config: config,
broadcaster: broadcaster,
}
}
Expand Down Expand Up @@ -153,11 +156,22 @@ func (u voteUsecase) Start(ctx context.Context) {
slog.Error("Failed to add vote result", log.ErrAttr(err))
}

u.discord.SendPayload(domain.ChannelModVoteLog, discord.VoteResultMessage(result))

recent = append(recent, result)

delete(active, evt.ServerID)

source, errSource := u.persons.GetOrCreatePersonBySteamID(ctx, result.SourceID)
if errSource != nil {
slog.Error("Failed to load vote source", log.ErrAttr(errSource), slog.String("steam_id", result.SourceID.String()))
}

target, errTarget := u.persons.GetOrCreatePersonBySteamID(ctx, result.SourceID)
if errTarget != nil {
slog.Error("Failed to load vote target", log.ErrAttr(errSource), slog.String("steam_id", result.TargetID.String()))
}

u.discord.SendPayload(domain.ChannelModVoteLog, discord.VoteResultMessage(u.config.Config(), result, source, target))

}
}
}
Expand Down

0 comments on commit c9e9fa2

Please sign in to comment.