forked from an/flokati
Added module configuration params: -params=<key>:<val>(!<key>:<val>])*
This commit is contained in:
parent
5f2dd41d55
commit
44ee1cf628
2
main.go
2
main.go
|
@ -52,7 +52,7 @@ func main() {
|
||||||
//mods := strings.Split(*modules, ",")
|
//mods := strings.Split(*modules, ",")
|
||||||
//TODO: implement more robust list parsing
|
//TODO: implement more robust list parsing
|
||||||
|
|
||||||
modules.Initialize(sayCh)
|
modules.Init(sayCh, *params)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
var ()
|
var ()
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
msgHandlers["announcements"] = anncouncementsHandleMessage
|
MsgHandlers["announcements"] = anncouncementsHandleMessage
|
||||||
log.Println("Initializing announcements module")
|
log.Println("Initializing announcements module")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
msgHandlers["coffee"] = coffeeHandleMessage
|
MsgHandlers["coffee"] = coffeeHandleMessage
|
||||||
log.Println("Initializing coffee module")
|
log.Println("Initializing coffee module")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,9 +37,9 @@ func coffeeHandleMessage(m *irc.Message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func coffeeMake(rec []string) {
|
func coffeeMake(rec []string) {
|
||||||
sayCh <- "*\nsetzt Kaffee auf."
|
SayCh <- "*\nsetzt Kaffee auf."
|
||||||
time.Sleep(30 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
sayCh <- "*\nstellt eine frische Kanne Kaffee in den Raum."
|
SayCh <- "*\nstellt eine frische Kanne Kaffee in den Raum."
|
||||||
if rec != nil {
|
if rec != nil {
|
||||||
var users string
|
var users string
|
||||||
for i, v := range rec {
|
for i, v := range rec {
|
||||||
|
@ -50,8 +50,8 @@ func coffeeMake(rec []string) {
|
||||||
users += " und "
|
users += " und "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sayCh <- "*\ngibt " + users + " einen frischen, richtig schwarzen, richtig leckeren Kaffee."
|
SayCh <- "*\ngibt " + users + " einen frischen, richtig schwarzen, richtig leckeren Kaffee."
|
||||||
}
|
}
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
sayCh <- "*\nProst! (c)"
|
SayCh <- "*\nProst! (c)"
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
msgHandlers["fortune"] = fortuneHandleMessage
|
MsgHandlers["fortune"] = fortuneHandleMessage
|
||||||
log.Println("Initializing fortune module")
|
log.Println("Initializing fortune module")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ func fortune() {
|
||||||
s = strings.Replace(s, "\t", " ", -1)
|
s = strings.Replace(s, "\t", " ", -1)
|
||||||
for _, l := range strings.Split(s, "\n") {
|
for _, l := range strings.Split(s, "\n") {
|
||||||
if l != "" {
|
if l != "" {
|
||||||
sayCh <- fmt.Sprintf("*\n%s", l)
|
SayCh <- fmt.Sprintf("*\n%s", l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
msgHandlers["fuzzytime"] = fuzzytimeHandleMessage
|
MsgHandlers["fuzzytime"] = fuzzytimeHandleMessage
|
||||||
log.Println("Initializing fuzzytime module")
|
log.Println("Initializing fuzzytime module")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ func fuzzytimeShow() {
|
||||||
s += fmt.Sprintf("%s Uhr\n", fuzzytimeSayHour(h+1))
|
s += fmt.Sprintf("%s Uhr\n", fuzzytimeSayHour(h+1))
|
||||||
}
|
}
|
||||||
log.Println("saying now:", s)
|
log.Println("saying now:", s)
|
||||||
sayCh <- fmt.Sprintf("*\n%s", s)
|
SayCh <- fmt.Sprintf("*\n%s", s)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,9 +23,14 @@ import (
|
||||||
var hideOutput = true
|
var hideOutput = true
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
msgHandlers["rss"] = rssHandleMessage
|
MsgHandlers["rss"] = rssHandleMessage
|
||||||
log.Printf("Initializing news module")
|
log.Printf("Initializing rss module")
|
||||||
path := "newsfeeds.conf"
|
go rssRun()
|
||||||
|
}
|
||||||
|
|
||||||
|
func rssRun() {
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
path := ModParams["rss-feeds"]
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -53,7 +58,7 @@ func rssPollFeed(uri string, timeout int, cr xmlx.CharsetFunc) {
|
||||||
log.Printf("Polling feed: %s", uri)
|
log.Printf("Polling feed: %s", uri)
|
||||||
if err := feed.Fetch(uri, cr); err != nil {
|
if err := feed.Fetch(uri, cr); err != nil {
|
||||||
log.Printf("[e] %s: %s", "*", uri, err)
|
log.Printf("[e] %s: %s", "*", uri, err)
|
||||||
sayCh <- fmt.Sprintf("%s\n[RSS] Error %s: %s", "*", uri, err)
|
SayCh <- fmt.Sprintf("%s\n[RSS] Error %s: %s", "*", uri, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
<-time.After(time.Duration(feed.SecondsTillUpdate() * 1e9))
|
<-time.After(time.Duration(feed.SecondsTillUpdate() * 1e9))
|
||||||
|
@ -61,7 +66,7 @@ func rssPollFeed(uri string, timeout int, cr xmlx.CharsetFunc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func rssChanHandler(feed *gorss.Feed, newchannels []*gorss.Channel) {
|
func rssChanHandler(feed *gorss.Feed, newchannels []*gorss.Channel) {
|
||||||
sayCh <- fmt.Sprintf("%s\n[RSS] %d new channel(s) in %s", "*", len(newchannels), feed.Url)
|
SayCh <- fmt.Sprintf("%s\n[RSS] %d new channel(s) in %s", "*", len(newchannels), feed.Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
func rssItemHandler(feed *gorss.Feed, ch *gorss.Channel, newitems []*gorss.Item) {
|
func rssItemHandler(feed *gorss.Feed, ch *gorss.Channel, newitems []*gorss.Item) {
|
||||||
|
@ -69,7 +74,7 @@ func rssItemHandler(feed *gorss.Feed, ch *gorss.Channel, newitems []*gorss.Item)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, ni := range newitems {
|
for _, ni := range newitems {
|
||||||
sayCh <- fmt.Sprintf("%s\n[RSS] %v - %v", "*", ni.Title, ni.Links[0].Href)
|
SayCh <- fmt.Sprintf("%s\n[RSS] %v - %v", "*", ni.Title, ni.Links[0].Href)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
msgHandlers["sc"] = scHandleMessage
|
MsgHandlers["sc"] = scHandleMessage
|
||||||
log.Println("Initializing sc module")
|
log.Println("Initializing sc module")
|
||||||
go scScrapeLoop()
|
go scScrapeLoop()
|
||||||
}
|
}
|
||||||
|
@ -111,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 <- "*\n[SC] Star Citizens: " + util.NumberToString(curFans, '.')
|
||||||
}
|
}
|
||||||
if curFleet >= nextFleet {
|
if curFleet >= nextFleet {
|
||||||
sayCh <- "*\n[SC] The UEE Fleet: " + util.NumberToString(curFleet, '.')
|
SayCh <- "*\n[SC] The UEE Fleet: " + util.NumberToString(curFleet, '.')
|
||||||
}
|
}
|
||||||
if curFunds >= nextFunds {
|
if curFunds >= nextFunds {
|
||||||
sayCh <- "*\n[SC] Funds raised: " + util.NumberToString(curFunds, '.')
|
SayCh <- "*\n[SC] Funds raised: " + util.NumberToString(curFunds, '.')
|
||||||
}
|
}
|
||||||
|
|
||||||
fans = curFans
|
fans = curFans
|
||||||
|
@ -126,10 +126,10 @@ func scScraper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func showScStats() {
|
func showScStats() {
|
||||||
sayCh <- "*\n*** SC User and Funding Stats ***"
|
SayCh <- "*\n*** SC User and Funding Stats ***"
|
||||||
sayCh <- fmt.Sprintf("*\nFans: %s", util.NumberToString(fans, '.'))
|
SayCh <- fmt.Sprintf("*\nFans: %s", util.NumberToString(fans, '.'))
|
||||||
sayCh <- fmt.Sprintf("*\nFleet: %s", util.NumberToString(fleet, '.'))
|
SayCh <- fmt.Sprintf("*\nFleet: %s", util.NumberToString(fleet, '.'))
|
||||||
sayCh <- fmt.Sprintf("*\nFunds: $ %s", util.NumberToString(funds, '.'))
|
SayCh <- fmt.Sprintf("*\nFunds: $ %s", util.NumberToString(funds, '.'))
|
||||||
}
|
}
|
||||||
|
|
||||||
func showCitizen(handle string) {
|
func showCitizen(handle string) {
|
||||||
|
@ -157,18 +157,18 @@ 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 <- "*\n*** Citizen Info ***"
|
||||||
sayCh <- "*\n" + "Name: " + html.UnescapeString(string(name[1])) + " [" + string(handle_[1]) + "]"
|
SayCh <- "*\n" + "Name: " + html.UnescapeString(string(name[1])) + " [" + string(handle_[1]) + "]"
|
||||||
sayCh <- "*\n" + "URL: " + QUERY_CIT_URL + string(handle_[1])
|
SayCh <- "*\n" + "URL: " + QUERY_CIT_URL + string(handle_[1])
|
||||||
sayCh <- "*\n" + "UEE #: " + string(record[1])
|
SayCh <- "*\n" + "UEE #: " + string(record[1])
|
||||||
if len(org) > 1 {
|
if len(org) > 1 {
|
||||||
sayCh <- "*\n" + "Organization: " + html.UnescapeString(string(org[1])) + " [" + string(sid[1]) + "]"
|
SayCh <- "*\n" + "Organization: " + html.UnescapeString(string(org[1])) + " [" + string(sid[1]) + "]"
|
||||||
sayCh <- "*\n" + "Rank: " + html.UnescapeString(string(rank[1]))
|
SayCh <- "*\n" + "Rank: " + html.UnescapeString(string(rank[1]))
|
||||||
} else {
|
} else {
|
||||||
sayCh <- "*\n" + "Organization: <none>"
|
SayCh <- "*\n" + "Organization: <none>"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sayCh <- "*\n" + "*** No Such Citizen ***"
|
SayCh <- "*\n" + "*** No Such Citizen ***"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,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 <- "*\n*** Organization Info ***"
|
||||||
sayCh <- "*\nName: " + string(name[1]) + " [" + strings.ToUpper(handle) + "]"
|
SayCh <- "*\nName: " + string(name[1]) + " [" + strings.ToUpper(handle) + "]"
|
||||||
sayCh <- "*\nURL: " + QUERY_ORG_URL + strings.ToUpper(handle)
|
SayCh <- "*\nURL: " + QUERY_ORG_URL + strings.ToUpper(handle)
|
||||||
sayCh <- "*\nMembers: " + string(count[1])
|
SayCh <- "*\nMembers: " + string(count[1])
|
||||||
sayCh <- "*\nModel: " + string(model[1])
|
SayCh <- "*\nModel: " + string(model[1])
|
||||||
sayCh <- "*\nCommitment: " + string(comm[1])
|
SayCh <- "*\nCommitment: " + string(comm[1])
|
||||||
sayCh <- "*\nFocus: " + string(focus[1]) + ", " + string(focus[2])
|
SayCh <- "*\nFocus: " + string(focus[1]) + ", " + string(focus[2])
|
||||||
} else {
|
} else {
|
||||||
sayCh <- "*\n*** No Such Organization ***"
|
SayCh <- "*\n*** No Such Organization ***"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -520,7 +520,7 @@ var quotes = [][]string{
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
msgHandlers["stoll"] = stollHandleMessage
|
MsgHandlers["stoll"] = stollHandleMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
func stollHandleMessage(m *irc.Message) {
|
func stollHandleMessage(m *irc.Message) {
|
||||||
|
@ -535,6 +535,6 @@ func stollHandleMessage(m *irc.Message) {
|
||||||
line += " "
|
line += " "
|
||||||
}
|
}
|
||||||
line += "[Dr. Axel Stoll, promovierter Naturwissenschaftler]"
|
line += "[Dr. Axel Stoll, promovierter Naturwissenschaftler]"
|
||||||
sayCh <- fmt.Sprintf("%s\n%s", "*", line)
|
SayCh <- fmt.Sprintf("%s\n%s", "*", line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
msgHandlers["twitch"] = twitchHandleMessage
|
MsgHandlers["twitch"] = twitchHandleMessage
|
||||||
log.Println("Initializing twitch module")
|
log.Println("Initializing twitch module")
|
||||||
go pollStreamData()
|
go pollStreamData()
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ func twitchHandleMessage(m *irc.Message) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if onlinestreams == 0 {
|
if onlinestreams == 0 {
|
||||||
sayCh <- fmt.Sprintf("*\n%s", "[TWTCH] All streams offline")
|
SayCh <- fmt.Sprintf("*\n%s", "[TWTCH] All streams offline")
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
streamname := tok[1]
|
streamname := tok[1]
|
||||||
|
@ -176,7 +176,7 @@ func twitchHandleMessage(m *irc.Message) {
|
||||||
co = getTwitchChannelObject(streamname)
|
co = getTwitchChannelObject(streamname)
|
||||||
twitchSendMsg(co, so)
|
twitchSendMsg(co, so)
|
||||||
} else {
|
} else {
|
||||||
sayCh <- fmt.Sprintf("*\n%s", "[TWTCH] "+streamname+" not found or offline")
|
SayCh <- fmt.Sprintf("*\n%s", "[TWTCH] "+streamname+" not found or offline")
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
@ -242,6 +242,6 @@ func getTwitchChannelObject(streamname string) TwitchChannelObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
func twitchSendMsg(tcobj TwitchChannelObject, tso TwitchStreamObject) {
|
func twitchSendMsg(tcobj TwitchChannelObject, tso TwitchStreamObject) {
|
||||||
sayCh <- fmt.Sprintf("*\n%s", "[TWTCH] "+tso.Stream.Channel.DisplayName+", "+util.NumberToString(tso.Stream.Viewers, '.')+" viewers, playing: "+tso.Stream.Game+", "+tcobj.URL)
|
SayCh <- fmt.Sprintf("*\n%s", "[TWTCH] "+tso.Stream.Channel.DisplayName+", "+util.NumberToString(tso.Stream.Viewers, '.')+" viewers, playing: "+tso.Stream.Game+", "+tcobj.URL)
|
||||||
sayCh <- fmt.Sprintf("*\n%s", "[TWTCH] "+"Title: \""+tcobj.Status+"\"")
|
SayCh <- fmt.Sprintf("*\n%s", "[TWTCH] "+"Title: \""+tcobj.Status+"\"")
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/sorcix/irc"
|
"github.com/sorcix/irc"
|
||||||
)
|
)
|
||||||
|
@ -69,8 +70,14 @@ type WeatherObject struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
msgHandlers["weather"] = weatherHandleMessage
|
MsgHandlers["weather"] = weatherHandleMessage
|
||||||
log.Println("Initializing weather module")
|
log.Println("Initializing weather module")
|
||||||
|
go weatherConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
func weatherConfig() {
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
owmQueryAPIKey = ModParams["weather-api-key"]
|
||||||
}
|
}
|
||||||
|
|
||||||
func weatherHandleMessage(m *irc.Message) {
|
func weatherHandleMessage(m *irc.Message) {
|
||||||
|
@ -82,10 +89,10 @@ func weatherHandleMessage(m *irc.Message) {
|
||||||
case "!weather", "!wetter":
|
case "!weather", "!wetter":
|
||||||
switch len(tok) {
|
switch len(tok) {
|
||||||
case 1:
|
case 1:
|
||||||
sayCh <- fmt.Sprintf("*\n%s", weatherPrefix+"Usage: !w <zip/city/state/country>")
|
SayCh <- fmt.Sprintf("*\n%s", weatherPrefix+"Usage: !w <zip/city/state/country>")
|
||||||
default:
|
default:
|
||||||
if strings.Compare(owmQueryAPIKey, "") == 0 {
|
if strings.Compare(owmQueryAPIKey, "") == 0 {
|
||||||
sayCh <- fmt.Sprintf("*\n%s", weatherPrefix+"No API Key set.")
|
SayCh <- fmt.Sprintf("*\n%s", weatherPrefix+"No API Key set.")
|
||||||
} else {
|
} else {
|
||||||
go getWeather(strings.Join(tok[1:], " "))
|
go getWeather(strings.Join(tok[1:], " "))
|
||||||
}
|
}
|
||||||
|
@ -99,19 +106,19 @@ func getWeather(query string) {
|
||||||
r, err := http.Get(q)
|
r, err := http.Get(q)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
sayCh <- fmt.Sprintf("*\n%s", weatherPrefix+err.Error())
|
SayCh <- fmt.Sprintf("*\n%s", weatherPrefix+err.Error())
|
||||||
} else {
|
} else {
|
||||||
re, err := ioutil.ReadAll(r.Body)
|
re, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
sayCh <- fmt.Sprintf("*\n%s", weatherPrefix+err.Error())
|
SayCh <- fmt.Sprintf("*\n%s", weatherPrefix+err.Error())
|
||||||
} else {
|
} else {
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
var wo WeatherObject
|
var wo WeatherObject
|
||||||
err := json.Unmarshal(re, &wo)
|
err := json.Unmarshal(re, &wo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
sayCh <- fmt.Sprintf("*\n%s", weatherPrefix+err.Error())
|
SayCh <- fmt.Sprintf("*\n%s", weatherPrefix+err.Error())
|
||||||
} else {
|
} else {
|
||||||
var description string
|
var description string
|
||||||
if len(wo.Weather) < 1 {
|
if len(wo.Weather) < 1 {
|
||||||
|
@ -119,7 +126,7 @@ func getWeather(query string) {
|
||||||
} else {
|
} else {
|
||||||
description = ", " + wo.Weather[0].Description
|
description = ", " + wo.Weather[0].Description
|
||||||
}
|
}
|
||||||
sayCh <- fmt.Sprintf("*\n%s", weatherPrefix+wo.Name+", "+wo.Sys.Country+
|
SayCh <- fmt.Sprintf("*\n%s", weatherPrefix+wo.Name+", "+wo.Sys.Country+
|
||||||
" - Temp: "+strconv.Itoa(int(wo.Main.Temp-273.15))+
|
" - Temp: "+strconv.Itoa(int(wo.Main.Temp-273.15))+
|
||||||
"°C"+description+
|
"°C"+description+
|
||||||
", Humidity: "+strconv.Itoa(int(wo.Main.Humidity))+
|
", Humidity: "+strconv.Itoa(int(wo.Main.Humidity))+
|
||||||
|
|
Loading…
Reference in New Issue