modules/sc: Answers go to channel where query was initiated

This commit is contained in:
an 2017-07-01 16:23:07 +02:00
parent ad20283c23
commit 1edeefa0ff
1 changed files with 34 additions and 32 deletions

View File

@ -4,6 +4,7 @@ package modules
import (
"encoding/json"
"flag"
"fmt"
"html"
"io/ioutil"
@ -40,9 +41,10 @@ const (
)
var (
fans = 0
fleet = 0
funds = 0
fans = 0
fleet = 0
funds = 0
targetChannel = flag.String("sc_target_channel", "", "Default channel for stats output")
)
func init() {
@ -57,14 +59,14 @@ func scHandleMessage(m *Message) {
}
switch tok[0] {
case "!scstats":
showScStats()
showScStats(m.Channel)
case "!sccit":
if len(tok) > 1 {
showCitizen(tok[1])
showCitizen(tok[1], m.Channel)
}
case "!scorg":
if len(tok) > 1 {
showOrganization(tok[1])
showOrganization(tok[1], m.Channel)
}
default:
}
@ -109,13 +111,13 @@ func scScraper() {
nextFunds := ((funds / FUNDS_INT) * FUNDS_INT) + FUNDS_INT
if curFans >= nextFans {
SayCh <- "*\n[SC] Star Citizens: " + util.NumberToString(curFans, '.')
SayCh <- *targetChannel + "\n[SC] Star Citizens: " + util.NumberToString(curFans, '.')
}
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 {
SayCh <- "*\n[SC] Funds raised: " + util.NumberToString(curFunds, '.')
SayCh <- *targetChannel + "\n[SC] Funds raised: " + util.NumberToString(curFunds, '.')
}
fans = curFans
@ -123,14 +125,14 @@ func scScraper() {
funds = curFunds
}
func showScStats() {
SayCh <- "*\n**SC User and Funding Stats**"
SayCh <- fmt.Sprintf("*\nFans: %s", util.NumberToString(fans, '.'))
SayCh <- fmt.Sprintf("*\nFleet: %s", util.NumberToString(fleet, '.'))
SayCh <- fmt.Sprintf("*\nFunds: $ %s", util.NumberToString(funds, '.'))
func showScStats(channel string) {
SayCh <- channel + "\n**SC User and Funding Stats**"
SayCh <- fmt.Sprintf("%s\nFans: %s", channel, util.NumberToString(fans, '.'))
SayCh <- fmt.Sprintf("%s\nFleet: %s", channel, util.NumberToString(fleet, '.'))
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)
if err != nil {
xlog.Info("Error: %v", err)
@ -155,22 +157,22 @@ func showCitizen(handle string) {
sid := reSid.FindStringSubmatch(string(body))
rank := reRank.FindStringSubmatch(string(body))
if len(name) > 1 {
SayCh <- "*\n**Citizen Info**"
SayCh <- "*\n" + "Name: " + html.UnescapeString(string(name[1])) + " [" + string(handle_[1]) + "]"
SayCh <- "*\n" + "URL: " + QUERY_CIT_URL + string(handle_[1])
SayCh <- "*\n" + "UEE #: " + string(record[1])
SayCh <- channel + "\n**Citizen Info**"
SayCh <- channel + "\nName: " + html.UnescapeString(string(name[1])) + " [" + string(handle_[1]) + "]"
SayCh <- channel + "\nURL: " + QUERY_CIT_URL + string(handle_[1])
SayCh <- channel + "\nUEE #: " + string(record[1])
if len(org) > 1 {
SayCh <- "*\n" + "Organization: " + html.UnescapeString(string(org[1])) + " [" + string(sid[1]) + "]"
SayCh <- "*\n" + "Rank: " + html.UnescapeString(string(rank[1]))
SayCh <- channel + "\nOrganization: " + html.UnescapeString(string(org[1])) + " [" + string(sid[1]) + "]"
SayCh <- channel + "\nRank: " + html.UnescapeString(string(rank[1]))
} else {
SayCh <- "*\n" + "Organization: <none>"
SayCh <- channel + "\nOrganization: <none>"
}
} 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)
if err != nil {
xlog.Info("Error: %v", err)
@ -193,14 +195,14 @@ func showOrganization(handle string) {
focus := reFocus.FindStringSubmatch(string(body))
comm := reComm.FindStringSubmatch(string(body))
if len(name) > 1 {
SayCh <- "*\n**Organization Info**"
SayCh <- "*\nName: " + string(name[1]) + " [" + strings.ToUpper(handle) + "]"
SayCh <- "*\nURL: " + QUERY_ORG_URL + strings.ToUpper(handle)
SayCh <- "*\nMembers: " + string(count[1])
SayCh <- "*\nModel: " + string(model[1])
SayCh <- "*\nCommitment: " + string(comm[1])
SayCh <- "*\nFocus: " + string(focus[1]) + ", " + string(focus[2])
SayCh <- channel + "\n**Organization Info**"
SayCh <- channel + "\nName: " + string(name[1]) + " [" + strings.ToUpper(handle) + "]"
SayCh <- channel + "\nURL: " + QUERY_ORG_URL + strings.ToUpper(handle)
SayCh <- channel + "\nMembers: " + string(count[1])
SayCh <- channel + "\nModel: " + string(model[1])
SayCh <- channel + "\nCommitment: " + string(comm[1])
SayCh <- channel + "\nFocus: " + string(focus[1]) + ", " + string(focus[2])
} else {
SayCh <- "*\n***No Such Organization***"
SayCh <- channel + "\n***No Such Organization***"
}
}