-
Notifications
You must be signed in to change notification settings - Fork 0
/
emojis.go
72 lines (57 loc) · 1.44 KB
/
emojis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"strings"
"github.com/RumbleFrog/discordgo"
"github.com/sahilm/fuzzy"
)
// Emojis is a slice
type Emojis []*discordgo.Emoji
type Emoji struct {
ID string
Name string
}
// String returns the fuzzy search part of the struct
func (e Emojis) String(i int) string {
return e[i].Name
}
// Len returns the length of the Emojis slice
func (e Emojis) Len() int {
return len(e)
}
// FuzzyRemoveDups fuzzy searches the list of emojis and returns the slice of results
func FuzzyRemoveDups(pattern string, emojis []*discordgo.Emoji) (nodups Emojis) {
_e := Emojis(emojis)
matches := fuzzy.FindFrom(pattern, _e)
for i := 0; i < len(matches)-1; i++ {
if strings.ToUpper(matches[i].Str) == strings.ToUpper(matches[i+1].Str) {
continue
}
nodups = append(nodups, emojis[matches[i].Index])
}
return
}
/* HTML STRUCTURE FOR AUTOSUGGESTION ENTRY
[div.autosuggestions]
| [img.emoji]
| TEXT
| [p.autosuggestion-subtitle]
*/
const EmojiSuggestionHTML = `
<div class="autosuggestion" id="%s">
<img class="autosuggestion-emoji emoji" src="https://cdn.discordapp.com/emojis/%d.png" />
%s
</div>
`
// ConstructAutocompletions builds the list of divs for emoji completion
// The maximum entry it will do is 8
func (e Emojis) ConstructAutocompletions() (html string) {
for i := 0; i < 8 && i < len(e); i++ {
emoji := e[i]
html += fmt.Sprintf(
EmojiSuggestionHTML,
emoji.MessageFormat(), emoji.ID, emoji.Name,
)
}
return
}