From 7bcaca66aa5ba7aa13544a2b0d60dddbdf96b9fd Mon Sep 17 00:00:00 2001 From: Vladimir Hodakov Date: Tue, 30 Jan 2018 18:41:23 +0400 Subject: [PATCH] Fix for non-finding weapons --- lib/datacache/weapons.go | 3 ++- lib/users/parsers.go | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/datacache/weapons.go b/lib/datacache/weapons.go index 7c7214d..4b03b66 100644 --- a/lib/datacache/weapons.go +++ b/lib/datacache/weapons.go @@ -7,6 +7,7 @@ import ( "errors" "git.wtfteam.pro/fat0troll/i2_bot/lib/dbmapping" "strconv" + "strings" ) func (dc *DataCache) initWeapons() { @@ -37,7 +38,7 @@ func (dc *DataCache) loadWeapons() { func (dc *DataCache) GetWeaponTypeByName(name string) (*dbmapping.Weapon, error) { dc.weaponsMutex.Lock() for i := range dc.weapons { - if dc.weapons[i].Name == name { + if strings.HasPrefix(dc.weapons[i].Name, name) { dc.weaponsMutex.Unlock() return dc.weapons[i], nil } diff --git a/lib/users/parsers.go b/lib/users/parsers.go index 1205b73..3535c0f 100644 --- a/lib/users/parsers.go +++ b/lib/users/parsers.go @@ -247,7 +247,11 @@ func (u *Users) ParseProfile(update *tgbotapi.Update, playerRaw *dbmapping.Playe profileRaw.Exp = expInt profileRaw.EggExp = eggexpInt profileRaw.Power = powerInt - profileRaw.WeaponID = weaponRaw.ID + if weaponRaw != nil { + profileRaw.WeaponID = weaponRaw.ID + } else { + profileRaw.WeaponID = 0 + } profileRaw.Crystalls = crystallsInt profileRaw.CreatedAt = time.Now().UTC()