forked from an/flokati
modules/sc: Answers go to channel where query was initiated
This commit is contained in:
parent
ad20283c23
commit
1edeefa0ff
|
@ -4,6 +4,7 @@ package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -43,6 +44,7 @@ var (
|
||||||
fans = 0
|
fans = 0
|
||||||
fleet = 0
|
fleet = 0
|
||||||
funds = 0
|
funds = 0
|
||||||
|
targetChannel = flag.String("sc_target_channel", "", "Default channel for stats output")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -57,14 +59,14 @@ func scHandleMessage(m *Message) {
|
||||||
}
|
}
|
||||||
switch tok[0] {
|
switch tok[0] {
|
||||||
case "!scstats":
|
case "!scstats":
|
||||||
showScStats()
|
showScStats(m.Channel)
|
||||||
case "!sccit":
|
case "!sccit":
|
||||||
if len(tok) > 1 {
|
if len(tok) > 1 {
|
||||||
showCitizen(tok[1])
|
showCitizen(tok[1], m.Channel)
|
||||||
}
|
}
|
||||||
case "!scorg":
|
case "!scorg":
|
||||||
if len(tok) > 1 {
|
if len(tok) > 1 {
|
||||||
showOrganization(tok[1])
|
showOrganization(tok[1], m.Channel)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
@ -109,13 +111,13 @@ func scScraper() {
|
||||||
nextFunds := ((funds / FUNDS_INT) * FUNDS_INT) + FUNDS_INT
|
nextFunds := ((funds / FUNDS_INT) * FUNDS_INT) + FUNDS_INT
|
||||||
|
|
||||||
if curFans >= nextFans {
|
if curFans >= nextFans {
|
||||||
SayCh <- "*\n[SC] Star Citizens: " + util.NumberToString(curFans, '.')
|
SayCh <- *targetChannel + "\n[SC] Star Citizens: " + util.NumberToString(curFans, '.')
|
||||||
}
|
}
|
||||||
if curFleet >= nextFleet {
|
if curFleet >= nextFleet {
|
||||||
SayCh <- "*\n[SC] The UEE Fleet: " + util.NumberToString(curFleet, '.')
|
SayCh <- *targetChannel + "\n[SC] The UEE Fleet: " + util.NumberToString(curFleet, '.')
|
||||||
}
|
}
|
||||||
if curFunds >= nextFunds {
|
if curFunds >= nextFunds {
|
||||||
SayCh <- "*\n[SC] Funds raised: " + util.NumberToString(curFunds, '.')
|
SayCh <- *targetChannel + "\n[SC] Funds raised: " + util.NumberToString(curFunds, '.')
|
||||||
}
|
}
|
||||||
|
|
||||||
fans = curFans
|
fans = curFans
|
||||||
|
@ -123,14 +125,14 @@ func scScraper() {
|
||||||
funds = curFunds
|
funds = curFunds
|
||||||
}
|
}
|
||||||
|
|
||||||
func showScStats() {
|
func showScStats(channel string) {
|
||||||
SayCh <- "*\n**SC User and Funding Stats**"
|
SayCh <- channel + "\n**SC User and Funding Stats**"
|
||||||
SayCh <- fmt.Sprintf("*\nFans: %s", util.NumberToString(fans, '.'))
|
SayCh <- fmt.Sprintf("%s\nFans: %s", channel, util.NumberToString(fans, '.'))
|
||||||
SayCh <- fmt.Sprintf("*\nFleet: %s", util.NumberToString(fleet, '.'))
|
SayCh <- fmt.Sprintf("%s\nFleet: %s", channel, util.NumberToString(fleet, '.'))
|
||||||
SayCh <- fmt.Sprintf("*\nFunds: $ %s", util.NumberToString(funds, '.'))
|
SayCh <- fmt.Sprintf("%s*\nFunds: $ %s", channel, util.NumberToString(funds, '.'))
|
||||||
}
|
}
|
||||||
|
|
||||||
func showCitizen(handle string) {
|
func showCitizen(handle, channel string) {
|
||||||
resp, err := http.Get(QUERY_CIT_URL + handle)
|
resp, err := http.Get(QUERY_CIT_URL + handle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xlog.Info("Error: %v", err)
|
xlog.Info("Error: %v", err)
|
||||||
|
@ -155,22 +157,22 @@ func showCitizen(handle string) {
|
||||||
sid := reSid.FindStringSubmatch(string(body))
|
sid := reSid.FindStringSubmatch(string(body))
|
||||||
rank := reRank.FindStringSubmatch(string(body))
|
rank := reRank.FindStringSubmatch(string(body))
|
||||||
if len(name) > 1 {
|
if len(name) > 1 {
|
||||||
SayCh <- "*\n**Citizen Info**"
|
SayCh <- channel + "\n**Citizen Info**"
|
||||||
SayCh <- "*\n" + "Name: " + html.UnescapeString(string(name[1])) + " [" + string(handle_[1]) + "]"
|
SayCh <- channel + "\nName: " + html.UnescapeString(string(name[1])) + " [" + string(handle_[1]) + "]"
|
||||||
SayCh <- "*\n" + "URL: " + QUERY_CIT_URL + string(handle_[1])
|
SayCh <- channel + "\nURL: " + QUERY_CIT_URL + string(handle_[1])
|
||||||
SayCh <- "*\n" + "UEE #: " + string(record[1])
|
SayCh <- channel + "\nUEE #: " + string(record[1])
|
||||||
if len(org) > 1 {
|
if len(org) > 1 {
|
||||||
SayCh <- "*\n" + "Organization: " + html.UnescapeString(string(org[1])) + " [" + string(sid[1]) + "]"
|
SayCh <- channel + "\nOrganization: " + html.UnescapeString(string(org[1])) + " [" + string(sid[1]) + "]"
|
||||||
SayCh <- "*\n" + "Rank: " + html.UnescapeString(string(rank[1]))
|
SayCh <- channel + "\nRank: " + html.UnescapeString(string(rank[1]))
|
||||||
} else {
|
} else {
|
||||||
SayCh <- "*\n" + "Organization: <none>"
|
SayCh <- channel + "\nOrganization: <none>"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SayCh <- "*\n" + "***No Such Citizen***"
|
SayCh <- channel + "\n***No Such Citizen***"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func showOrganization(handle string) {
|
func showOrganization(handle, channel string) {
|
||||||
resp, err := http.Get(QUERY_ORG_URL + handle)
|
resp, err := http.Get(QUERY_ORG_URL + handle)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xlog.Info("Error: %v", err)
|
xlog.Info("Error: %v", err)
|
||||||
|
@ -193,14 +195,14 @@ func showOrganization(handle string) {
|
||||||
focus := reFocus.FindStringSubmatch(string(body))
|
focus := reFocus.FindStringSubmatch(string(body))
|
||||||
comm := reComm.FindStringSubmatch(string(body))
|
comm := reComm.FindStringSubmatch(string(body))
|
||||||
if len(name) > 1 {
|
if len(name) > 1 {
|
||||||
SayCh <- "*\n**Organization Info**"
|
SayCh <- channel + "\n**Organization Info**"
|
||||||
SayCh <- "*\nName: " + string(name[1]) + " [" + strings.ToUpper(handle) + "]"
|
SayCh <- channel + "\nName: " + string(name[1]) + " [" + strings.ToUpper(handle) + "]"
|
||||||
SayCh <- "*\nURL: " + QUERY_ORG_URL + strings.ToUpper(handle)
|
SayCh <- channel + "\nURL: " + QUERY_ORG_URL + strings.ToUpper(handle)
|
||||||
SayCh <- "*\nMembers: " + string(count[1])
|
SayCh <- channel + "\nMembers: " + string(count[1])
|
||||||
SayCh <- "*\nModel: " + string(model[1])
|
SayCh <- channel + "\nModel: " + string(model[1])
|
||||||
SayCh <- "*\nCommitment: " + string(comm[1])
|
SayCh <- channel + "\nCommitment: " + string(comm[1])
|
||||||
SayCh <- "*\nFocus: " + string(focus[1]) + ", " + string(focus[2])
|
SayCh <- channel + "\nFocus: " + string(focus[1]) + ", " + string(focus[2])
|
||||||
} else {
|
} else {
|
||||||
SayCh <- "*\n***No Such Organization***"
|
SayCh <- channel + "\n***No Such Organization***"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue