2023-10-31 22:40:14 +00:00
|
|
|
package person
|
|
|
|
|
|
|
|
import (
|
2024-02-04 10:56:21 +00:00
|
|
|
"time"
|
|
|
|
|
2024-01-29 23:46:22 +00:00
|
|
|
"github.com/ectrc/snow/aid"
|
2023-10-31 22:40:14 +00:00
|
|
|
"github.com/ectrc/snow/storage"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Person struct {
|
2023-11-05 01:58:00 +00:00
|
|
|
ID string
|
2023-10-31 22:40:14 +00:00
|
|
|
DisplayName string
|
2024-02-04 15:21:16 +00:00
|
|
|
RefundTickets int
|
2024-02-09 21:51:26 +00:00
|
|
|
Permissions Permission
|
2023-11-05 01:58:00 +00:00
|
|
|
AthenaProfile *Profile
|
2023-10-31 22:40:14 +00:00
|
|
|
CommonCoreProfile *Profile
|
2023-11-03 23:48:50 +00:00
|
|
|
CommonPublicProfile *Profile
|
2023-11-06 22:41:52 +00:00
|
|
|
Profile0Profile *Profile
|
2023-12-03 20:16:40 +00:00
|
|
|
CollectionsProfile *Profile
|
2023-12-08 15:35:00 +00:00
|
|
|
CreativeProfile *Profile
|
2023-12-10 00:52:59 +00:00
|
|
|
Discord *storage.DB_DiscordPerson
|
2024-02-10 01:55:56 +00:00
|
|
|
BanHistory aid.GenericSyncMap[storage.DB_BanStatus]
|
2024-01-30 16:34:17 +00:00
|
|
|
Relationships aid.GenericSyncMap[Relationship]
|
2024-02-11 19:09:23 +00:00
|
|
|
Parties aid.GenericSyncMap[Party]
|
2024-02-14 20:30:55 +00:00
|
|
|
Invites aid.GenericSyncMap[PartyInvite]
|
2024-02-17 14:40:17 +00:00
|
|
|
Intentions aid.GenericSyncMap[PartyIntention]
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewPerson() *Person {
|
|
|
|
return &Person{
|
|
|
|
ID: uuid.New().String(),
|
2023-11-01 01:24:42 +00:00
|
|
|
DisplayName: uuid.New().String(),
|
2024-02-09 21:51:26 +00:00
|
|
|
Permissions: 0,
|
2024-02-04 15:21:16 +00:00
|
|
|
RefundTickets: 3,
|
2024-01-03 23:25:17 +00:00
|
|
|
AthenaProfile: NewProfile("athena"),
|
|
|
|
CommonCoreProfile: NewProfile("common_core"),
|
|
|
|
CommonPublicProfile: NewProfile("common_public"),
|
|
|
|
Profile0Profile: NewProfile("profile0"),
|
|
|
|
CollectionsProfile: NewProfile("collections"),
|
|
|
|
CreativeProfile: NewProfile("creative"),
|
2024-02-12 20:29:02 +00:00
|
|
|
BanHistory: aid.GenericSyncMap[storage.DB_BanStatus]{},
|
|
|
|
Relationships: aid.GenericSyncMap[Relationship]{},
|
|
|
|
Parties: aid.GenericSyncMap[Party]{},
|
2024-02-14 20:30:55 +00:00
|
|
|
Invites: aid.GenericSyncMap[PartyInvite]{},
|
2024-02-17 14:40:17 +00:00
|
|
|
Intentions: aid.GenericSyncMap[PartyIntention]{},
|
2024-01-03 23:25:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPersonWithCustomID(id string) *Person {
|
|
|
|
return &Person{
|
|
|
|
ID: id,
|
|
|
|
DisplayName: uuid.New().String(),
|
2024-02-09 21:51:26 +00:00
|
|
|
Permissions: 0,
|
2024-02-04 15:21:16 +00:00
|
|
|
RefundTickets: 3,
|
2023-10-31 23:19:52 +00:00
|
|
|
AthenaProfile: NewProfile("athena"),
|
|
|
|
CommonCoreProfile: NewProfile("common_core"),
|
2023-11-03 23:48:50 +00:00
|
|
|
CommonPublicProfile: NewProfile("common_public"),
|
2023-11-06 22:41:52 +00:00
|
|
|
Profile0Profile: NewProfile("profile0"),
|
2023-12-03 20:16:40 +00:00
|
|
|
CollectionsProfile: NewProfile("collections"),
|
2023-12-08 15:35:00 +00:00
|
|
|
CreativeProfile: NewProfile("creative"),
|
2024-02-12 20:29:02 +00:00
|
|
|
BanHistory: aid.GenericSyncMap[storage.DB_BanStatus]{},
|
|
|
|
Relationships: aid.GenericSyncMap[Relationship]{},
|
|
|
|
Parties: aid.GenericSyncMap[Party]{},
|
2024-02-14 20:30:55 +00:00
|
|
|
Invites: aid.GenericSyncMap[PartyInvite]{},
|
2024-02-17 14:40:17 +00:00
|
|
|
Intentions: aid.GenericSyncMap[PartyIntention]{},
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-03 23:48:50 +00:00
|
|
|
func Find(personId string) *Person {
|
2023-11-05 01:58:00 +00:00
|
|
|
if cache == nil {
|
|
|
|
cache = NewPersonsCacheMutex()
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
|
2023-11-05 01:58:00 +00:00
|
|
|
cachedPerson := cache.GetPerson(personId)
|
|
|
|
if cachedPerson != nil {
|
|
|
|
return cachedPerson
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
2023-11-05 01:58:00 +00:00
|
|
|
|
|
|
|
person := storage.Repo.GetPersonFromDB(personId)
|
|
|
|
if person == nil {
|
|
|
|
return nil
|
2023-11-03 23:48:50 +00:00
|
|
|
}
|
2023-11-05 01:58:00 +00:00
|
|
|
|
2024-01-29 23:46:22 +00:00
|
|
|
return findHelper(person, false, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func FindShallow(personId string) *Person {
|
|
|
|
if cache == nil {
|
|
|
|
cache = NewPersonsCacheMutex()
|
|
|
|
}
|
|
|
|
|
|
|
|
cachedPerson := cache.GetPerson(personId)
|
|
|
|
if cachedPerson != nil {
|
|
|
|
return cachedPerson
|
|
|
|
}
|
|
|
|
|
|
|
|
person := storage.Repo.GetPersonFromDB(personId)
|
|
|
|
if person == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-31 00:16:57 +00:00
|
|
|
return findHelper(person, true, false)
|
2023-11-03 23:48:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func FindByDisplay(displayName string) *Person {
|
2023-11-05 01:58:00 +00:00
|
|
|
if cache == nil {
|
|
|
|
cache = NewPersonsCacheMutex()
|
|
|
|
}
|
|
|
|
|
2023-12-10 00:52:59 +00:00
|
|
|
cachedPerson := cache.GetPersonByDisplay(displayName)
|
|
|
|
if cachedPerson != nil {
|
|
|
|
return cachedPerson
|
|
|
|
}
|
|
|
|
|
2023-11-05 01:58:00 +00:00
|
|
|
person := storage.Repo.GetPersonByDisplayFromDB(displayName)
|
2023-11-03 23:48:50 +00:00
|
|
|
if person == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-29 23:46:22 +00:00
|
|
|
return findHelper(person, false, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func FindByDisplayShallow(displayName string) *Person {
|
|
|
|
if cache == nil {
|
|
|
|
cache = NewPersonsCacheMutex()
|
|
|
|
}
|
|
|
|
|
|
|
|
cachedPerson := cache.GetPersonByDisplay(displayName)
|
|
|
|
if cachedPerson != nil {
|
|
|
|
return cachedPerson
|
|
|
|
}
|
|
|
|
|
|
|
|
person := storage.Repo.GetPersonByDisplayFromDB(displayName)
|
|
|
|
if person == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-31 00:16:57 +00:00
|
|
|
return findHelper(person, true, false)
|
2023-12-10 00:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func FindByDiscord(discordId string) *Person {
|
|
|
|
if cache == nil {
|
|
|
|
cache = NewPersonsCacheMutex()
|
|
|
|
}
|
|
|
|
|
|
|
|
cachedPerson := cache.GetPersonByDiscordID(discordId)
|
2023-11-05 01:58:00 +00:00
|
|
|
if cachedPerson != nil {
|
|
|
|
return cachedPerson
|
|
|
|
}
|
|
|
|
|
2023-12-10 00:52:59 +00:00
|
|
|
person := storage.Repo.GetPersonByDiscordIDFromDB(discordId)
|
|
|
|
if person == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-29 23:46:22 +00:00
|
|
|
return findHelper(person, false, true)
|
2023-11-05 01:58:00 +00:00
|
|
|
}
|
|
|
|
|
2024-01-29 23:46:22 +00:00
|
|
|
func findHelper(databasePerson *storage.DB_Person, shallow bool, save bool) *Person {
|
2023-11-03 23:48:50 +00:00
|
|
|
athenaProfile := NewProfile("athena")
|
|
|
|
commonCoreProfile := NewProfile("common_core")
|
|
|
|
commonPublicProfile := NewProfile("common_public")
|
|
|
|
profile0 := NewProfile("profile0")
|
2023-12-03 20:16:40 +00:00
|
|
|
collectionsProfile := NewProfile("collections")
|
2023-12-08 15:35:00 +00:00
|
|
|
creativeProfile := NewProfile("creative")
|
2023-11-03 23:48:50 +00:00
|
|
|
|
2023-11-05 01:58:00 +00:00
|
|
|
for _, profile := range databasePerson.Profiles {
|
2023-11-03 23:48:50 +00:00
|
|
|
if profile.Type == "athena" {
|
|
|
|
athenaProfile.ID = profile.ID
|
|
|
|
athenaProfile = FromDatabaseProfile(&profile)
|
|
|
|
}
|
|
|
|
|
|
|
|
if profile.Type == "common_core" {
|
|
|
|
commonCoreProfile.ID = profile.ID
|
|
|
|
commonCoreProfile = FromDatabaseProfile(&profile)
|
|
|
|
}
|
|
|
|
|
|
|
|
if profile.Type == "common_public" {
|
|
|
|
commonPublicProfile.ID = profile.ID
|
|
|
|
commonPublicProfile = FromDatabaseProfile(&profile)
|
|
|
|
}
|
|
|
|
|
|
|
|
if profile.Type == "profile0" {
|
|
|
|
profile0.ID = profile.ID
|
|
|
|
profile0 = FromDatabaseProfile(&profile)
|
|
|
|
}
|
2023-12-03 20:16:40 +00:00
|
|
|
|
|
|
|
if profile.Type == "collections" {
|
|
|
|
collectionsProfile.ID = profile.ID
|
|
|
|
collectionsProfile = FromDatabaseProfile(&profile)
|
|
|
|
}
|
2023-12-08 15:35:00 +00:00
|
|
|
|
|
|
|
if profile.Type == "creative" {
|
|
|
|
creativeProfile.ID = profile.ID
|
|
|
|
creativeProfile = FromDatabaseProfile(&profile)
|
|
|
|
}
|
2023-11-03 23:48:50 +00:00
|
|
|
}
|
2023-11-05 01:58:00 +00:00
|
|
|
|
|
|
|
person := &Person{
|
|
|
|
ID: databasePerson.ID,
|
|
|
|
DisplayName: databasePerson.DisplayName,
|
2024-02-09 21:51:26 +00:00
|
|
|
Permissions: Permission(databasePerson.Permissions),
|
2024-02-10 01:55:56 +00:00
|
|
|
BanHistory: aid.GenericSyncMap[storage.DB_BanStatus]{},
|
2023-11-03 23:48:50 +00:00
|
|
|
AthenaProfile: athenaProfile,
|
|
|
|
CommonCoreProfile: commonCoreProfile,
|
|
|
|
CommonPublicProfile: commonPublicProfile,
|
2023-11-06 22:41:52 +00:00
|
|
|
Profile0Profile: profile0,
|
2023-12-03 20:16:40 +00:00
|
|
|
CollectionsProfile: collectionsProfile,
|
2023-12-08 15:35:00 +00:00
|
|
|
CreativeProfile: creativeProfile,
|
2023-12-10 00:52:59 +00:00
|
|
|
Discord: &databasePerson.Discord,
|
2024-02-04 15:21:16 +00:00
|
|
|
RefundTickets: databasePerson.RefundTickets,
|
2024-01-30 16:34:17 +00:00
|
|
|
Relationships: aid.GenericSyncMap[Relationship]{},
|
2024-02-12 20:29:02 +00:00
|
|
|
Parties: aid.GenericSyncMap[Party]{},
|
2024-02-14 20:30:55 +00:00
|
|
|
Invites: aid.GenericSyncMap[PartyInvite]{},
|
2024-02-17 14:40:17 +00:00
|
|
|
Intentions: aid.GenericSyncMap[PartyIntention]{},
|
2024-01-29 23:46:22 +00:00
|
|
|
}
|
|
|
|
|
2024-02-10 01:55:56 +00:00
|
|
|
for _, ban := range databasePerson.BanHistory {
|
|
|
|
person.BanHistory.Set(ban.ID, &ban)
|
|
|
|
}
|
|
|
|
|
2024-01-29 23:46:22 +00:00
|
|
|
if !shallow {
|
|
|
|
person.LoadRelationships()
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
2023-11-05 01:58:00 +00:00
|
|
|
|
2024-01-29 23:46:22 +00:00
|
|
|
if save {
|
|
|
|
cache.SavePerson(person)
|
|
|
|
}
|
2024-02-19 01:49:14 +00:00
|
|
|
|
2023-11-05 01:58:00 +00:00
|
|
|
return person
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func AllFromDatabase() []*Person {
|
|
|
|
var persons []*Person
|
|
|
|
for _, person := range storage.Repo.GetAllPersons() {
|
2023-11-03 23:48:50 +00:00
|
|
|
persons = append(persons, Find(person.ID))
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return persons
|
|
|
|
}
|
|
|
|
|
2023-11-05 02:43:21 +00:00
|
|
|
func AllFromCache() []*Person {
|
|
|
|
if cache == nil {
|
|
|
|
cache = NewPersonsCacheMutex()
|
|
|
|
}
|
|
|
|
|
|
|
|
var persons []*Person
|
|
|
|
cache.RangeEntry(func(key string, value *CacheEntry) bool {
|
|
|
|
persons = append(persons, value.Entry)
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
return persons
|
|
|
|
}
|
|
|
|
|
2023-11-03 23:48:50 +00:00
|
|
|
func (p *Person) GetProfileFromType(profileType string) *Profile {
|
|
|
|
switch profileType {
|
|
|
|
case "athena":
|
|
|
|
return p.AthenaProfile
|
|
|
|
case "common_core":
|
|
|
|
return p.CommonCoreProfile
|
|
|
|
case "common_public":
|
|
|
|
return p.CommonPublicProfile
|
|
|
|
case "profile0":
|
2023-11-06 22:41:52 +00:00
|
|
|
return p.Profile0Profile
|
2023-12-03 20:16:40 +00:00
|
|
|
case "collections":
|
|
|
|
return p.CollectionsProfile
|
2023-12-08 15:35:00 +00:00
|
|
|
case "creative":
|
|
|
|
return p.CreativeProfile
|
2023-11-03 23:48:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-10-31 22:40:14 +00:00
|
|
|
func (p *Person) Save() {
|
2023-11-05 01:58:00 +00:00
|
|
|
dbPerson := p.ToDatabase()
|
|
|
|
storage.Repo.SavePerson(dbPerson)
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
|
2024-02-04 01:25:44 +00:00
|
|
|
func (p *Person) SaveShallow() {
|
|
|
|
dbPerson := p.ToDatabaseShallow()
|
|
|
|
storage.Repo.SavePerson(dbPerson)
|
|
|
|
}
|
|
|
|
|
2024-02-10 01:55:56 +00:00
|
|
|
func (p *Person) AddBan(reason string, issuedBy string, expiry ...string) {
|
|
|
|
t := time.Now().AddDate(0, 0, 7)
|
|
|
|
|
|
|
|
if len(expiry) > 0 && expiry[0] != "" {
|
|
|
|
parsed, err := aid.ParseDuration(expiry[0])
|
|
|
|
if err == nil {
|
|
|
|
t = time.Now().Add(parsed)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ban := &storage.DB_BanStatus{
|
2024-02-04 10:56:21 +00:00
|
|
|
ID: uuid.New().String(),
|
|
|
|
PersonID: p.ID,
|
2024-02-10 01:55:56 +00:00
|
|
|
IssuedBy: issuedBy,
|
|
|
|
Reason: reason,
|
|
|
|
Expiry: t,
|
|
|
|
}
|
2024-02-04 10:56:21 +00:00
|
|
|
|
2024-02-10 01:55:56 +00:00
|
|
|
p.BanHistory.Set(ban.ID, ban)
|
|
|
|
storage.Repo.SaveBanStatus(ban)
|
2023-12-14 19:47:54 +00:00
|
|
|
}
|
|
|
|
|
2024-02-10 01:55:56 +00:00
|
|
|
func (p *Person) ClearBans() {
|
|
|
|
p.BanHistory.Range(func(key string, ban *storage.DB_BanStatus) bool {
|
|
|
|
ban.Expiry = time.Now()
|
|
|
|
storage.Repo.SaveBanStatus(ban)
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Person) GetLatestActiveBan() *storage.DB_BanStatus {
|
|
|
|
var latestBan *storage.DB_BanStatus
|
|
|
|
p.BanHistory.Range(func(key string, ban *storage.DB_BanStatus) bool {
|
|
|
|
if latestBan == nil || ban.Expiry.After(latestBan.Expiry) {
|
|
|
|
latestBan = ban
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
if latestBan != nil && latestBan.Expiry.Before(time.Now()) {
|
|
|
|
return nil
|
2024-02-04 10:56:21 +00:00
|
|
|
}
|
|
|
|
|
2024-02-10 01:55:56 +00:00
|
|
|
return latestBan
|
2023-12-14 19:47:54 +00:00
|
|
|
}
|
|
|
|
|
2024-02-09 21:51:26 +00:00
|
|
|
func (p *Person) AddPermission(permission Permission) {
|
|
|
|
p.Permissions |= permission
|
2024-02-04 01:25:44 +00:00
|
|
|
p.SaveShallow()
|
2023-12-14 19:47:54 +00:00
|
|
|
}
|
|
|
|
|
2024-02-09 21:51:26 +00:00
|
|
|
func (p *Person) RemovePermission(permission Permission) {
|
|
|
|
p.Permissions &= ^permission
|
2024-02-04 01:25:44 +00:00
|
|
|
p.SaveShallow()
|
2023-12-14 19:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Person) HasPermission(permission Permission) bool {
|
2024-02-10 00:33:10 +00:00
|
|
|
// if permission == PermissionAll && permission != PermissionOwner {
|
|
|
|
// return p.Permissions == PermissionAll
|
|
|
|
// }
|
2023-12-14 19:47:54 +00:00
|
|
|
|
2024-02-09 21:51:26 +00:00
|
|
|
return p.Permissions & permission != 0
|
2023-12-14 19:47:54 +00:00
|
|
|
}
|
|
|
|
|
2023-10-31 22:40:14 +00:00
|
|
|
func (p *Person) ToDatabase() *storage.DB_Person {
|
|
|
|
dbPerson := storage.DB_Person{
|
|
|
|
ID: p.ID,
|
|
|
|
DisplayName: p.DisplayName,
|
2024-02-09 21:51:26 +00:00
|
|
|
Permissions: int64(p.Permissions),
|
2024-02-10 01:55:56 +00:00
|
|
|
BanHistory: []storage.DB_BanStatus{},
|
2024-02-04 15:21:16 +00:00
|
|
|
RefundTickets: p.RefundTickets,
|
2023-10-31 22:40:14 +00:00
|
|
|
Profiles: []storage.DB_Profile{},
|
2023-12-11 00:06:41 +00:00
|
|
|
Stats: []storage.DB_SeasonStat{},
|
2023-12-14 19:47:54 +00:00
|
|
|
Discord: storage.DB_DiscordPerson{},
|
2023-12-10 23:54:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if p.Discord != nil {
|
|
|
|
dbPerson.Discord = *p.Discord
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
|
2023-11-01 00:05:17 +00:00
|
|
|
profilesToConvert := map[string]*Profile{
|
|
|
|
"common_core": p.CommonCoreProfile,
|
2023-11-03 23:48:50 +00:00
|
|
|
"athena": p.AthenaProfile,
|
|
|
|
"common_public": p.CommonPublicProfile,
|
2023-11-06 22:41:52 +00:00
|
|
|
"profile0": p.Profile0Profile,
|
2023-12-03 20:16:40 +00:00
|
|
|
"collections": p.CollectionsProfile,
|
2023-12-08 15:35:00 +00:00
|
|
|
"creative": p.CreativeProfile,
|
2023-11-01 00:05:17 +00:00
|
|
|
}
|
2023-10-31 22:40:14 +00:00
|
|
|
|
2024-02-10 01:55:56 +00:00
|
|
|
p.BanHistory.Range(func(key string, ban *storage.DB_BanStatus) bool {
|
|
|
|
dbPerson.BanHistory = append(dbPerson.BanHistory, *ban)
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2023-10-31 22:40:14 +00:00
|
|
|
for profileType, profile := range profilesToConvert {
|
|
|
|
dbProfile := storage.DB_Profile{
|
|
|
|
ID: profile.ID,
|
|
|
|
PersonID: p.ID,
|
|
|
|
Type: profileType,
|
|
|
|
Items: []storage.DB_Item{},
|
|
|
|
Gifts: []storage.DB_Gift{},
|
2023-11-05 01:58:00 +00:00
|
|
|
Quests: []storage.DB_Quest{},
|
2023-11-20 21:20:26 +00:00
|
|
|
Loadouts: []storage.DB_Loadout{},
|
2024-02-04 02:05:31 +00:00
|
|
|
Attributes: []storage.DB_Attribute{},
|
2023-11-05 01:58:00 +00:00
|
|
|
Revision: profile.Revision,
|
2023-10-31 22:40:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
profile.Items.RangeItems(func(id string, item *Item) bool {
|
|
|
|
dbProfile.Items = append(dbProfile.Items, *item.ToDatabase(p.ID))
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
profile.Gifts.RangeGifts(func(id string, gift *Gift) bool {
|
|
|
|
dbProfile.Gifts = append(dbProfile.Gifts, *gift.ToDatabase(p.ID))
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
profile.Quests.RangeQuests(func(id string, quest *Quest) bool {
|
|
|
|
dbProfile.Quests = append(dbProfile.Quests, *quest.ToDatabase(p.ID))
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2023-11-01 00:05:17 +00:00
|
|
|
profile.Attributes.RangeAttributes(func(key string, value *Attribute) bool {
|
|
|
|
dbProfile.Attributes = append(dbProfile.Attributes, *value.ToDatabase(p.ID))
|
2023-10-31 22:40:14 +00:00
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2023-11-20 21:20:26 +00:00
|
|
|
profile.Loadouts.RangeLoadouts(func(id string, loadout *Loadout) bool {
|
|
|
|
dbProfile.Loadouts = append(dbProfile.Loadouts, *loadout.ToDatabase(p.ID))
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2023-10-31 22:40:14 +00:00
|
|
|
dbPerson.Profiles = append(dbPerson.Profiles, dbProfile)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &dbPerson
|
2023-11-01 00:05:17 +00:00
|
|
|
}
|
|
|
|
|
2024-02-04 01:25:44 +00:00
|
|
|
func (p *Person) ToDatabaseShallow() *storage.DB_Person {
|
|
|
|
dbPerson := storage.DB_Person{
|
|
|
|
ID: p.ID,
|
|
|
|
DisplayName: p.DisplayName,
|
2024-02-09 21:51:26 +00:00
|
|
|
Permissions: int64(p.Permissions),
|
2024-02-10 01:55:56 +00:00
|
|
|
BanHistory: []storage.DB_BanStatus{},
|
2024-02-04 15:21:16 +00:00
|
|
|
RefundTickets: p.RefundTickets,
|
2024-02-04 01:25:44 +00:00
|
|
|
Profiles: []storage.DB_Profile{},
|
|
|
|
Stats: []storage.DB_SeasonStat{},
|
|
|
|
Discord: storage.DB_DiscordPerson{},
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.Discord != nil {
|
|
|
|
dbPerson.Discord = *p.Discord
|
|
|
|
}
|
|
|
|
|
2024-02-10 01:55:56 +00:00
|
|
|
p.BanHistory.Range(func(key string, ban *storage.DB_BanStatus) bool {
|
|
|
|
dbPerson.BanHistory = append(dbPerson.BanHistory, *ban)
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
2024-02-04 01:25:44 +00:00
|
|
|
return &dbPerson
|
|
|
|
}
|
|
|
|
|
2023-11-01 00:05:17 +00:00
|
|
|
func (p *Person) Snapshot() *PersonSnapshot {
|
2024-02-10 01:55:56 +00:00
|
|
|
snapshot := &PersonSnapshot{
|
2023-11-01 00:05:17 +00:00
|
|
|
ID: p.ID,
|
|
|
|
DisplayName: p.DisplayName,
|
2024-02-19 01:49:14 +00:00
|
|
|
RefundTickets: p.RefundTickets,
|
2024-02-09 21:51:26 +00:00
|
|
|
Permissions: int64(p.Permissions),
|
2023-11-01 00:05:17 +00:00
|
|
|
AthenaProfile: *p.AthenaProfile.Snapshot(),
|
2023-11-05 01:58:00 +00:00
|
|
|
CommonCoreProfile: *p.CommonCoreProfile.Snapshot(),
|
2023-11-06 22:41:52 +00:00
|
|
|
CommonPublicProfile: *p.CommonPublicProfile.Snapshot(),
|
|
|
|
Profile0Profile: *p.Profile0Profile.Snapshot(),
|
2023-12-03 20:16:40 +00:00
|
|
|
CollectionsProfile: *p.CollectionsProfile.Snapshot(),
|
2023-12-08 15:35:00 +00:00
|
|
|
CreativeProfile: *p.CreativeProfile.Snapshot(),
|
2024-02-10 01:55:56 +00:00
|
|
|
BanHistory: []storage.DB_BanStatus{},
|
2023-12-10 00:52:59 +00:00
|
|
|
Discord: *p.Discord,
|
2024-02-19 01:49:14 +00:00
|
|
|
Relationships: *p.Relationships.Snapshot(),
|
|
|
|
Parties: *p.Parties.Snapshot(),
|
|
|
|
Invites: *p.Invites.Snapshot(),
|
|
|
|
Intentions: *p.Intentions.Snapshot(),
|
2023-11-01 00:05:17 +00:00
|
|
|
}
|
2024-02-10 01:55:56 +00:00
|
|
|
|
|
|
|
p.BanHistory.Range(func(key string, ban *storage.DB_BanStatus) bool {
|
|
|
|
snapshot.BanHistory = append(snapshot.BanHistory, *ban)
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
return snapshot
|
2023-12-13 22:52:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Person) Delete() {
|
|
|
|
storage.Repo.DeletePerson(p.ID)
|
2024-02-10 00:33:10 +00:00
|
|
|
cache.DeletePerson(p.ID)
|
2024-02-04 15:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Person) SetPurchaseHistoryAttribute() {
|
|
|
|
purchases := []aid.JSON{}
|
|
|
|
|
|
|
|
p.AthenaProfile.Purchases.RangePurchases(func(key string, value *Purchase) bool {
|
|
|
|
purchases = append(purchases, value.GenerateFortnitePurchaseEntry())
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
|
|
|
|
purchaseAttribute := p.CommonCoreProfile.Attributes.GetAttributeByKey("mtx_purchase_history")
|
|
|
|
purchaseAttribute.ValueJSON = aid.JSONStringify(aid.JSON{
|
|
|
|
"refundsUsed": p.AthenaProfile.Purchases.CountRefunded(),
|
|
|
|
"refundCredits": p.RefundTickets,
|
|
|
|
"purchases": purchases,
|
|
|
|
})
|
|
|
|
purchaseAttribute.Save()
|
2023-12-13 22:52:16 +00:00
|
|
|
}
|