Archived
1
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
i2_bot/lib/pokedexer/parsers.go

75 lines
2.8 KiB
Go
Raw Normal View History

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package pokedexer
import (
"github.com/go-telegram-bot-api/telegram-bot-api"
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
2017-10-18 07:03:34 +04:00
"strconv"
"strings"
)
// ParsePokememe parses pokememe, forwarded from PokememeBroBot, to database
func (p *Pokedexer) ParsePokememe(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
c.Log.Info("Starting pokememe parsing...")
pokememeStringsArray := strings.Split(update.Message.Text, "\n")
pokememeRunesArray := make([][]rune, 0)
for i := range pokememeStringsArray {
pokememeRunesArray = append(pokememeRunesArray, []rune(pokememeStringsArray[i]))
2017-10-18 07:03:34 +04:00
}
pokememeData := make(map[string]string)
for i := range pokememeStringsArray {
infoString := pokememeStringsArray[i]
c.Log.Debug("Processing string: " + infoString)
if strings.HasPrefix(infoString, "Elements ") {
infoString = strings.Replace(infoString, "Elements ", "", -1)
elements := strings.Split(infoString, " ")
elementsIDs := make([]string, 0)
for ii := range elements {
element, _ := c.DataCache.FindElementIDBySymbol(elements[ii])
elementsIDs = append(elementsIDs, strconv.Itoa(element))
}
pokememeData["elements"] = "\\[" + strings.Join(elementsIDs, ", ") + "]"
} else if strings.HasPrefix(infoString, "Place ") {
infoString = strings.Replace(infoString, "Place ", "", -1)
places := strings.Split(infoString, ",")
locationIDs := make([]string, 0)
for ii := range places {
locationID, _ := c.DataCache.FindLocationIDByName(places[ii])
locationIDs = append(locationIDs, strconv.Itoa(locationID))
}
pokememeData["locations"] = "\\[" + strings.Join(locationIDs, ", ") + "]"
} else if strings.HasPrefix(infoString, "Buyable ") {
pokememeData["purchaseable"] = "false"
if strings.HasSuffix(infoString, "Yes") {
pokememeData["purchaseable"] = "true"
}
} else {
pokememeData[strings.Split(infoString, " ")[0]] = strings.Join(strings.Split(infoString, " ")[1:], " ")
2017-10-18 07:03:34 +04:00
}
}
c.Log.Debugln("Pokememe data: ", pokememeData)
message := "- id: " + pokememeData["Dex"]
message += "\n grade: " + pokememeData["Grade"]
message += "\n name: \"" + pokememeData["Name"] + "\""
message += "\n description: \"" + pokememeData["Description"] + "\""
message += "\n attack: " + pokememeData["Attack"]
message += "\n defence: " + pokememeData["Def"]
message += "\n health: " + pokememeData["HP"]
message += "\n mana: " + pokememeData["MP"]
message += "\n cost: " + pokememeData["Cost"]
message += "\n purchaseable: " + pokememeData["purchaseable"]
message += "\n image: \"" + pokememeData["Image"] + "\""
message += "\n elements: " + pokememeData["elements"]
message += "\n locations: " + pokememeData["locations"]
c.Sender.SendMarkdownAnswer(update, message)
2017-10-18 07:03:34 +04:00
return "ok"
}