Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot] ecaf81509f
Merge 07478d469f into a187ea363c 2024-04-01 06:22:05 +00:00
4 changed files with 10 additions and 35 deletions

View File

@ -93,9 +93,7 @@ func (d Discord) Send(kind bot.Kind, args ...any) (string, error) {
return d.sendMessage(args[0].(string), msg, false, args...)
case bot.Reaction:
msg := args[2].(msg.Message)
snowflake := d.GetEmojySnowflake(args[1].(string))
log.Debug().Str("snowflake", snowflake).Msg("bot.Send")
err := d.client.MessageReactionAdd(args[0].(string), msg.ID, snowflake)
err := d.client.MessageReactionAdd(args[0].(string), msg.ID, args[1].(string))
return args[1].(string), err
case bot.Delete:
ch := args[0].(string)
@ -215,25 +213,16 @@ func (d *Discord) GetEmojiList(force bool) map[string]string {
return emojis
}
func (d *Discord) GetEmojyID(name string) string {
func (d *Discord) GetEmojySnowflake(name string) string {
list := d.GetEmojiList(true)
for k, v := range list {
log.Debug().Str("k", k).Str("v", v).Str("name", name).Msg("emoj")
if strings.Contains(name, v) {
if name == v {
return k
}
}
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
// Note that the channel ID does not matter in this particular case
func (d *Discord) Who(id string) []string {
@ -385,7 +374,7 @@ func (d *Discord) UploadEmojy(emojy, path string) error {
}
func (d *Discord) DeleteEmojy(emojy string) error {
emojyID := d.GetEmojyID(emojy)
emojyID := d.GetEmojySnowflake(emojy)
return d.client.GuildEmojiDelete(d.guildID, emojyID)
}

View File

@ -420,7 +420,6 @@ func (p *AdminPlugin) setNick(r bot.Request) bool {
p.bot.Send(r.Conn, bot.Message, r.Msg.Channel, "I can't seem to set a new nick.")
return true
}
p.cfg.Set("nick", nick)
p.bot.Send(r.Conn, bot.Message, r.Msg.Channel, fmt.Sprintf("I shall now be known as %s.", nick))
return true
}

View File

@ -4,7 +4,7 @@ package emojifyme
import (
"encoding/json"
"io"
"io/ioutil"
"math/rand"
"net/http"
"regexp"
@ -26,14 +26,13 @@ func New(b bot.Bot) *EmojifyMePlugin {
if err != nil {
log.Fatal().Err(err).Msg("Error generic emoji list")
}
body, err := io.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
log.Fatal().Err(err).Msg("Error generic emoji list body")
}
type Emoji struct {
Emoji string `json:"emoji"`
Aliases []string `json:"aliases"`
}
@ -46,22 +45,16 @@ func New(b bot.Bot) *EmojifyMePlugin {
emojiMap := map[string]string{}
for _, e := range emoji {
for _, alias := range e.Aliases {
emojiMap[alias] = e.Emoji
emojiMap[alias] = alias
}
}
emojy := b.GetEmojiList(true)
log.Debug().Interface("emojyList", emojy).Msg("startup")
for _, v := range emojy {
emojiMap[v] = v
}
ep := &EmojifyMePlugin{
Bot: b,
GotBotEmoji: false,
Emoji: emojiMap,
}
b.RegisterRegex(ep, bot.Any, regexp.MustCompile(`.*`), ep.message)
b.RegisterRegex(ep, bot.Message, regexp.MustCompile(`.*`), ep.message)
return ep
}
@ -102,13 +95,7 @@ func (p *EmojifyMePlugin) message(r bot.Request) bool {
if emojied > 0 && rand.Float64() <= p.Bot.Config().GetFloat64("Emojify.Chance", 0.02)*emojied {
for _, e := range emojys {
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)
}
p.Bot.Send(c, bot.Reaction, message.Channel, e, message)
}
return false
}

View File

@ -214,7 +214,7 @@ func (p *FirstPlugin) register() {
fmt.Sprintf("Deleted first entry: '%s' and set a random timer for when first will happen next.", fe.body))
return true
}},
{Kind: bot.Any, IsCmd: false,
{Kind: bot.Message, IsCmd: false,
Regex: regexp.MustCompile(`.*`),
Handler: func(r bot.Request) bool {
if r.Msg.IsIM || !p.enabled || !p.enabled_channel(r) {