From b30ccd0171f7cefe1e9db4ee4ad8a273a36aabe8 Mon Sep 17 00:00:00 2001 From: an Date: Sun, 25 Jun 2017 12:03:49 +0200 Subject: [PATCH] modules/weather: new config flag for api key --- modules/coffee.go | 5 ++--- modules/markov.go | 25 +++++++++++++++---------- modules/quiz.go | 3 ++- modules/sc.go | 12 ++++++------ modules/twitch.go | 2 +- modules/weather.go | 7 ++++++- 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/modules/coffee.go b/modules/coffee.go index 05a0207..80e42f5 100644 --- a/modules/coffee.go +++ b/modules/coffee.go @@ -13,7 +13,6 @@ import ( "time" "github.com/sorcix/irc" - "github.com/sorcix/irc/ctcp" ) type Receivers struct { @@ -102,6 +101,6 @@ func (r *Receivers) addNames(newNames []string) { } func printAction(s string) { - msg := ctcp.Encode(ctcp.ACTION, fmt.Sprintf(s)) - SayCh <- fmt.Sprintf("%s\n%s", "*", msg) + //msg := ctcp.Encode(ctcp.ACTION, fmt.Sprintf(s)) + SayCh <- fmt.Sprintf("%s\n%s", "*", s) } diff --git a/modules/markov.go b/modules/markov.go index 8a5fa84..b592429 100644 --- a/modules/markov.go +++ b/modules/markov.go @@ -11,11 +11,11 @@ package modules import ( "bufio" "encoding/gob" + "flag" "fmt" "math/rand" "os" "regexp" - "strconv" "strings" "sync" "time" @@ -25,6 +25,14 @@ import ( "github.com/sorcix/irc" ) +var ( + markovPrefixLen = flag.Int("markov_prefix_len", 2, "markov: prefix len") + markovAnswerLen = flag.Int("markov_answer_len", 10, "markov: answer len") + markovResponseChance = flag.Int("markov_response_chance", 10, "markov: chance to get an answer (percent)") + markovStateFile = flag.String("markov_state_file", "state.dat", "markov: state file") + markovTrainFile = flag.String("markov_train_file", "train.txt", "markov: training file") +) + var markovChain *MarkovChain func init() { @@ -39,10 +47,8 @@ func markovHandleMessage(m *irc.Message) { } text = markovParseText(text) - answerLen, _ := strconv.Atoi(ModParams["markov-answer-len"]) - respChance, _ := strconv.Atoi(ModParams["markov-response-chance"]) - if rand.Intn(100) <= respChance || strings.Index(text, strings.ToLower(ModParams["_nick"])) != -1 { - responseText := markovChain.Generate(answerLen, text) + if rand.Intn(100) <= *markovResponseChance || strings.Index(text, strings.ToLower(ModParams["_nick"])) != -1 { + responseText := markovChain.Generate(*markovAnswerLen, text) if responseText != "" { go func() { time.Sleep(time.Duration(rand.Intn(8)+2) * time.Second) @@ -55,13 +61,12 @@ func markovHandleMessage(m *irc.Message) { } func markovRun() { - prefixLen, _ := strconv.Atoi(ModParams["markov-prefix-len"]) - markovChain = markovNewChain(prefixLen) - err := markovChain.Load(ModParams["markov-state-file"]) + markovChain = markovNewChain(*markovPrefixLen) + err := markovChain.Load(*markovStateFile) if err != nil { xlog.Error(err.Error()) } - filepath := ModParams["markov-import-file"] + filepath := *markovTrainFile if filepath != "-" { file, _ := os.Open(filepath) scanner := bufio.NewScanner(file) @@ -76,7 +81,7 @@ func markovRun() { go func() { for { time.Sleep(60 * time.Second) - markovChain.Save(ModParams["markov-state-file"]) + markovChain.Save(*markovStateFile) } }() } diff --git a/modules/quiz.go b/modules/quiz.go index 8b79ec0..c5b7c76 100644 --- a/modules/quiz.go +++ b/modules/quiz.go @@ -4,7 +4,6 @@ package modules import ( "bufio" - "flokatirc/util" "fmt" "math/rand" "os" @@ -12,6 +11,8 @@ import ( "strings" "time" + "code.dnix.de/an/flokatilib/util" + "github.com/sorcix/irc" "code.dnix.de/an/xlog" diff --git a/modules/sc.go b/modules/sc.go index cf506af..2992a52 100644 --- a/modules/sc.go +++ b/modules/sc.go @@ -15,7 +15,7 @@ import ( "code.dnix.de/an/xlog" - "flokatirc/util" + "code.dnix.de/an/flokatilib/util" "github.com/sorcix/irc" ) @@ -126,7 +126,7 @@ func scScraper() { } 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("*\nFleet: %s", util.NumberToString(fleet, '.')) SayCh <- fmt.Sprintf("*\nFunds: $ %s", util.NumberToString(funds, '.')) @@ -157,7 +157,7 @@ func showCitizen(handle string) { sid := reSid.FindStringSubmatch(string(body)) rank := reRank.FindStringSubmatch(string(body)) 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" + "URL: " + QUERY_CIT_URL + string(handle_[1]) SayCh <- "*\n" + "UEE #: " + string(record[1]) @@ -168,7 +168,7 @@ func showCitizen(handle string) { SayCh <- "*\n" + "Organization: " } } else { - SayCh <- "*\n" + "*** No Such Citizen ***" + SayCh <- "*\n" + "***No Such Citizen***" } } @@ -195,7 +195,7 @@ func showOrganization(handle string) { focus := reFocus.FindStringSubmatch(string(body)) comm := reComm.FindStringSubmatch(string(body)) if len(name) > 1 { - SayCh <- "*\n*** Organization Info ***" + 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]) @@ -203,6 +203,6 @@ func showOrganization(handle string) { SayCh <- "*\nCommitment: " + string(comm[1]) SayCh <- "*\nFocus: " + string(focus[1]) + ", " + string(focus[2]) } else { - SayCh <- "*\n*** No Such Organization ***" + SayCh <- "*\n***No Such Organization***" } } diff --git a/modules/twitch.go b/modules/twitch.go index e2d2f48..feade5f 100644 --- a/modules/twitch.go +++ b/modules/twitch.go @@ -16,7 +16,7 @@ import ( "code.dnix.de/an/xlog" - "flokatirc/util" + "code.dnix.de/an/flokatilib/util" "github.com/sorcix/irc" ) diff --git a/modules/weather.go b/modules/weather.go index a63486b..c2e2cd1 100644 --- a/modules/weather.go +++ b/modules/weather.go @@ -8,6 +8,7 @@ package modules import ( "encoding/json" + "flag" "fmt" "io/ioutil" "net/http" @@ -20,6 +21,10 @@ import ( "github.com/sorcix/irc" ) +var ( + weatherApiKey = flag.String("weather_api_key", "", "MOD: weather: api key") +) + var ( owmQueryAPIKey = "" owmQueryURLPrefix = "http://api.openweathermap.org/data/2.5/weather?q=" @@ -77,7 +82,7 @@ func init() { func weatherConfig() { time.Sleep(5 * time.Second) - owmQueryAPIKey = ModParams["weather-api-key"] + owmQueryAPIKey = weatherApiKey } func weatherHandleMessage(m *irc.Message) {