Archived
minor improvements, new d3 module (no output yet)
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
/.idea
|
||||||
|
/WGoSlackBot.iml
|
||||||
# ---> Go
|
# ---> Go
|
||||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||||
*.o
|
*.o
|
||||||
|
|||||||
+655
@@ -0,0 +1,655 @@
|
|||||||
|
// d3.go
|
||||||
|
package modules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dev.ixab.de/WGSWATBP/WGoSlackBot/util"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"github.com/leekchan/accounting"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
d3apikey string
|
||||||
|
d3botname string
|
||||||
|
d3boticon string
|
||||||
|
bnetd3apiurl string = "https://eu.api.battle.net/d3/"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
MsgHandlers["d3"] = d3HandleMessage
|
||||||
|
log.Println("Initializing d3 module")
|
||||||
|
go setd3Config()
|
||||||
|
}
|
||||||
|
func setd3Config() {
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
d3apikey = ModParams["d3apikey"]
|
||||||
|
d3botname = ModParams["d3botname"]
|
||||||
|
d3boticon = ModParams["d3boticon"]
|
||||||
|
}
|
||||||
|
func d3HandleMessage(payload *WebhookPayload) {
|
||||||
|
if payload.Command == "/d3" {
|
||||||
|
reply := handleD3Request(payload, true)
|
||||||
|
if reply != "" {
|
||||||
|
//SayCh <- GeneratePayload(payload.ChannelName, d3boticon, reply, d3botname)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if payload.TriggerWord == "!d3" {
|
||||||
|
reply := handleD3Request(payload, false)
|
||||||
|
if reply != "" {
|
||||||
|
//SayCh <- GeneratePayload(payload.ChannelName, d3boticon, reply, d3botname)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func handleD3Request(payload *WebhookPayload, isCommand bool) string {
|
||||||
|
var tokMod int
|
||||||
|
if isCommand {
|
||||||
|
tokMod = 0
|
||||||
|
} else {
|
||||||
|
tokMod = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
tok := strings.Split(payload.Text, " ")
|
||||||
|
var result string
|
||||||
|
if len(tok) < 2+tokMod {
|
||||||
|
if tok[0+tokMod] == "" {
|
||||||
|
SayCh <- GeneratePayload("@"+payload.UserName, d3boticon, "Es wurde kein Battletag angegeben.", d3botname)
|
||||||
|
} else {
|
||||||
|
battletag, err := checkBattleTag(tok[0+tokMod])
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
SayCh <- GeneratePayload("@"+payload.UserName, d3boticon, "Battletag "+tok[0+tokMod]+"fehlerhaft oder nicht gefunden.", d3botname)
|
||||||
|
}
|
||||||
|
profile := getD3Profile(battletag)
|
||||||
|
// ab hier output generieren
|
||||||
|
result = "Profil: " + util.NumberToString(profile.ParagonLevel, '.')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(tok) >= 2+tokMod {
|
||||||
|
battletag, err := checkBattleTag(tok[0+tokMod])
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
SayCh <- GeneratePayload("@"+payload.UserName, d3boticon, "Battletag "+tok[0+tokMod]+"fehlerhaft oder nicht gefunden.", d3botname)
|
||||||
|
} else {
|
||||||
|
profile := getD3Profile(battletag)
|
||||||
|
hit := false
|
||||||
|
for _, currenthero := range profile.Heroes {
|
||||||
|
if strings.ToLower(currenthero.Name) == strings.ToLower(tok[1+tokMod]) {
|
||||||
|
hero := getD3Hero(battletag, currenthero.ID)
|
||||||
|
hit = true
|
||||||
|
// ab hier output generieren
|
||||||
|
result = "Hero: " + accounting.FormatNumberFloat64(hero.Stats.Damage, 3, ".", ",")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !hit {
|
||||||
|
SayCh <- GeneratePayload("@"+payload.UserName, d3boticon, "Es konnte kein Charakter mit dem Namen *"+tok[1+tokMod]+"* unter dem Battletag *"+tok[0+tokMod]+"* gefunden werden.", d3botname)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
func checkBattleTag(battletag string) (tag string, e error) {
|
||||||
|
if strings.ContainsRune(battletag, '-') {
|
||||||
|
return battletag, nil
|
||||||
|
}
|
||||||
|
if strings.ContainsRune(battletag, '#') {
|
||||||
|
return strings.Replace(battletag, "#", "-", 1), nil
|
||||||
|
}
|
||||||
|
return "", errors.New("invalid battletag")
|
||||||
|
}
|
||||||
|
func getD3Profile(battletag string) d3Profile {
|
||||||
|
requesturl := bnetd3apiurl + "profile/" + battletag + "/?locale=en_GB&apikey=" + d3apikey
|
||||||
|
var result d3Profile
|
||||||
|
resp, err := http.Get(requesturl)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
} else {
|
||||||
|
reader, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
} else {
|
||||||
|
defer resp.Body.Close()
|
||||||
|
json.Unmarshal(reader, &result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
func getD3Hero(battletag string, heroid int) d3Hero {
|
||||||
|
heroidstring := strconv.Itoa(heroid)
|
||||||
|
requesturl := bnetd3apiurl + "profile/" + battletag + "/hero/" + heroidstring + "?locale=en_GB&apikey=" + d3apikey
|
||||||
|
var result d3Hero
|
||||||
|
resp, err := http.Get(requesturl)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
} else {
|
||||||
|
reader, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
} else {
|
||||||
|
defer resp.Body.Close()
|
||||||
|
json.Unmarshal(reader, &result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
type d3Profile struct {
|
||||||
|
BattleTag string `json:"battleTag"`
|
||||||
|
Blacksmith struct {
|
||||||
|
Level int `json:"level"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
StepCurrent int `json:"stepCurrent"`
|
||||||
|
StepMax int `json:"stepMax"`
|
||||||
|
} `json:"blacksmith"`
|
||||||
|
BlacksmithHardcore struct {
|
||||||
|
Level int `json:"level"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
StepCurrent int `json:"stepCurrent"`
|
||||||
|
StepMax int `json:"stepMax"`
|
||||||
|
} `json:"blacksmithHardcore"`
|
||||||
|
BlacksmithSeason struct {
|
||||||
|
Level int `json:"level"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
StepCurrent int `json:"stepCurrent"`
|
||||||
|
StepMax int `json:"stepMax"`
|
||||||
|
} `json:"blacksmithSeason"`
|
||||||
|
BlacksmithSeasonHardcore struct {
|
||||||
|
Level int `json:"level"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
StepCurrent int `json:"stepCurrent"`
|
||||||
|
StepMax int `json:"stepMax"`
|
||||||
|
} `json:"blacksmithSeasonHardcore"`
|
||||||
|
FallenHeroes []interface{} `json:"fallenHeroes"`
|
||||||
|
GuildName string `json:"guildName"`
|
||||||
|
Heroes []struct {
|
||||||
|
Class string `json:"class"`
|
||||||
|
Dead bool `json:"dead"`
|
||||||
|
Gender int `json:"gender"`
|
||||||
|
Hardcore bool `json:"hardcore"`
|
||||||
|
ID int `json:"id"`
|
||||||
|
Kills struct {
|
||||||
|
Elites int `json:"elites"`
|
||||||
|
} `json:"kills"`
|
||||||
|
Last_updated int `json:"last-updated"`
|
||||||
|
Level int `json:"level"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
ParagonLevel int `json:"paragonLevel"`
|
||||||
|
Seasonal bool `json:"seasonal"`
|
||||||
|
} `json:"heroes"`
|
||||||
|
HighestHardcoreLevel int `json:"highestHardcoreLevel"`
|
||||||
|
Jeweler struct {
|
||||||
|
Level int `json:"level"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
StepCurrent int `json:"stepCurrent"`
|
||||||
|
StepMax int `json:"stepMax"`
|
||||||
|
} `json:"jeweler"`
|
||||||
|
JewelerHardcore struct {
|
||||||
|
Level int `json:"level"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
StepCurrent int `json:"stepCurrent"`
|
||||||
|
StepMax int `json:"stepMax"`
|
||||||
|
} `json:"jewelerHardcore"`
|
||||||
|
JewelerSeason struct {
|
||||||
|
Level int `json:"level"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
StepCurrent int `json:"stepCurrent"`
|
||||||
|
StepMax int `json:"stepMax"`
|
||||||
|
} `json:"jewelerSeason"`
|
||||||
|
JewelerSeasonHardcore struct {
|
||||||
|
Level int `json:"level"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
StepCurrent int `json:"stepCurrent"`
|
||||||
|
StepMax int `json:"stepMax"`
|
||||||
|
} `json:"jewelerSeasonHardcore"`
|
||||||
|
Kills struct {
|
||||||
|
Elites int `json:"elites"`
|
||||||
|
HardcoreMonsters int `json:"hardcoreMonsters"`
|
||||||
|
Monsters int `json:"monsters"`
|
||||||
|
} `json:"kills"`
|
||||||
|
LastHeroPlayed int `json:"lastHeroPlayed"`
|
||||||
|
LastUpdated int `json:"lastUpdated"`
|
||||||
|
Mystic struct {
|
||||||
|
Level int `json:"level"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
StepCurrent int `json:"stepCurrent"`
|
||||||
|
StepMax int `json:"stepMax"`
|
||||||
|
} `json:"mystic"`
|
||||||
|
MysticHardcore struct {
|
||||||
|
Level int `json:"level"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
StepCurrent int `json:"stepCurrent"`
|
||||||
|
StepMax int `json:"stepMax"`
|
||||||
|
} `json:"mysticHardcore"`
|
||||||
|
MysticSeason struct {
|
||||||
|
Level int `json:"level"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
StepCurrent int `json:"stepCurrent"`
|
||||||
|
StepMax int `json:"stepMax"`
|
||||||
|
} `json:"mysticSeason"`
|
||||||
|
MysticSeasonHardcore struct {
|
||||||
|
Level int `json:"level"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
StepCurrent int `json:"stepCurrent"`
|
||||||
|
StepMax int `json:"stepMax"`
|
||||||
|
} `json:"mysticSeasonHardcore"`
|
||||||
|
ParagonLevel int `json:"paragonLevel"`
|
||||||
|
ParagonLevelHardcore int `json:"paragonLevelHardcore"`
|
||||||
|
ParagonLevelSeason int `json:"paragonLevelSeason"`
|
||||||
|
ParagonLevelSeasonHardcore int `json:"paragonLevelSeasonHardcore"`
|
||||||
|
Progression struct {
|
||||||
|
Act1 bool `json:"act1"`
|
||||||
|
Act2 bool `json:"act2"`
|
||||||
|
Act3 bool `json:"act3"`
|
||||||
|
Act4 bool `json:"act4"`
|
||||||
|
Act5 bool `json:"act5"`
|
||||||
|
} `json:"progression"`
|
||||||
|
SeasonalProfiles struct {
|
||||||
|
Season0 struct {
|
||||||
|
HighestHardcoreLevel int `json:"highestHardcoreLevel"`
|
||||||
|
Kills struct {
|
||||||
|
Elites int `json:"elites"`
|
||||||
|
HardcoreMonsters int `json:"hardcoreMonsters"`
|
||||||
|
Monsters int `json:"monsters"`
|
||||||
|
} `json:"kills"`
|
||||||
|
ParagonLevel int `json:"paragonLevel"`
|
||||||
|
ParagonLevelHardcore int `json:"paragonLevelHardcore"`
|
||||||
|
Progression struct {
|
||||||
|
Act1 bool `json:"act1"`
|
||||||
|
Act2 bool `json:"act2"`
|
||||||
|
Act3 bool `json:"act3"`
|
||||||
|
Act4 bool `json:"act4"`
|
||||||
|
Act5 bool `json:"act5"`
|
||||||
|
} `json:"progression"`
|
||||||
|
SeasonID int `json:"seasonId"`
|
||||||
|
TimePlayed struct {
|
||||||
|
Barbarian float64 `json:"barbarian"`
|
||||||
|
Crusader float64 `json:"crusader"`
|
||||||
|
Demon_hunter float64 `json:"demon-hunter"`
|
||||||
|
Monk float64 `json:"monk"`
|
||||||
|
Witch_doctor int `json:"witch-doctor"`
|
||||||
|
Wizard float64 `json:"wizard"`
|
||||||
|
} `json:"timePlayed"`
|
||||||
|
} `json:"season0"`
|
||||||
|
Season1 struct {
|
||||||
|
HighestHardcoreLevel int `json:"highestHardcoreLevel"`
|
||||||
|
Kills struct {
|
||||||
|
Elites int `json:"elites"`
|
||||||
|
HardcoreMonsters int `json:"hardcoreMonsters"`
|
||||||
|
Monsters int `json:"monsters"`
|
||||||
|
} `json:"kills"`
|
||||||
|
ParagonLevel int `json:"paragonLevel"`
|
||||||
|
ParagonLevelHardcore int `json:"paragonLevelHardcore"`
|
||||||
|
Progression struct {
|
||||||
|
Act1 bool `json:"act1"`
|
||||||
|
Act2 bool `json:"act2"`
|
||||||
|
Act3 bool `json:"act3"`
|
||||||
|
Act4 bool `json:"act4"`
|
||||||
|
Act5 bool `json:"act5"`
|
||||||
|
} `json:"progression"`
|
||||||
|
SeasonID int `json:"seasonId"`
|
||||||
|
TimePlayed struct {
|
||||||
|
Barbarian int `json:"barbarian"`
|
||||||
|
Crusader int `json:"crusader"`
|
||||||
|
Demon_hunter int `json:"demon-hunter"`
|
||||||
|
Monk int `json:"monk"`
|
||||||
|
Witch_doctor int `json:"witch-doctor"`
|
||||||
|
Wizard int `json:"wizard"`
|
||||||
|
} `json:"timePlayed"`
|
||||||
|
} `json:"season1"`
|
||||||
|
Season2 struct {
|
||||||
|
HighestHardcoreLevel int `json:"highestHardcoreLevel"`
|
||||||
|
Kills struct {
|
||||||
|
Elites int `json:"elites"`
|
||||||
|
HardcoreMonsters int `json:"hardcoreMonsters"`
|
||||||
|
Monsters int `json:"monsters"`
|
||||||
|
} `json:"kills"`
|
||||||
|
ParagonLevel int `json:"paragonLevel"`
|
||||||
|
ParagonLevelHardcore int `json:"paragonLevelHardcore"`
|
||||||
|
Progression struct {
|
||||||
|
Act1 bool `json:"act1"`
|
||||||
|
Act2 bool `json:"act2"`
|
||||||
|
Act3 bool `json:"act3"`
|
||||||
|
Act4 bool `json:"act4"`
|
||||||
|
Act5 bool `json:"act5"`
|
||||||
|
} `json:"progression"`
|
||||||
|
SeasonID int `json:"seasonId"`
|
||||||
|
TimePlayed struct {
|
||||||
|
Barbarian int `json:"barbarian"`
|
||||||
|
Crusader int `json:"crusader"`
|
||||||
|
Demon_hunter int `json:"demon-hunter"`
|
||||||
|
Monk int `json:"monk"`
|
||||||
|
Witch_doctor int `json:"witch-doctor"`
|
||||||
|
Wizard int `json:"wizard"`
|
||||||
|
} `json:"timePlayed"`
|
||||||
|
} `json:"season2"`
|
||||||
|
Season3 struct {
|
||||||
|
HighestHardcoreLevel int `json:"highestHardcoreLevel"`
|
||||||
|
Kills struct {
|
||||||
|
Elites int `json:"elites"`
|
||||||
|
HardcoreMonsters int `json:"hardcoreMonsters"`
|
||||||
|
Monsters int `json:"monsters"`
|
||||||
|
} `json:"kills"`
|
||||||
|
ParagonLevel int `json:"paragonLevel"`
|
||||||
|
ParagonLevelHardcore int `json:"paragonLevelHardcore"`
|
||||||
|
Progression struct {
|
||||||
|
Act1 bool `json:"act1"`
|
||||||
|
Act2 bool `json:"act2"`
|
||||||
|
Act3 bool `json:"act3"`
|
||||||
|
Act4 bool `json:"act4"`
|
||||||
|
Act5 bool `json:"act5"`
|
||||||
|
} `json:"progression"`
|
||||||
|
SeasonID int `json:"seasonId"`
|
||||||
|
TimePlayed struct {
|
||||||
|
Barbarian float64 `json:"barbarian"`
|
||||||
|
Crusader int `json:"crusader"`
|
||||||
|
Demon_hunter int `json:"demon-hunter"`
|
||||||
|
Monk int `json:"monk"`
|
||||||
|
Witch_doctor int `json:"witch-doctor"`
|
||||||
|
Wizard int `json:"wizard"`
|
||||||
|
} `json:"timePlayed"`
|
||||||
|
} `json:"season3"`
|
||||||
|
Season4 struct {
|
||||||
|
HighestHardcoreLevel int `json:"highestHardcoreLevel"`
|
||||||
|
Kills struct {
|
||||||
|
Elites int `json:"elites"`
|
||||||
|
HardcoreMonsters int `json:"hardcoreMonsters"`
|
||||||
|
Monsters int `json:"monsters"`
|
||||||
|
} `json:"kills"`
|
||||||
|
ParagonLevel int `json:"paragonLevel"`
|
||||||
|
ParagonLevelHardcore int `json:"paragonLevelHardcore"`
|
||||||
|
Progression struct {
|
||||||
|
Act1 bool `json:"act1"`
|
||||||
|
Act2 bool `json:"act2"`
|
||||||
|
Act3 bool `json:"act3"`
|
||||||
|
Act4 bool `json:"act4"`
|
||||||
|
Act5 bool `json:"act5"`
|
||||||
|
} `json:"progression"`
|
||||||
|
SeasonID int `json:"seasonId"`
|
||||||
|
TimePlayed struct {
|
||||||
|
Barbarian float64 `json:"barbarian"`
|
||||||
|
Crusader int `json:"crusader"`
|
||||||
|
Demon_hunter int `json:"demon-hunter"`
|
||||||
|
Monk int `json:"monk"`
|
||||||
|
Witch_doctor int `json:"witch-doctor"`
|
||||||
|
Wizard int `json:"wizard"`
|
||||||
|
} `json:"timePlayed"`
|
||||||
|
} `json:"season4"`
|
||||||
|
Season5 struct {
|
||||||
|
HighestHardcoreLevel int `json:"highestHardcoreLevel"`
|
||||||
|
Kills struct {
|
||||||
|
Elites int `json:"elites"`
|
||||||
|
HardcoreMonsters int `json:"hardcoreMonsters"`
|
||||||
|
Monsters int `json:"monsters"`
|
||||||
|
} `json:"kills"`
|
||||||
|
ParagonLevel int `json:"paragonLevel"`
|
||||||
|
ParagonLevelHardcore int `json:"paragonLevelHardcore"`
|
||||||
|
Progression struct {
|
||||||
|
Act1 bool `json:"act1"`
|
||||||
|
Act2 bool `json:"act2"`
|
||||||
|
Act3 bool `json:"act3"`
|
||||||
|
Act4 bool `json:"act4"`
|
||||||
|
Act5 bool `json:"act5"`
|
||||||
|
} `json:"progression"`
|
||||||
|
SeasonID int `json:"seasonId"`
|
||||||
|
TimePlayed struct {
|
||||||
|
Barbarian int `json:"barbarian"`
|
||||||
|
Crusader float64 `json:"crusader"`
|
||||||
|
Demon_hunter int `json:"demon-hunter"`
|
||||||
|
Monk int `json:"monk"`
|
||||||
|
Witch_doctor int `json:"witch-doctor"`
|
||||||
|
Wizard int `json:"wizard"`
|
||||||
|
} `json:"timePlayed"`
|
||||||
|
} `json:"season5"`
|
||||||
|
Season6 struct {
|
||||||
|
HighestHardcoreLevel int `json:"highestHardcoreLevel"`
|
||||||
|
Kills struct {
|
||||||
|
Elites int `json:"elites"`
|
||||||
|
HardcoreMonsters int `json:"hardcoreMonsters"`
|
||||||
|
Monsters int `json:"monsters"`
|
||||||
|
} `json:"kills"`
|
||||||
|
ParagonLevel int `json:"paragonLevel"`
|
||||||
|
ParagonLevelHardcore int `json:"paragonLevelHardcore"`
|
||||||
|
Progression struct {
|
||||||
|
Act1 bool `json:"act1"`
|
||||||
|
Act2 bool `json:"act2"`
|
||||||
|
Act3 bool `json:"act3"`
|
||||||
|
Act4 bool `json:"act4"`
|
||||||
|
Act5 bool `json:"act5"`
|
||||||
|
} `json:"progression"`
|
||||||
|
SeasonID int `json:"seasonId"`
|
||||||
|
TimePlayed struct {
|
||||||
|
Barbarian int `json:"barbarian"`
|
||||||
|
Crusader int `json:"crusader"`
|
||||||
|
Demon_hunter int `json:"demon-hunter"`
|
||||||
|
Monk int `json:"monk"`
|
||||||
|
Witch_doctor int `json:"witch-doctor"`
|
||||||
|
Wizard int `json:"wizard"`
|
||||||
|
} `json:"timePlayed"`
|
||||||
|
} `json:"season6"`
|
||||||
|
} `json:"seasonalProfiles"`
|
||||||
|
TimePlayed struct {
|
||||||
|
Barbarian float64 `json:"barbarian"`
|
||||||
|
Crusader float64 `json:"crusader"`
|
||||||
|
Demon_hunter float64 `json:"demon-hunter"`
|
||||||
|
Monk float64 `json:"monk"`
|
||||||
|
Witch_doctor int `json:"witch-doctor"`
|
||||||
|
Wizard float64 `json:"wizard"`
|
||||||
|
} `json:"timePlayed"`
|
||||||
|
}
|
||||||
|
type d3Hero struct {
|
||||||
|
Class string `json:"class"`
|
||||||
|
Dead bool `json:"dead"`
|
||||||
|
Followers struct {
|
||||||
|
Enchantress struct {
|
||||||
|
Items struct{} `json:"items"`
|
||||||
|
Level int `json:"level"`
|
||||||
|
Skills []struct {
|
||||||
|
Skill struct {
|
||||||
|
Description string `json:"description"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
Level int `json:"level"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
SimpleDescription string `json:"simpleDescription"`
|
||||||
|
SkillCalcID string `json:"skillCalcId"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
TooltipURL string `json:"tooltipUrl"`
|
||||||
|
} `json:"skill"`
|
||||||
|
} `json:"skills"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
Stats struct {
|
||||||
|
ExperienceBonus int `json:"experienceBonus"`
|
||||||
|
GoldFind int `json:"goldFind"`
|
||||||
|
MagicFind int `json:"magicFind"`
|
||||||
|
} `json:"stats"`
|
||||||
|
} `json:"enchantress"`
|
||||||
|
Scoundrel struct {
|
||||||
|
Items struct {
|
||||||
|
MainHand struct {
|
||||||
|
DisplayColor string `json:"displayColor"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
TooltipParams string `json:"tooltipParams"`
|
||||||
|
} `json:"mainHand"`
|
||||||
|
Special struct {
|
||||||
|
DisplayColor string `json:"displayColor"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
ID string `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
TooltipParams string `json:"tooltipParams"`
|
||||||
|
} `json:"special"`
|
||||||
|
} `json:"items"`
|
||||||
|
Level int `json:"level"`
|
||||||
|
Skills []struct {
|
||||||
|
Skill struct {
|
||||||
|
Description string `json:"description"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
Level int `json:"level"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
SimpleDescription string `json:"simpleDescription"`
|
||||||
|
SkillCalcID string `json:"skillCalcId"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
TooltipURL string `json:"tooltipUrl"`
|
||||||
|
} `json:"skill"`
|
||||||
|
} `json:"skills"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
Stats struct {
|
||||||
|
ExperienceBonus int `json:"experienceBonus"`
|
||||||
|
GoldFind int `json:"goldFind"`
|
||||||
|
MagicFind int `json:"magicFind"`
|
||||||
|
} `json:"stats"`
|
||||||
|
} `json:"scoundrel"`
|
||||||
|
Templar struct {
|
||||||
|
Items struct{} `json:"items"`
|
||||||
|
Level int `json:"level"`
|
||||||
|
Skills []struct {
|
||||||
|
Skill struct {
|
||||||
|
Description string `json:"description"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
Level int `json:"level"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
SimpleDescription string `json:"simpleDescription"`
|
||||||
|
SkillCalcID string `json:"skillCalcId"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
TooltipURL string `json:"tooltipUrl"`
|
||||||
|
} `json:"skill"`
|
||||||
|
} `json:"skills"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
Stats struct {
|
||||||
|
ExperienceBonus int `json:"experienceBonus"`
|
||||||
|
GoldFind int `json:"goldFind"`
|
||||||
|
MagicFind int `json:"magicFind"`
|
||||||
|
} `json:"stats"`
|
||||||
|
} `json:"templar"`
|
||||||
|
} `json:"followers"`
|
||||||
|
Gender int `json:"gender"`
|
||||||
|
Hardcore bool `json:"hardcore"`
|
||||||
|
ID int `json:"id"`
|
||||||
|
Items struct{} `json:"items"`
|
||||||
|
Kills struct {
|
||||||
|
Elites int `json:"elites"`
|
||||||
|
} `json:"kills"`
|
||||||
|
Last_updated int `json:"last-updated"`
|
||||||
|
LegendaryPowers []interface{} `json:"legendaryPowers"`
|
||||||
|
Level int `json:"level"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
ParagonLevel int `json:"paragonLevel"`
|
||||||
|
Progression struct {
|
||||||
|
Act1 struct {
|
||||||
|
Completed bool `json:"completed"`
|
||||||
|
CompletedQuests []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
} `json:"completedQuests"`
|
||||||
|
} `json:"act1"`
|
||||||
|
Act2 struct {
|
||||||
|
Completed bool `json:"completed"`
|
||||||
|
CompletedQuests []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
} `json:"completedQuests"`
|
||||||
|
} `json:"act2"`
|
||||||
|
Act3 struct {
|
||||||
|
Completed bool `json:"completed"`
|
||||||
|
CompletedQuests []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
} `json:"completedQuests"`
|
||||||
|
} `json:"act3"`
|
||||||
|
Act4 struct {
|
||||||
|
Completed bool `json:"completed"`
|
||||||
|
CompletedQuests []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
} `json:"completedQuests"`
|
||||||
|
} `json:"act4"`
|
||||||
|
Act5 struct {
|
||||||
|
Completed bool `json:"completed"`
|
||||||
|
CompletedQuests []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
} `json:"completedQuests"`
|
||||||
|
} `json:"act5"`
|
||||||
|
} `json:"progression"`
|
||||||
|
SeasonCreated int `json:"seasonCreated"`
|
||||||
|
Seasonal bool `json:"seasonal"`
|
||||||
|
Skills struct {
|
||||||
|
Active []struct {
|
||||||
|
Rune struct {
|
||||||
|
Description string `json:"description"`
|
||||||
|
Level int `json:"level"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Order int `json:"order"`
|
||||||
|
SimpleDescription string `json:"simpleDescription"`
|
||||||
|
SkillCalcID string `json:"skillCalcId"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
TooltipParams string `json:"tooltipParams"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
} `json:"rune"`
|
||||||
|
Skill struct {
|
||||||
|
CategorySlug string `json:"categorySlug"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
Level int `json:"level"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
SimpleDescription string `json:"simpleDescription"`
|
||||||
|
SkillCalcID string `json:"skillCalcId"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
TooltipURL string `json:"tooltipUrl"`
|
||||||
|
} `json:"skill"`
|
||||||
|
} `json:"active"`
|
||||||
|
Passive []struct {
|
||||||
|
Skill struct {
|
||||||
|
Description string `json:"description"`
|
||||||
|
Flavor string `json:"flavor"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
Level int `json:"level"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
SkillCalcID string `json:"skillCalcId"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
TooltipURL string `json:"tooltipUrl"`
|
||||||
|
} `json:"skill"`
|
||||||
|
} `json:"passive"`
|
||||||
|
} `json:"skills"`
|
||||||
|
Stats struct {
|
||||||
|
ArcaneResist int `json:"arcaneResist"`
|
||||||
|
Armor int `json:"armor"`
|
||||||
|
AttackSpeed int `json:"attackSpeed"`
|
||||||
|
BlockAmountMax int `json:"blockAmountMax"`
|
||||||
|
BlockAmountMin int `json:"blockAmountMin"`
|
||||||
|
BlockChance int `json:"blockChance"`
|
||||||
|
ColdResist int `json:"coldResist"`
|
||||||
|
CritChance float64 `json:"critChance"`
|
||||||
|
CritDamage float64 `json:"critDamage"`
|
||||||
|
Damage float64 `json:"damage"`
|
||||||
|
DamageIncrease int `json:"damageIncrease"`
|
||||||
|
DamageReduction int `json:"damageReduction"`
|
||||||
|
Dexterity int `json:"dexterity"`
|
||||||
|
FireResist int `json:"fireResist"`
|
||||||
|
GoldFind int `json:"goldFind"`
|
||||||
|
Healing float64 `json:"healing"`
|
||||||
|
Intelligence int `json:"intelligence"`
|
||||||
|
Life int `json:"life"`
|
||||||
|
LifeOnHit int `json:"lifeOnHit"`
|
||||||
|
LifePerKill int `json:"lifePerKill"`
|
||||||
|
LifeSteal int `json:"lifeSteal"`
|
||||||
|
LightningResist int `json:"lightningResist"`
|
||||||
|
MagicFind int `json:"magicFind"`
|
||||||
|
PhysicalResist int `json:"physicalResist"`
|
||||||
|
PoisonResist int `json:"poisonResist"`
|
||||||
|
PrimaryResource int `json:"primaryResource"`
|
||||||
|
SecondaryResource int `json:"secondaryResource"`
|
||||||
|
Strength int `json:"strength"`
|
||||||
|
Thorns int `json:"thorns"`
|
||||||
|
Toughness float64 `json:"toughness"`
|
||||||
|
Vitality int `json:"vitality"`
|
||||||
|
} `json:"stats"`
|
||||||
|
}
|
||||||
+15
-11
@@ -2,12 +2,14 @@
|
|||||||
package modules
|
package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
)
|
||||||
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"time"
|
||||||
"net"
|
"net"
|
||||||
|
"bufio"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -24,9 +26,9 @@ var (
|
|||||||
func init() {
|
func init() {
|
||||||
MsgHandlers["ts3"] = ts3HandleMessage
|
MsgHandlers["ts3"] = ts3HandleMessage
|
||||||
log.Println("Initializing ts3 module")
|
log.Println("Initializing ts3 module")
|
||||||
go setConfig()
|
go setTS3Config()
|
||||||
}
|
}
|
||||||
func setConfig() {
|
func setTS3Config() {
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
host = ModParams["tshost"]
|
host = ModParams["tshost"]
|
||||||
port = ModParams["tsport"]
|
port = ModParams["tsport"]
|
||||||
@@ -35,12 +37,12 @@ func setConfig() {
|
|||||||
botname = ModParams["tsbotname"]
|
botname = ModParams["tsbotname"]
|
||||||
channel = ModParams["tschan"]
|
channel = ModParams["tschan"]
|
||||||
tsboticon = ModParams["tsboticon"]
|
tsboticon = ModParams["tsboticon"]
|
||||||
go loop()
|
go ts3loop()
|
||||||
}
|
}
|
||||||
func loop() {
|
func ts3loop() {
|
||||||
for {
|
for {
|
||||||
var err error
|
var err error
|
||||||
users, err = getUsers()
|
users, err = getTS3Users()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
log.Println("Trying again in 60 seconds.")
|
log.Println("Trying again in 60 seconds.")
|
||||||
@@ -54,18 +56,20 @@ func loop() {
|
|||||||
if channel == "" { // dont spam if no channel is set
|
if channel == "" { // dont spam if no channel is set
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
neu, err := getUsers()
|
neu, err := getTS3Users()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
time.Sleep(50 * time.Second)
|
time.Sleep(50 * time.Second)
|
||||||
} else {
|
} else {
|
||||||
for i, _ := range neu {
|
for i, _ := range neu {
|
||||||
if users[i] != neu[i] {
|
if users[i] != neu[i] {
|
||||||
|
log.Println("TS3: " + i + " joined")
|
||||||
SayCh <- GeneratePayload(channel, tsboticon, i+" joined TS3.", botname)
|
SayCh <- GeneratePayload(channel, tsboticon, i+" joined TS3.", botname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, _ := range users {
|
for i, _ := range users {
|
||||||
if users[i] != neu[i] {
|
if users[i] != neu[i] {
|
||||||
|
log.Println("TS3: " + i + " left")
|
||||||
SayCh <- GeneratePayload(channel, tsboticon, i+" left TS3.", botname)
|
SayCh <- GeneratePayload(channel, tsboticon, i+" left TS3.", botname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,8 +81,8 @@ func loop() {
|
|||||||
}
|
}
|
||||||
func ts3HandleMessage(payload *WebhookPayload) {
|
func ts3HandleMessage(payload *WebhookPayload) {
|
||||||
if payload.Command == "/ts" || payload.TriggerWord == "!ts" {
|
if payload.Command == "/ts" || payload.TriggerWord == "!ts" {
|
||||||
log.Println("TS3 users requested by " + payload.UserName)
|
log.Println("TS3: current users requested by " + payload.UserName)
|
||||||
users, _ := getUsers()
|
users, _ := getTS3Users()
|
||||||
var s string
|
var s string
|
||||||
i := 0
|
i := 0
|
||||||
s += "Current users on TS3 Server:\n"
|
s += "Current users on TS3 Server:\n"
|
||||||
@@ -93,7 +97,7 @@ func ts3HandleMessage(payload *WebhookPayload) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUsers() (u map[string]bool, e error) {
|
func getTS3Users() (u map[string]bool, e error) {
|
||||||
conn, err := net.Dial("tcp", host+":"+port)
|
conn, err := net.Dial("tcp", host+":"+port)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -266,6 +266,7 @@ func twitchSendMsg(tcobj TwitchChannelObject, tso TwitchStreamObject, target str
|
|||||||
if target == "" {
|
if target == "" {
|
||||||
target = announceChannel
|
target = announceChannel
|
||||||
}
|
}
|
||||||
|
log.Println("TS3: announcing " + tso.Stream.Channel.DisplayName)
|
||||||
SayCh <- GeneratePayload(target,
|
SayCh <- GeneratePayload(target,
|
||||||
twitchBotIcon,
|
twitchBotIcon,
|
||||||
"*"+tso.Stream.Channel.DisplayName+
|
"*"+tso.Stream.Channel.DisplayName+
|
||||||
|
|||||||
Reference in New Issue
Block a user