mirror of https://github.com/velour/catbase.git
Compare commits
No commits in common. "61cdb66546ebb5c9bfaeb7c15fcaf1e5324b6cb8" and "aa88ef44f5d043f5f9bcd282fe3f7676a51b2f3a" have entirely different histories.
61cdb66546
...
aa88ef44f5
2
go.mod
2
go.mod
|
@ -11,7 +11,6 @@ require (
|
|||
github.com/chrissexton/leftpad v0.0.0-20181207133115-1e93189d2fff
|
||||
github.com/chrissexton/sentiment v0.0.0-20190927141846-d69c422ba035
|
||||
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90
|
||||
github.com/forPelevin/gomoji v1.1.4
|
||||
github.com/go-chi/chi/v5 v5.0.7
|
||||
github.com/gocolly/colly v1.2.0
|
||||
github.com/google/uuid v1.3.0
|
||||
|
@ -68,7 +67,6 @@ require (
|
|||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d // indirect
|
||||
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
|
||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -46,8 +46,6 @@ github.com/dustin/gojson v0.0.0-20160307161227-2e71ec9dd5ad h1:Qk76DOWdOp+GlyDKB
|
|||
github.com/dustin/gojson v0.0.0-20160307161227-2e71ec9dd5ad/go.mod h1:mPKfmRa823oBIgl2r20LeMSpTAteW5j7FLkc0vjmzyQ=
|
||||
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90 h1:WXb3TSNmHp2vHoCroCIB1foO/yQ36swABL8aOVeDpgg=
|
||||
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
|
||||
github.com/forPelevin/gomoji v1.1.4 h1:mlxsZQgTO7v1qnpUUoS8kk0Lf/rEvxZYgYxuVUX7edg=
|
||||
github.com/forPelevin/gomoji v1.1.4/go.mod h1:ypB7Kz3Fsp+LVR7KoT7mEFOioYBuTuAtaAT4RGl+ASY=
|
||||
github.com/garyburd/go-oauth v0.0.0-20180319155456-bca2e7f09a17 h1:GOfMz6cRgTJ9jWV0qAezv642OhPnKEG7gtUjJSdStHE=
|
||||
github.com/garyburd/go-oauth v0.0.0-20180319155456-bca2e7f09a17/go.mod h1:HfkOCN6fkKKaPSAeNq/er3xObxTW4VLeY6UUK895gLQ=
|
||||
github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
|
||||
|
@ -136,8 +134,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
|||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d h1:1VUlQbCfkoSGv7qP7Y+ro3ap1P1pPZxgdGVqiTVy5C4=
|
||||
github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d/go.mod h1:xvqspoSXJTIpemEonrMDFq6XzwHYYgToXWj5eRX1OtY=
|
||||
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
package emojy
|
||||
|
||||
import (
|
||||
"github.com/forPelevin/gomoji"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/velour/catbase/bot"
|
||||
"github.com/velour/catbase/config"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -42,18 +38,6 @@ func (p *EmojyPlugin) setupDB() {
|
|||
|
||||
func (p *EmojyPlugin) register() {
|
||||
ht := bot.HandlerTable{
|
||||
{
|
||||
Kind: bot.Message, IsCmd: false,
|
||||
Regex: regexp.MustCompile(`.*`),
|
||||
Handler: func(request bot.Request) bool {
|
||||
r := regexp.MustCompile(`:[a-zA-Z0-9_-]+:`)
|
||||
for _, match := range r.FindAllString(request.Msg.Body, -1) {
|
||||
log.Debug().Msgf("Emojy detected: %s", match)
|
||||
p.recordReaction(match)
|
||||
}
|
||||
return false
|
||||
},
|
||||
},
|
||||
{
|
||||
Kind: bot.Reaction, IsCmd: false,
|
||||
Regex: regexp.MustCompile(`.*`),
|
||||
|
@ -84,58 +68,15 @@ type EmojyEntry struct {
|
|||
|
||||
type EmojyCount struct {
|
||||
Emojy string `json:"emojy"`
|
||||
URL string `json:"url"`
|
||||
Count int `json:"count"`
|
||||
OnServer bool `json:"onServer"`
|
||||
}
|
||||
|
||||
func invertEmojyList(emojy map[string]string) map[string]string {
|
||||
out := map[string]string{}
|
||||
for k, v := range emojy {
|
||||
out[v] = k
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (p *EmojyPlugin) allCounts() (map[string][]EmojyCount, error) {
|
||||
out := map[string][]EmojyCount{}
|
||||
onServerList := invertEmojyList(p.b.DefaultConnector().GetEmojiList())
|
||||
func (p *EmojyPlugin) allCounts() ([]EmojyCount, error) {
|
||||
q := `select emojy, count(observed) as count from emojyLog group by emojy order by count desc`
|
||||
result := []EmojyCount{}
|
||||
err := p.db.Select(&result, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, e := range result {
|
||||
_, e.OnServer = onServerList[e.Emojy]
|
||||
if isEmoji(e.Emojy) {
|
||||
out["emoji"] = append(out["emoji"], e)
|
||||
} else if ok, fname, _ := p.isKnownEmojy(e.Emojy); ok {
|
||||
e.URL = fname
|
||||
out["emojy"] = append(out["emojy"], e)
|
||||
} else {
|
||||
out["unknown"] = append(out["unknown"], e)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (p *EmojyPlugin) isKnownEmojy(name string) (bool, string, error) {
|
||||
emojyPath := p.c.Get("emojy.path", "emojy")
|
||||
baseURL := p.c.Get("emojy.baseURL", "/emojy/file")
|
||||
entries, err := os.ReadDir(emojyPath)
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
}
|
||||
for _, e := range entries {
|
||||
if !e.IsDir() && strings.HasPrefix(e.Name(), name) {
|
||||
url := path.Join(baseURL, e.Name())
|
||||
return true, url, nil
|
||||
}
|
||||
}
|
||||
return false, "", nil
|
||||
}
|
||||
|
||||
func isEmoji(in string) bool {
|
||||
return gomoji.ContainsEmoji(in)
|
||||
return result, nil
|
||||
}
|
||||
|
|
|
@ -34,21 +34,7 @@
|
|||
</b-alert>
|
||||
|
||||
<ul>
|
||||
<li v-for="(category, name) in results" key="name">
|
||||
{{name}}:
|
||||
<ul>
|
||||
<li v-for="emojy in category" key="emojy">
|
||||
{{emojy.count}} -
|
||||
<span v-if="name != 'emoji'">
|
||||
<span v-if="emojy.onServer">✅</span>
|
||||
<span v-else>❎</span>
|
||||
-
|
||||
</span>
|
||||
<img v-if="emojy.url" :src="emojy.url" :alt="emojy.name" class="img-thumbnail" style="max-width: 64px; max-height: 64px" />
|
||||
<span v-else>{{emojy.emojy}}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li v-for="emojy in results" key="Emojy">{{emojy.count}} - {{emojy.emojy}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -5,9 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/rs/zerolog/log"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path"
|
||||
)
|
||||
|
||||
//go:embed *.html
|
||||
|
@ -16,7 +14,6 @@ var embeddedFS embed.FS
|
|||
func (p *EmojyPlugin) registerWeb() {
|
||||
r := chi.NewRouter()
|
||||
r.HandleFunc("/all", p.handleAll)
|
||||
r.HandleFunc("/file/{name}", p.handleEmojy)
|
||||
r.HandleFunc("/", p.handleIndex)
|
||||
p.b.RegisterWebName(r, "/emojy", "Emojys")
|
||||
}
|
||||
|
@ -37,15 +34,3 @@ func (p *EmojyPlugin) handleAll(w http.ResponseWriter, r *http.Request) {
|
|||
out, _ := json.Marshal(emojy)
|
||||
w.Write(out)
|
||||
}
|
||||
|
||||
func (p *EmojyPlugin) handleEmojy(w http.ResponseWriter, r *http.Request) {
|
||||
fname := chi.URLParam(r, "name")
|
||||
emojyPath := p.c.Get("emojy.path", "emojy")
|
||||
contents, err := ioutil.ReadFile(path.Join(emojyPath, fname))
|
||||
if err != nil {
|
||||
w.WriteHeader(404)
|
||||
out, _ := json.Marshal(struct{ err error }{err})
|
||||
w.Write(out)
|
||||
}
|
||||
w.Write(contents)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue