mirror of https://github.com/velour/catbase.git
Compare commits
1 Commits
4296d5109c
...
28beed6806
Author | SHA1 | Date |
---|---|---|
dependabot[bot] | 28beed6806 |
|
@ -93,9 +93,7 @@ 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)
|
||||||
snowflake := d.GetEmojySnowflake(args[1].(string))
|
err := d.client.MessageReactionAdd(args[0].(string), msg.ID, 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)
|
||||||
|
@ -215,25 +213,16 @@ func (d *Discord) GetEmojiList(force bool) map[string]string {
|
||||||
return emojis
|
return emojis
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Discord) GetEmojyID(name string) string {
|
func (d *Discord) GetEmojySnowflake(name string) string {
|
||||||
list := d.GetEmojiList(true)
|
list := d.GetEmojiList(true)
|
||||||
for k, v := range list {
|
for k, v := range list {
|
||||||
log.Debug().Str("k", k).Str("v", v).Str("name", name).Msg("emoj")
|
if name == v {
|
||||||
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 {
|
||||||
|
@ -385,7 +374,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.GetEmojyID(emojy)
|
emojyID := d.GetEmojySnowflake(emojy)
|
||||||
return d.client.GuildEmojiDelete(d.guildID, emojyID)
|
return d.client.GuildEmojiDelete(d.guildID, emojyID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.")
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ package emojifyme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -26,14 +26,13 @@ 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 := io.ReadAll(resp.Body)
|
body, err := ioutil.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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,22 +45,16 @@ 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] = 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{
|
ep := &EmojifyMePlugin{
|
||||||
Bot: b,
|
Bot: b,
|
||||||
GotBotEmoji: false,
|
GotBotEmoji: false,
|
||||||
Emoji: emojiMap,
|
Emoji: emojiMap,
|
||||||
}
|
}
|
||||||
b.RegisterRegex(ep, bot.Any, regexp.MustCompile(`.*`), ep.message)
|
b.RegisterRegex(ep, bot.Message, regexp.MustCompile(`.*`), ep.message)
|
||||||
return ep
|
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 {
|
if emojied > 0 && rand.Float64() <= p.Bot.Config().GetFloat64("Emojify.Chance", 0.02)*emojied {
|
||||||
for _, e := range emojys {
|
for _, e := range emojys {
|
||||||
log.Debug().
|
p.Bot.Send(c, bot.Reaction, message.Channel, e, message)
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.Any, IsCmd: false,
|
{Kind: bot.Message, 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) {
|
||||||
|
|
Loading…
Reference in New Issue