diff --git a/bot/bot.go b/bot/bot.go
index e66eda7..8674a34 100644
--- a/bot/bot.go
+++ b/bot/bot.go
@@ -138,8 +138,8 @@ var rootIndex = `
diff --git a/plugins/cli/index.go b/plugins/cli/index.go
index 09b4364..04b0be2 100644
--- a/plugins/cli/index.go
+++ b/plugins/cli/index.go
@@ -117,6 +117,8 @@ var indexHTML = `
},
send(evt) {
evt.preventDefault();
+ evt.stopPropagation()
+ this.input = "";
if (!this.authenticated) {
console.log("User is a bot.");
this.err = "User appears to be a bot.";
diff --git a/plugins/counter/html.go b/plugins/counter/html.go
index dca3964..3dd9b3a 100644
--- a/plugins/counter/html.go
+++ b/plugins/counter/html.go
@@ -14,6 +14,7 @@ var html = `
+
Counters
diff --git a/plugins/fact/factoid.go b/plugins/fact/factoid.go
index eec9156..452fcc0 100644
--- a/plugins/fact/factoid.go
+++ b/plugins/fact/factoid.go
@@ -4,6 +4,7 @@ package fact
import (
"database/sql"
+ "encoding/json"
"fmt"
"html/template"
"math/rand"
@@ -759,6 +760,7 @@ func (p *FactoidPlugin) factTimer(c bot.Connector, channel string) {
// Register any web URLs desired
func (p *FactoidPlugin) registerWeb() {
+ http.HandleFunc("/factoid/api", p.serveAPI)
http.HandleFunc("/factoid/req", p.serveQuery)
http.HandleFunc("/factoid", p.serveQuery)
p.Bot.RegisterWeb("/factoid", "Factoid")
@@ -773,28 +775,38 @@ func linkify(text string) template.HTML {
}
return template.HTML(strings.Join(parts, " "))
}
+func (p *FactoidPlugin) serveAPI(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodPost {
+ fmt.Fprintf(w, "Incorrect HTTP method")
+ return
+ }
+ info := struct {
+ Query string `json:"query"`
+ }{}
+ decoder := json.NewDecoder(r.Body)
+ err := decoder.Decode(&info)
+ if err != nil {
+ w.WriteHeader(500)
+ fmt.Fprint(w, err)
+ return
+ }
+
+ entries, err := getFacts(p.db, info.Query, "")
+ if err != nil {
+ w.WriteHeader(500)
+ fmt.Fprint(w, err)
+ return
+ }
+
+ data, err := json.Marshal(entries)
+ if err != nil {
+ w.WriteHeader(500)
+ fmt.Fprint(w, err)
+ return
+ }
+ w.Write(data)
+}
func (p *FactoidPlugin) serveQuery(w http.ResponseWriter, r *http.Request) {
- context := make(map[string]interface{})
- funcMap := template.FuncMap{
- // The name "title" is what the function will be called in the template text.
- "linkify": linkify,
- }
- if e := r.FormValue("entry"); e != "" {
- entries, err := getFacts(p.db, e, "")
- if err != nil {
- log.Error().Err(err).Msg("Web error searching")
- }
- context["Count"] = fmt.Sprintf("%d", len(entries))
- context["Entries"] = entries
- context["Search"] = e
- }
- t, err := template.New("factoidIndex").Funcs(funcMap).Parse(factoidIndex)
- if err != nil {
- log.Error().Err(err)
- }
- err = t.Execute(w, context)
- if err != nil {
- log.Error().Err(err)
- }
+ fmt.Fprint(w, factoidIndex)
}
diff --git a/plugins/fact/webTemplates.go b/plugins/fact/webTemplates.go
index 0c0c7b7..c890664 100644
--- a/plugins/fact/webTemplates.go
+++ b/plugins/fact/webTemplates.go
@@ -9,104 +9,101 @@ package fact
var factoidIndex = `
-
+
-
Factoids
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
Factoids
-
-
-
+
-
-
-
- {{if .Error}}
- {{.Error}}
- {{end}}
-
- {{if .Count}}
- Found {{.Count}} entries.
- {{end}}
-
-
- {{if .Entries}}
-
-
-
-
- Trigger |
- Full Text |
- Author |
- # Hits |
-
-
-
-
- {{range .Entries}}
-
- {{linkify .Fact}} |
- {{linkify .Tidbit}} |
- {{linkify .Owner}} |
- {{.Count}} |
-
- {{end}}
-
-
-
- {{end}}
-
-
+
+
Factoids
+
+ {{ err }}
+
+
+
+
+
+
+
+
+ Search
+
+
+
+
+
+
+
+
+
+
+
+
`