mirror of https://github.com/velour/catbase.git
emojifyme: fix it
This commit is contained in:
parent
8823159490
commit
e7acd4730c
|
@ -93,7 +93,9 @@ func (d Discord) Send(kind bot.Kind, args ...any) (string, error) {
|
||||||
return d.sendMessage(args[0].(string), msg, false, args...)
|
return d.sendMessage(args[0].(string), msg, false, args...)
|
||||||
case bot.Reaction:
|
case bot.Reaction:
|
||||||
msg := args[2].(msg.Message)
|
msg := args[2].(msg.Message)
|
||||||
err := d.client.MessageReactionAdd(args[0].(string), msg.ID, args[1].(string))
|
snowflake := d.GetEmojySnowflake(args[1].(string))
|
||||||
|
log.Debug().Str("snowflake", snowflake).Msg("bot.Send")
|
||||||
|
err := d.client.MessageReactionAdd(args[0].(string), msg.ID, snowflake)
|
||||||
return args[1].(string), err
|
return args[1].(string), err
|
||||||
case bot.Delete:
|
case bot.Delete:
|
||||||
ch := args[0].(string)
|
ch := args[0].(string)
|
||||||
|
@ -213,16 +215,25 @@ func (d *Discord) GetEmojiList(force bool) map[string]string {
|
||||||
return emojis
|
return emojis
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Discord) GetEmojySnowflake(name string) string {
|
func (d *Discord) GetEmojyID(name string) string {
|
||||||
list := d.GetEmojiList(true)
|
list := d.GetEmojiList(true)
|
||||||
for k, v := range list {
|
for k, v := range list {
|
||||||
if name == v {
|
log.Debug().Str("k", k).Str("v", v).Str("name", name).Msg("emoj")
|
||||||
|
if strings.Contains(name, v) {
|
||||||
return k
|
return k
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Discord) GetEmojySnowflake(name string) string {
|
||||||
|
id := d.GetEmojyID(name)
|
||||||
|
if id != name {
|
||||||
|
return name + ":" + id
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
// Who gets the users in the guild
|
// Who gets the users in the guild
|
||||||
// Note that the channel ID does not matter in this particular case
|
// Note that the channel ID does not matter in this particular case
|
||||||
func (d *Discord) Who(id string) []string {
|
func (d *Discord) Who(id string) []string {
|
||||||
|
@ -374,7 +385,7 @@ func (d *Discord) UploadEmojy(emojy, path string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Discord) DeleteEmojy(emojy string) error {
|
func (d *Discord) DeleteEmojy(emojy string) error {
|
||||||
emojyID := d.GetEmojySnowflake(emojy)
|
emojyID := d.GetEmojyID(emojy)
|
||||||
return d.client.GuildEmojiDelete(d.guildID, emojyID)
|
return d.client.GuildEmojiDelete(d.guildID, emojyID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ package emojifyme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -26,13 +26,14 @@ func New(b bot.Bot) *EmojifyMePlugin {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("Error generic emoji list")
|
log.Fatal().Err(err).Msg("Error generic emoji list")
|
||||||
}
|
}
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("Error generic emoji list body")
|
log.Fatal().Err(err).Msg("Error generic emoji list body")
|
||||||
}
|
}
|
||||||
|
|
||||||
type Emoji struct {
|
type Emoji struct {
|
||||||
|
Emoji string `json:"emoji"`
|
||||||
Aliases []string `json:"aliases"`
|
Aliases []string `json:"aliases"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,16 +46,22 @@ func New(b bot.Bot) *EmojifyMePlugin {
|
||||||
emojiMap := map[string]string{}
|
emojiMap := map[string]string{}
|
||||||
for _, e := range emoji {
|
for _, e := range emoji {
|
||||||
for _, alias := range e.Aliases {
|
for _, alias := range e.Aliases {
|
||||||
emojiMap[alias] = alias
|
emojiMap[alias] = e.Emoji
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emojy := b.GetEmojiList(true)
|
||||||
|
log.Debug().Interface("emojyList", emojy).Msg("startup")
|
||||||
|
for _, v := range emojy {
|
||||||
|
emojiMap[v] = v
|
||||||
|
}
|
||||||
|
|
||||||
ep := &EmojifyMePlugin{
|
ep := &EmojifyMePlugin{
|
||||||
Bot: b,
|
Bot: b,
|
||||||
GotBotEmoji: false,
|
GotBotEmoji: false,
|
||||||
Emoji: emojiMap,
|
Emoji: emojiMap,
|
||||||
}
|
}
|
||||||
b.RegisterRegex(ep, bot.Message, regexp.MustCompile(`.*`), ep.message)
|
b.RegisterRegex(ep, bot.Any, regexp.MustCompile(`.*`), ep.message)
|
||||||
return ep
|
return ep
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +102,13 @@ func (p *EmojifyMePlugin) message(r bot.Request) bool {
|
||||||
|
|
||||||
if emojied > 0 && rand.Float64() <= p.Bot.Config().GetFloat64("Emojify.Chance", 0.02)*emojied {
|
if emojied > 0 && rand.Float64() <= p.Bot.Config().GetFloat64("Emojify.Chance", 0.02)*emojied {
|
||||||
for _, e := range emojys {
|
for _, e := range emojys {
|
||||||
p.Bot.Send(c, bot.Reaction, message.Channel, e, message)
|
log.Debug().
|
||||||
|
Str("emojy", e).
|
||||||
|
Msgf("trying to react")
|
||||||
|
_, err := p.Bot.Send(c, bot.Reaction, message.Channel, e, message)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Msgf("emojy react error: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue