Compare commits

..

No commits in common. "f2153bf0b4b2fa8a103b6f039d5318d5668be56b" and "bfd50a346d5f67210a5a840594864d36443cbc3d" have entirely different histories.

1 changed files with 8 additions and 17 deletions

View File

@ -7,7 +7,6 @@ import (
"github.com/velour/catbase/bot/user" "github.com/velour/catbase/bot/user"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url"
"strconv" "strconv"
"time" "time"
@ -40,8 +39,8 @@ func (p *CounterPlugin) registerWeb() {
func (p *CounterPlugin) mkIncrementByNAPI(direction int) func(w http.ResponseWriter, r *http.Request) { func (p *CounterPlugin) mkIncrementByNAPI(direction int) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
userName, _ := url.QueryUnescape(chi.URLParam(r, "user")) userName := chi.URLParam(r, "user")
itemName, _ := url.QueryUnescape(chi.URLParam(r, "item")) itemName := chi.URLParam(r, "item")
delta, _ := strconv.Atoi(chi.URLParam(r, "delta")) delta, _ := strconv.Atoi(chi.URLParam(r, "delta"))
secret, pass, ok := r.BasicAuth() secret, pass, ok := r.BasicAuth()
@ -86,11 +85,7 @@ func (p *CounterPlugin) mkIncrementByNAPI(direction int) func(w http.ResponseWri
personalMsg = fmt.Sprintf("\nMessage: %s", inputMsg) personalMsg = fmt.Sprintf("\nMessage: %s", inputMsg)
} }
chs := p.cfg.GetMap("counter.channelItems", map[string]string{}) chs := p.cfg.GetArray("channels", []string{p.cfg.Get("channels", "none")})
ch, ok := chs[itemName]
if len(chs) == 0 || !ok {
return
}
req := &bot.Request{ req := &bot.Request{
Conn: p.b.DefaultConnector(), Conn: p.b.DefaultConnector(),
Kind: bot.Message, Kind: bot.Message,
@ -98,7 +93,7 @@ func (p *CounterPlugin) mkIncrementByNAPI(direction int) func(w http.ResponseWri
User: &u, User: &u,
// Noting here that we're only going to do goals in a "default" // Noting here that we're only going to do goals in a "default"
// channel even if it should send updates to others. // channel even if it should send updates to others.
Channel: ch, Channel: chs[0],
Body: fmt.Sprintf("%s += %d", itemName, delta), Body: fmt.Sprintf("%s += %d", itemName, delta),
Time: time.Now(), Time: time.Now(),
}, },
@ -119,8 +114,8 @@ func (p *CounterPlugin) mkIncrementByNAPI(direction int) func(w http.ResponseWri
func (p *CounterPlugin) mkIncrementAPI(delta int) func(w http.ResponseWriter, r *http.Request) { func (p *CounterPlugin) mkIncrementAPI(delta int) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
userName, _ := url.QueryUnescape(chi.URLParam(r, "user")) userName := chi.URLParam(r, "user")
itemName, _ := url.QueryUnescape(chi.URLParam(r, "item")) itemName := chi.URLParam(r, "item")
secret, pass, ok := r.BasicAuth() secret, pass, ok := r.BasicAuth()
if !ok || !p.b.CheckPassword(secret, pass) { if !ok || !p.b.CheckPassword(secret, pass) {
@ -164,11 +159,7 @@ func (p *CounterPlugin) mkIncrementAPI(delta int) func(w http.ResponseWriter, r
personalMsg = fmt.Sprintf("\nMessage: %s", inputMsg) personalMsg = fmt.Sprintf("\nMessage: %s", inputMsg)
} }
chs := p.cfg.GetMap("counter.channelItems", map[string]string{}) chs := p.cfg.GetArray("channels", []string{p.cfg.Get("channels", "none")})
ch, ok := chs[itemName]
if len(chs) == 0 || !ok {
return
}
req := &bot.Request{ req := &bot.Request{
Conn: p.b.DefaultConnector(), Conn: p.b.DefaultConnector(),
Kind: bot.Message, Kind: bot.Message,
@ -176,7 +167,7 @@ func (p *CounterPlugin) mkIncrementAPI(delta int) func(w http.ResponseWriter, r
User: &u, User: &u,
// Noting here that we're only going to do goals in a "default" // Noting here that we're only going to do goals in a "default"
// channel even if it should send updates to others. // channel even if it should send updates to others.
Channel: ch, Channel: chs[0],
Body: fmt.Sprintf("%s += %d", itemName, delta), Body: fmt.Sprintf("%s += %d", itemName, delta),
Time: time.Now(), Time: time.Now(),
}, },