Compare commits

...

6 Commits

Author SHA1 Message Date
dependabot[bot] 4296d5109c
Merge 1bf66e58bc into efc4605f39 2024-05-08 17:15:51 +00:00
Chris Sexton efc4605f39 Revert "config: use Charm KV as backing for config KV entries"
This reverts commit d6aa94d5df.
2024-05-08 13:15:47 -04:00
Chris Sexton d6aa94d5df config: use Charm KV as backing for config KV entries 2024-05-06 21:52:54 -04:00
Chris Sexton f207117b28 admin: set nick config as well 2024-04-19 13:44:10 -04:00
Chris Sexton e7acd4730c emojifyme: fix it 2024-04-19 13:36:47 -04:00
Chris Sexton 8823159490 first: fix message type 2024-04-19 13:36:47 -04:00
4 changed files with 35 additions and 10 deletions

View File

@ -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)
} }

View File

@ -420,6 +420,7 @@ 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.") p.bot.Send(r.Conn, bot.Message, r.Msg.Channel, "I can't seem to set a new nick.")
return true 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)) p.bot.Send(r.Conn, bot.Message, r.Msg.Channel, fmt.Sprintf("I shall now be known as %s.", nick))
return true return true
} }

View File

@ -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
} }

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