modules/weather: new config flag for api key
This commit is contained in:
parent
fa6081e5ec
commit
b30ccd0171
|
@ -13,7 +13,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sorcix/irc"
|
"github.com/sorcix/irc"
|
||||||
"github.com/sorcix/irc/ctcp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Receivers struct {
|
type Receivers struct {
|
||||||
|
@ -102,6 +101,6 @@ func (r *Receivers) addNames(newNames []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func printAction(s string) {
|
func printAction(s string) {
|
||||||
msg := ctcp.Encode(ctcp.ACTION, fmt.Sprintf(s))
|
//msg := ctcp.Encode(ctcp.ACTION, fmt.Sprintf(s))
|
||||||
SayCh <- fmt.Sprintf("%s\n%s", "*", msg)
|
SayCh <- fmt.Sprintf("%s\n%s", "*", s)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,11 @@ package modules
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -25,6 +25,14 @@ import (
|
||||||
"github.com/sorcix/irc"
|
"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
|
var markovChain *MarkovChain
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -39,10 +47,8 @@ func markovHandleMessage(m *irc.Message) {
|
||||||
}
|
}
|
||||||
text = markovParseText(text)
|
text = markovParseText(text)
|
||||||
|
|
||||||
answerLen, _ := strconv.Atoi(ModParams["markov-answer-len"])
|
if rand.Intn(100) <= *markovResponseChance || strings.Index(text, strings.ToLower(ModParams["_nick"])) != -1 {
|
||||||
respChance, _ := strconv.Atoi(ModParams["markov-response-chance"])
|
responseText := markovChain.Generate(*markovAnswerLen, text)
|
||||||
if rand.Intn(100) <= respChance || strings.Index(text, strings.ToLower(ModParams["_nick"])) != -1 {
|
|
||||||
responseText := markovChain.Generate(answerLen, text)
|
|
||||||
if responseText != "" {
|
if responseText != "" {
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Duration(rand.Intn(8)+2) * time.Second)
|
time.Sleep(time.Duration(rand.Intn(8)+2) * time.Second)
|
||||||
|
@ -55,13 +61,12 @@ func markovHandleMessage(m *irc.Message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func markovRun() {
|
func markovRun() {
|
||||||
prefixLen, _ := strconv.Atoi(ModParams["markov-prefix-len"])
|
markovChain = markovNewChain(*markovPrefixLen)
|
||||||
markovChain = markovNewChain(prefixLen)
|
err := markovChain.Load(*markovStateFile)
|
||||||
err := markovChain.Load(ModParams["markov-state-file"])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
xlog.Error(err.Error())
|
xlog.Error(err.Error())
|
||||||
}
|
}
|
||||||
filepath := ModParams["markov-import-file"]
|
filepath := *markovTrainFile
|
||||||
if filepath != "-" {
|
if filepath != "-" {
|
||||||
file, _ := os.Open(filepath)
|
file, _ := os.Open(filepath)
|
||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
|
@ -76,7 +81,7 @@ func markovRun() {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(60 * time.Second)
|
time.Sleep(60 * time.Second)
|
||||||
markovChain.Save(ModParams["markov-state-file"])
|
markovChain.Save(*markovStateFile)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"flokatirc/util"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
@ -12,6 +11,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.dnix.de/an/flokatilib/util"
|
||||||
|
|
||||||
"github.com/sorcix/irc"
|
"github.com/sorcix/irc"
|
||||||
|
|
||||||
"code.dnix.de/an/xlog"
|
"code.dnix.de/an/xlog"
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
|
|
||||||
"code.dnix.de/an/xlog"
|
"code.dnix.de/an/xlog"
|
||||||
|
|
||||||
"flokatirc/util"
|
"code.dnix.de/an/flokatilib/util"
|
||||||
|
|
||||||
"github.com/sorcix/irc"
|
"github.com/sorcix/irc"
|
||||||
)
|
)
|
||||||
|
@ -126,7 +126,7 @@ 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, '.'))
|
||||||
|
@ -157,7 +157,7 @@ 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])
|
||||||
|
@ -195,7 +195,7 @@ 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])
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
|
|
||||||
"code.dnix.de/an/xlog"
|
"code.dnix.de/an/xlog"
|
||||||
|
|
||||||
"flokatirc/util"
|
"code.dnix.de/an/flokatilib/util"
|
||||||
|
|
||||||
"github.com/sorcix/irc"
|
"github.com/sorcix/irc"
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,6 +8,7 @@ package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -20,6 +21,10 @@ import (
|
||||||
"github.com/sorcix/irc"
|
"github.com/sorcix/irc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
weatherApiKey = flag.String("weather_api_key", "", "MOD: weather: api key")
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
owmQueryAPIKey = ""
|
owmQueryAPIKey = ""
|
||||||
owmQueryURLPrefix = "http://api.openweathermap.org/data/2.5/weather?q="
|
owmQueryURLPrefix = "http://api.openweathermap.org/data/2.5/weather?q="
|
||||||
|
@ -77,7 +82,7 @@ func init() {
|
||||||
|
|
||||||
func weatherConfig() {
|
func weatherConfig() {
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
owmQueryAPIKey = ModParams["weather-api-key"]
|
owmQueryAPIKey = weatherApiKey
|
||||||
}
|
}
|
||||||
|
|
||||||
func weatherHandleMessage(m *irc.Message) {
|
func weatherHandleMessage(m *irc.Message) {
|
||||||
|
|
Loading…
Reference in New Issue