From 61cdb66546ebb5c9bfaeb7c15fcaf1e5324b6cb8 Mon Sep 17 00:00:00 2001 From: Chris Sexton <3216719+chrissexton@users.noreply.github.com> Date: Mon, 6 Jun 2022 10:47:11 -0400 Subject: [PATCH] emojy: indicate if an emojy is on the server --- plugins/emojy/emojy.go | 18 ++++++++++++++---- plugins/emojy/index.html | 5 +++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plugins/emojy/emojy.go b/plugins/emojy/emojy.go index 6843a85..8c4f50d 100644 --- a/plugins/emojy/emojy.go +++ b/plugins/emojy/emojy.go @@ -83,13 +83,23 @@ type EmojyEntry struct { } type EmojyCount struct { - Emojy string `json:"emojy"` - URL string `json:"url"` - Count int `json:"count"` + 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()) q := `select emojy, count(observed) as count from emojyLog group by emojy order by count desc` result := []EmojyCount{} err := p.db.Select(&result, q) @@ -97,8 +107,8 @@ func (p *EmojyPlugin) allCounts() (map[string][]EmojyCount, error) { 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 diff --git a/plugins/emojy/index.html b/plugins/emojy/index.html index cd46257..ed3b164 100644 --- a/plugins/emojy/index.html +++ b/plugins/emojy/index.html @@ -39,6 +39,11 @@