Browse Source

Add support for English league name in /me

master
Vladimir Hodakov 1 year ago
parent
commit
3723a1991f
Signed by: fat0troll <vladimir@hodakov.me> GPG Key ID: 673980B6882F82C6
7 changed files with 30 additions and 14 deletions
  1. +4
    -1
      data/leagues.yml
  2. +2
    -1
      lib/datacache/datacacheinterface/datacacheinterface.go
  3. +12
    -1
      lib/datacache/leagues.go
  4. +4
    -3
      lib/datamapping/leagues.go
  5. +2
    -2
      lib/forwarder/forwarder.go
  6. +2
    -2
      lib/users/parsers.go
  7. +4
    -4
      static/ab0x.go

+ 4
- 1
data/leagues.yml View File

@@ -1,9 +1,12 @@
- id: 1
symbol: 🈸
name: "ИНСТИНКТ"
name_english: "INSTINCT"
- id: 2
symbol: 🈳
name: "МИСТИКА"
name_english: "MYSTIC"
- id: 3
symbol: 🈵
name: "ОТВАГА"
name: "ОТВАГА"
name_english: "VALOR"

+ 2
- 1
lib/datacache/datacacheinterface/datacacheinterface.go View File

@@ -4,9 +4,9 @@
package datacacheinterface

import (
"github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/fat0troll/i2_bot/lib/datamapping"
"github.com/fat0troll/i2_bot/lib/dbmapping"
"github.com/go-telegram-bot-api/telegram-bot-api"
)

// DataCacheInterface implements DataCache for importing via appcontext.
@@ -52,6 +52,7 @@ type DataCacheInterface interface {
FindElementIDBySymbol(symbol string) (int, error)

GetLeagueByID(leagueID int) (*datamapping.League, error)
GetLeagueByEnglishName(name string) (*datamapping.League, error)
GetLeagueByName(name string) (*datamapping.League, error)
GetLeagueBySymbol(symbol string) (*datamapping.League, error)



+ 12
- 1
lib/datacache/leagues.go View File

@@ -8,9 +8,9 @@ import (
"strconv"
"strings"

"gopkg.in/yaml.v2"
"github.com/fat0troll/i2_bot/lib/datamapping"
"github.com/fat0troll/i2_bot/static"
"gopkg.in/yaml.v2"
)

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)
}

// 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
func (dc *DataCache) GetLeagueBySymbol(symbol string) (*datamapping.League, error) {
for i := range dc.leagues {


+ 4
- 3
lib/datamapping/leagues.go View File

@@ -5,7 +5,8 @@ package datamapping

// League is a struct, which represents league data
type League struct {
ID int `yaml:"id"`
Symbol string `yaml:"symbol"`
Name string `yaml:"name"`
ID int `yaml:"id"`
Symbol string `yaml:"symbol"`
Name string `yaml:"name"`
NameEnglish string `yaml:"name_english"`
}

+ 2
- 2
lib/forwarder/forwarder.go View File

@@ -6,8 +6,8 @@ package forwarder
import (
"regexp"

"github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/fat0troll/i2_bot/lib/dbmapping"
"github.com/go-telegram-bot-api/telegram-bot-api"
)

// ProcessForward process forwards for single-user chats
@@ -16,7 +16,7 @@ func (f *Forwarder) ProcessForward(update *tgbotapi.Update, playerRaw *dbmapping

// Forwards
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 {
case pokememeMsg.MatchString(text):


+ 2
- 2
lib/users/parsers.go View File

@@ -9,8 +9,8 @@ import (
"strings"
"time"

"github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/fat0troll/i2_bot/lib/dbmapping"
"github.com/go-telegram-bot-api/telegram-bot-api"
)

// Internal functions
@@ -76,7 +76,7 @@ func (u *Users) ParseProfile(update *tgbotapi.Update, playerRaw *dbmapping.Playe
fmt.Println(rawProfileData)

nickname := rawProfileData["Name"]
league, err := c.DataCache.GetLeagueByName(rawProfileData["Team"])
league, err := c.DataCache.GetLeagueByEnglishName(rawProfileData["Team"])
if err != nil {
c.Log.Error(err.Error())
u.profileAddFailureMessage(update)


+ 4
- 4
static/ab0x.go
File diff suppressed because it is too large
View File