modules/weather: new config flag for api key

This commit is contained in:
an 2017-06-25 12:03:49 +02:00
parent fa6081e5ec
commit b30ccd0171
6 changed files with 32 additions and 22 deletions

View File

@ -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)
}

View File

@ -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)
}
}()
}

View File

@ -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"

View File

@ -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])
@ -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])

View File

@ -16,7 +16,7 @@ import (
"code.dnix.de/an/xlog"
"flokatirc/util"
"code.dnix.de/an/flokatilib/util"
"github.com/sorcix/irc"
)

View File

@ -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) {