Skip to content

Commit

Permalink
Reputation is finalized. Ready for v0.2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
wneessen committed Dec 4, 2022
1 parent 6835a90 commit 312bffe
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 64 deletions.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
32 changes: 32 additions & 0 deletions bot/format.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bot

import "strings"

// List of icons/emojis
const (
IconGold = "\U0001F7E1"
Expand All @@ -26,3 +28,33 @@ func changeIcon[V int | int64 | float32 | float64](v V) string {
}
return IconDecrease
}

// dbEmissaryToName converts the emissary name in the DB to the human readable format
func dbEmissaryToName(e string) string {
// factiong|hunterscall|merchantalliance|bilgerats|talltales|athenasfortune|` +
// `goldhoarders|orderofsouls|reapersbones
switch strings.ToLower(e) {
case "factiong":
return "Guardians of Fortune"
case "factionb":
return "Servants of the Flame"
case "hunterscall":
return "Hunter's Call"
case "merchantalliance":
return "Merchant Alliance"
case "bilgerats":
return "Bilge Rats"
case "talltales":
return "Tall Tales"
case "athenasfortune":
return "Athena's Forutne"
case "goldhoarders":
return "Gold Hoarders"
case "orderofsouls":
return "Order of Souls"
case "reapersbones":
return "Reaper's Bones"
default:
return ""
}
}
5 changes: 4 additions & 1 deletion bot/sc_handler_sot_allegiance.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type SoTAllegiance struct {
ShipsSunk int64
MaxStreak int64
TotalGold int64
Icon string
}

// SlashCmdSoTAllegiance handles the /allegiance slash command
Expand Down Expand Up @@ -81,7 +82,7 @@ func (b *Bot) SlashCmdSoTAllegiance(s *discordgo.Session, i *discordgo.Interacti
{
Title: fmt.Sprintf("Your current allegiance values for the **%s**:", a.Allegiance),
Thumbnail: &discordgo.MessageEmbedThumbnail{
URL: fmt.Sprintf("%s/allegiance/%s.png", AssetsBaseURL, al),
URL: fmt.Sprintf("%s/factions/%s.png", AssetsBaseURL, a.Icon),
},
Type: discordgo.EmbedTypeRich,
Fields: ef,
Expand Down Expand Up @@ -148,6 +149,7 @@ func (b *Bot) SoTGetAllegiance(rq *Requester, at string) (SoTAllegiance, error)
a.TotalGold = v
}
a.Allegiance = "Guardians of Fortune"
a.Icon = "factiong"
}
case "servants":
for _, d := range al.Stats {
Expand All @@ -168,6 +170,7 @@ func (b *Bot) SoTGetAllegiance(rq *Requester, at string) (SoTAllegiance, error)
}
}
a.Allegiance = "Servants of the Flame"
a.Icon = "factionb"
}

return a, nil
Expand Down
88 changes: 39 additions & 49 deletions bot/sc_handler_sot_reputation.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (b *Bot) SlashCmdSoTReputation(s *discordgo.Session, i *discordgo.Interacti
return fmt.Errorf("provided option value is not a string")
}

re, err := regexp.Compile(`^(?i:factiong|hunterscall|merchantalliance|bilgerats|talltales|athenasfortune|` +
`goldhoarders|orderofsouls|reapersbones)$`)
re, err := regexp.Compile(`^(?i:factiong|hunterscall|merchantalliance|bilgerats|athenasfortune|` +
`goldhoarders|orderofsouls|reapersbones|factionb)$`)
if err != nil {
return err
}
Expand All @@ -70,62 +70,52 @@ func (b *Bot) SlashCmdSoTReputation(s *discordgo.Session, i *discordgo.Interacti
return err
}

/*
rp, err := b.SoTGetReputation(r)
if err != nil {
return err
}
*/
b.Log.Debug().Msgf("UID: %d, Emi: %s", r.User.ID, fa)
ur, err := b.Model.UserReputation.GetByUserIDAtTime(r.User.ID, fa, time.Now().Add(time.Minute*-40))
if err := b.StoreSoTUserReputation(r.User); err != nil {
b.Log.Warn().Msgf("failed to store user reputation data to database")
}
ur, err := b.Model.UserReputation.GetByUserID(r.User.ID, fa)
if err != nil {
return err
}
b.Log.Debug().Msgf("FACTIONS: %+v\n", ur)

/*
var ef []*discordgo.MessageEmbedField
ef = append(ef, &discordgo.MessageEmbedField{
Name: "Faction/Company",
Value: l.Name,
Inline: false,
})
var ef []*discordgo.MessageEmbedField
ef = append(ef, &discordgo.MessageEmbedField{
Name: "Motto",
Value: ur.Motto,
Inline: false,
})
if ur.Rank != "" {
ef = append(ef, &discordgo.MessageEmbedField{
Name: "Current Title",
Value: l.BandTitle,
Name: "Rank",
Value: ur.Rank,
Inline: false,
})
ef = append(ef, &discordgo.MessageEmbedField{
Name: "Emissary value",
Value: fmt.Sprintf("%s **%d**", IconAncientCoin, l.Score),
Inline: true,
})
ef = append(ef, &discordgo.MessageEmbedField{
Name: "Ledger position",
Value: fmt.Sprintf("%s **%d**", IconGauge, l.Rank),
Inline: true,
})
ef = append(ef, &discordgo.MessageEmbedField{
Name: "Next level in",
Value: fmt.Sprintf("%s **%d** points", IconIncrease, l.ToNextRank),
Inline: true,
})
e := []*discordgo.MessageEmbed{
{
Title: "Your global ledger in Sea of Thieves:",
Thumbnail: &discordgo.MessageEmbedThumbnail{
URL: fmt.Sprintf("%s/ledger/%s%d.png", AssetsBaseURL, fa, 4-l.Band),
},
Type: discordgo.EmbedTypeRich,
Fields: ef,
}
ef = append(ef, &discordgo.MessageEmbedField{
Name: "Level",
Value: fmt.Sprintf("%s **%d**", IconGauge, ur.Level),
Inline: true,
})
ef = append(ef, &discordgo.MessageEmbedField{
Name: "XP in current level",
Value: fmt.Sprintf("%s **%d/%d**", IconIncrease, ur.Experience, ur.ExperienceNextLevel),
Inline: true,
})

e := []*discordgo.MessageEmbed{
{
Title: fmt.Sprintf("Your user reputation with **%s**", dbEmissaryToName(ur.Emissary)),
Thumbnail: &discordgo.MessageEmbedThumbnail{
URL: fmt.Sprintf("%s/factions/%s.png", AssetsBaseURL, fa),
},
}
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}
Type: discordgo.EmbedTypeRich,
Fields: ef,
},
}
if _, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Embeds: &e}); err != nil {
return err
}

*/
return nil
}

Expand Down
28 changes: 14 additions & 14 deletions model/user_reputation.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,34 @@ type UserReputation struct {
CreateTime time.Time `json:"createTime"`
}

/*
// GetByUserID retrieves the User details from the database based on the given User ID
func (m UserStatModel) GetByUserID(i int64) (*UserStat, error) {
q := `SELECT id, user_id, title, gold, doubloons, ancient_coins, kraken, megalodon, chests, ships, vomit, distance, ctime
FROM user_stats s
WHERE s.user_id = $1
func (m UserReputationModel) GetByUserID(i int64, e string) (*UserReputation, error) {
q := `SELECT id, user_id, emissary, motto, rank, lvl, xp, next_lvl, xp_next_lvl, titlestotal, titlesunlocked,
emblemstotal, emblemsunlocked, itemstotal, itemsunlocked, ctime
FROM user_reputation r
WHERE r.user_id = $1
AND LOWER(r.emissary) = LOWER($2)
ORDER BY id DESC
LIMIT 1`

var us UserStat
var ur UserReputation
ctx, cancel := context.WithTimeout(context.Background(), SQLTimeout)
defer cancel()

row := m.DB.QueryRowContext(ctx, q, i)
err := row.Scan(&us.ID, &us.UserID, &us.Title, &us.Gold, &us.Doubloons, &us.AncientCoins, &us.KrakenDefeated,
&us.MegalodonEnounter, &us.ChestsHandedIn, &us.ShipsSunk, &us.VomittedTimes, &us.DistanceSailed,
&us.CreateTime)
row := m.DB.QueryRowContext(ctx, q, i, e)
err := row.Scan(&ur.ID, &ur.UserID, &ur.Emissary, &ur.Motto, &ur.Rank, &ur.Level, &ur.Experience,
&ur.NextLevel, &ur.ExperienceNextLevel, &ur.TitlesTotal, &ur.TitlesUnlocked, &ur.EmblemsTotal,
&ur.EmblemsUnlocked, &ur.ItemsTotal, &ur.ItemsUnlocked, &ur.CreateTime)
if err != nil {
switch {
case errors.Is(err, sql.ErrNoRows):
return &us, ErrUserStatNotExistent
return &ur, ErrUserRepNotExistent
default:
return &us, err
return &ur, err
}
}
return &us, nil
return &ur, nil
}
*/

// GetByUserIDAtTime retrieves the User details from the database based on the given User ID at a specific
// point of time
Expand Down

0 comments on commit 312bffe

Please sign in to comment.