Add support for English league name in /me
This commit is contained in:
parent
98bf2c393b
commit
3723a1991f
@ -1,9 +1,12 @@
|
|||||||
- id: 1
|
- id: 1
|
||||||
symbol: 🈸
|
symbol: 🈸
|
||||||
name: "ИНСТИНКТ"
|
name: "ИНСТИНКТ"
|
||||||
|
name_english: "INSTINCT"
|
||||||
- id: 2
|
- id: 2
|
||||||
symbol: 🈳
|
symbol: 🈳
|
||||||
name: "МИСТИКА"
|
name: "МИСТИКА"
|
||||||
|
name_english: "MYSTIC"
|
||||||
- id: 3
|
- id: 3
|
||||||
symbol: 🈵
|
symbol: 🈵
|
||||||
name: "ОТВАГА"
|
name: "ОТВАГА"
|
||||||
|
name_english: "VALOR"
|
@ -4,9 +4,9 @@
|
|||||||
package datacacheinterface
|
package datacacheinterface
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
"github.com/fat0troll/i2_bot/lib/datamapping"
|
"github.com/fat0troll/i2_bot/lib/datamapping"
|
||||||
"github.com/fat0troll/i2_bot/lib/dbmapping"
|
"github.com/fat0troll/i2_bot/lib/dbmapping"
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DataCacheInterface implements DataCache for importing via appcontext.
|
// DataCacheInterface implements DataCache for importing via appcontext.
|
||||||
@ -52,6 +52,7 @@ type DataCacheInterface interface {
|
|||||||
FindElementIDBySymbol(symbol string) (int, error)
|
FindElementIDBySymbol(symbol string) (int, error)
|
||||||
|
|
||||||
GetLeagueByID(leagueID int) (*datamapping.League, error)
|
GetLeagueByID(leagueID int) (*datamapping.League, error)
|
||||||
|
GetLeagueByEnglishName(name string) (*datamapping.League, error)
|
||||||
GetLeagueByName(name string) (*datamapping.League, error)
|
GetLeagueByName(name string) (*datamapping.League, error)
|
||||||
GetLeagueBySymbol(symbol string) (*datamapping.League, error)
|
GetLeagueBySymbol(symbol string) (*datamapping.League, error)
|
||||||
|
|
||||||
|
@ -8,9 +8,9 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
"github.com/fat0troll/i2_bot/lib/datamapping"
|
"github.com/fat0troll/i2_bot/lib/datamapping"
|
||||||
"github.com/fat0troll/i2_bot/static"
|
"github.com/fat0troll/i2_bot/static"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (dc *DataCache) initLeagues() {
|
func (dc *DataCache) initLeagues() {
|
||||||
@ -68,6 +68,17 @@ func (dc *DataCache) GetLeagueByName(name string) (*datamapping.League, error) {
|
|||||||
return nil, errors.New("There is no league with name = " + name)
|
return nil, errors.New("There is no league with name = " + name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetLeagueByEnglishName returns league from datacache by english name
|
||||||
|
func (dc *DataCache) GetLeagueByEnglishName(name string) (*datamapping.League, error) {
|
||||||
|
for i := range dc.leagues {
|
||||||
|
if strings.Contains(dc.leagues[i].NameEnglish, name) {
|
||||||
|
return dc.leagues[i], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("There is no league with name = " + name)
|
||||||
|
}
|
||||||
|
|
||||||
// GetLeagueBySymbol returns league from datacache by emoji
|
// GetLeagueBySymbol returns league from datacache by emoji
|
||||||
func (dc *DataCache) GetLeagueBySymbol(symbol string) (*datamapping.League, error) {
|
func (dc *DataCache) GetLeagueBySymbol(symbol string) (*datamapping.League, error) {
|
||||||
for i := range dc.leagues {
|
for i := range dc.leagues {
|
||||||
|
@ -8,4 +8,5 @@ type League struct {
|
|||||||
ID int `yaml:"id"`
|
ID int `yaml:"id"`
|
||||||
Symbol string `yaml:"symbol"`
|
Symbol string `yaml:"symbol"`
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
|
NameEnglish string `yaml:"name_english"`
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ package forwarder
|
|||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
"github.com/fat0troll/i2_bot/lib/dbmapping"
|
"github.com/fat0troll/i2_bot/lib/dbmapping"
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProcessForward process forwards for single-user chats
|
// ProcessForward process forwards for single-user chats
|
||||||
@ -16,7 +16,7 @@ func (f *Forwarder) ProcessForward(update *tgbotapi.Update, playerRaw *dbmapping
|
|||||||
|
|
||||||
// Forwards
|
// Forwards
|
||||||
var pokememeMsg = regexp.MustCompile(`Dex(.+)\nGrade(.+)\nName(.+)`)
|
var pokememeMsg = regexp.MustCompile(`Dex(.+)\nGrade(.+)\nName(.+)`)
|
||||||
var profileMsg = regexp.MustCompile(`id(\s)(\d+)\n(Team)(\s)([А-Я]+)\nName(\s)(.*)\nLvl(\s)(\d+)`)
|
var profileMsg = regexp.MustCompile(`id(\s)(\d+)\n(Team)(\s)([A-Z]+)\nName(\s)(.*)\nLvl(\s)(\d+)`)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case pokememeMsg.MatchString(text):
|
case pokememeMsg.MatchString(text):
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
|
||||||
"github.com/fat0troll/i2_bot/lib/dbmapping"
|
"github.com/fat0troll/i2_bot/lib/dbmapping"
|
||||||
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Internal functions
|
// Internal functions
|
||||||
@ -76,7 +76,7 @@ func (u *Users) ParseProfile(update *tgbotapi.Update, playerRaw *dbmapping.Playe
|
|||||||
fmt.Println(rawProfileData)
|
fmt.Println(rawProfileData)
|
||||||
|
|
||||||
nickname := rawProfileData["Name"]
|
nickname := rawProfileData["Name"]
|
||||||
league, err := c.DataCache.GetLeagueByName(rawProfileData["Team"])
|
league, err := c.DataCache.GetLeagueByEnglishName(rawProfileData["Team"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log.Error(err.Error())
|
c.Log.Error(err.Error())
|
||||||
u.profileAddFailureMessage(update)
|
u.profileAddFailureMessage(update)
|
||||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user