2017-10-06 02:56:06 +04:00
|
|
|
|
// i2_bot – Instinct PokememBro Bot
|
|
|
|
|
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
|
|
|
|
|
|
2017-11-21 06:06:32 +04:00
|
|
|
|
package pokedexer
|
2017-10-06 02:56:06 +04:00
|
|
|
|
|
|
|
|
|
import (
|
2017-10-18 07:03:34 +04:00
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
2018-05-02 07:25:39 +04:00
|
|
|
|
|
|
|
|
|
"github.com/go-telegram-bot-api/telegram-bot-api"
|
2018-05-19 12:14:25 +04:00
|
|
|
|
"github.com/fat0troll/i2_bot/lib/dbmapping"
|
2017-10-06 02:56:06 +04:00
|
|
|
|
)
|
|
|
|
|
|
2017-10-18 09:39:50 +04:00
|
|
|
|
// ParsePokememe parses pokememe, forwarded from PokememeBroBot, to database
|
2017-11-21 06:06:32 +04:00
|
|
|
|
func (p *Pokedexer) ParsePokememe(update *tgbotapi.Update, playerRaw *dbmapping.Player) string {
|
2018-05-02 00:47:55 +04:00
|
|
|
|
c.Log.Info("Starting pokememe parsing...")
|
2018-01-29 23:50:25 +04:00
|
|
|
|
pokememeStringsArray := strings.Split(update.Message.Text, "\n")
|
2017-10-18 09:39:50 +04:00
|
|
|
|
pokememeRunesArray := make([][]rune, 0)
|
|
|
|
|
for i := range pokememeStringsArray {
|
|
|
|
|
pokememeRunesArray = append(pokememeRunesArray, []rune(pokememeStringsArray[i]))
|
2017-10-18 07:03:34 +04:00
|
|
|
|
}
|
2017-10-06 02:56:06 +04:00
|
|
|
|
|
2018-01-29 23:50:25 +04:00
|
|
|
|
pokememeData := make(map[string]string)
|
2017-10-07 02:23:25 +04:00
|
|
|
|
|
2018-01-29 23:50:25 +04:00
|
|
|
|
for i := range pokememeStringsArray {
|
2018-05-02 00:47:55 +04:00
|
|
|
|
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))
|
2018-01-29 23:50:25 +04:00
|
|
|
|
}
|
2018-05-02 00:47:55 +04:00
|
|
|
|
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))
|
2018-01-29 23:50:25 +04:00
|
|
|
|
}
|
2018-05-02 00:47:55 +04:00
|
|
|
|
pokememeData["locations"] = "\\[" + strings.Join(locationIDs, ", ") + "]"
|
|
|
|
|
} else if strings.HasPrefix(infoString, "Buyable ") {
|
2018-01-29 23:50:25 +04:00
|
|
|
|
pokememeData["purchaseable"] = "false"
|
2018-05-02 00:47:55 +04:00
|
|
|
|
if strings.HasSuffix(infoString, "Yes") {
|
2018-01-29 23:50:25 +04:00
|
|
|
|
pokememeData["purchaseable"] = "true"
|
|
|
|
|
}
|
2018-05-02 00:47:55 +04:00
|
|
|
|
} else {
|
|
|
|
|
pokememeData[strings.Split(infoString, " ")[0]] = strings.Join(strings.Split(infoString, " ")[1:], " ")
|
2017-10-18 07:03:34 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-07 02:23:25 +04:00
|
|
|
|
|
2018-01-29 23:50:25 +04:00
|
|
|
|
c.Log.Debugln("Pokememe data: ", pokememeData)
|
|
|
|
|
|
2018-05-02 00:47:55 +04:00
|
|
|
|
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-07 02:23:25 +04:00
|
|
|
|
|
2017-10-18 07:03:34 +04:00
|
|
|
|
return "ok"
|
2017-10-06 02:56:06 +04:00
|
|
|
|
}
|