still trying to get get-emoji to work
This commit is contained in:
22
cmd_cat.go
22
cmd_cat.go
@@ -28,7 +28,7 @@ var cmd_cat = Command{
|
|||||||
cat, err := GetCatImageURL()
|
cat, err := GetCatImageURL()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = e.CreateMessage(discord.NewMessageCreateBuilder().
|
err = e.CreateMessage(discord.NewMessageCreateBuilder().
|
||||||
AddEmbeds(discord.NewEmbedBuilder().SetImage(cat).SetColor(hexToDecimal(color["primary"])).Build()).
|
AddEmbeds(discord.NewEmbedBuilder().SetDescription(cat.Fact).SetImage(cat.Image).SetColor(hexToDecimal(color["primary"])).Build()).
|
||||||
Build())
|
Build())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
@@ -37,22 +37,22 @@ var cmd_cat = Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type CatImage struct {
|
type Cat struct {
|
||||||
ID string `json:"_id"`
|
Image string `json:"image"`
|
||||||
|
Fact string `json:"fact"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCatImageURL() (string, error) {
|
func GetCatImageURL() (Cat, error) {
|
||||||
resp, err := http.Get("https://cataas.com/cat?json=true")
|
resp, err := http.Get("https://some-random-api.com/animal/cat")
|
||||||
|
var cat Cat
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return cat, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return cat, err
|
||||||
}
|
}
|
||||||
var images CatImage
|
err = json.Unmarshal(body, &cat)
|
||||||
err = json.Unmarshal(body, &images)
|
return cat, err
|
||||||
|
|
||||||
return "https://cataas.com/cat/" + images.ID, err
|
|
||||||
}
|
}
|
||||||
|
89
cmd_getemoji.go
Normal file
89
cmd_getemoji.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/disgoorg/disgo/discord"
|
||||||
|
"github.com/disgoorg/disgo/events"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
var cmd_getemoji Command = Command{
|
||||||
|
Definition: discord.SlashCommandCreate{
|
||||||
|
Name: "add-emoji",
|
||||||
|
Description: "Add an external emoji directly to the server.",
|
||||||
|
Options: []discord.ApplicationCommandOption{
|
||||||
|
&discord.ApplicationCommandOptionString{
|
||||||
|
Name: "emoji",
|
||||||
|
Description: "The emoji you want to add",
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Interact: func(e *events.ApplicationCommandInteractionCreate) {
|
||||||
|
emojiRegex := regexp.MustCompile(`<(.+):(\d+)>`)
|
||||||
|
emojistring := emojiRegex.FindString(e.SlashCommandInteractionData().String("emoji"))
|
||||||
|
logrus.Debug(emojistring)
|
||||||
|
emojiArray := strings.Split(emojistring, ":")
|
||||||
|
logrus.Debug(emojiArray)
|
||||||
|
var emojiName string
|
||||||
|
var emojiID string
|
||||||
|
var emojiFileName string
|
||||||
|
if len(emojiArray) > 1 {
|
||||||
|
emojiName = strings.TrimSuffix(emojiArray[1], ">")
|
||||||
|
emojiID = strings.TrimSuffix(emojiArray[2], ">")
|
||||||
|
}
|
||||||
|
imageType, emojiRead := getEmoji(emojiID)
|
||||||
|
emojiData, err := io.ReadAll(emojiRead)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
|
_, err = e.Client().Rest().CreateEmoji(*e.GuildID(), discord.EmojiCreate{
|
||||||
|
Name: emojiName,
|
||||||
|
Image: discord.Icon{
|
||||||
|
Type: imageType,
|
||||||
|
Data: emojiData,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
|
if imageType == discord.IconTypeGIF {
|
||||||
|
emojiFileName = emojiName + ".gif"
|
||||||
|
} else {
|
||||||
|
emojiFileName = emojiName + ".png"
|
||||||
|
}
|
||||||
|
err = e.CreateMessage(discord.NewMessageCreateBuilder().
|
||||||
|
SetContentf("Emoji %s sucessfully added to this server!", emojiName).SetFiles(discord.NewFile(emojiFileName, "The emoji that was picked", emojiRead)).SetEphemeral(true).
|
||||||
|
Build())
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEmoji(emojiID string) (discord.IconType, io.Reader) {
|
||||||
|
resp, err := http.Get("https://cdn.discordapp.com/emojis/" + emojiID)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
return discord.IconTypePNG, nil
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
imageData, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
return discord.IconTypePNG, nil
|
||||||
|
}
|
||||||
|
isAnimated := isGIFImage(imageData)
|
||||||
|
if isAnimated {
|
||||||
|
logrus.Debug("GIF")
|
||||||
|
return discord.IconTypeGIF, bytes.NewReader(imageData)
|
||||||
|
} else {
|
||||||
|
logrus.Debug("PNG")
|
||||||
|
return discord.IconTypePNG, bytes.NewReader(imageData)
|
||||||
|
}
|
||||||
|
}
|
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module github.com/vaporvee/acecore
|
|||||||
go 1.21.6
|
go 1.21.6
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/disgoorg/disgo v0.18.1-0.20240408224120-2676e29d6e86
|
github.com/disgoorg/disgo v0.18.1
|
||||||
github.com/disgoorg/json v1.1.0
|
github.com/disgoorg/json v1.1.0
|
||||||
github.com/disgoorg/snowflake/v2 v2.0.1
|
github.com/disgoorg/snowflake/v2 v2.0.1
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
|
12
go.sum
12
go.sum
@@ -1,12 +1,10 @@
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/disgoorg/disgo v0.17.2 h1:RxiLq8guMtk+9tArFwve02iya2APQ9yZVtV30ySKNtw=
|
|
||||||
github.com/disgoorg/disgo v0.17.2/go.mod h1:8r3h9fXSz7BbACxLPsPbtB6LX8gaQFUETgPKV/0gAKQ=
|
|
||||||
github.com/disgoorg/disgo v0.18.0 h1:EviKy/OiGofYW2X4kLjgxAUYrqjmBEMpVp/MMXHP1pY=
|
|
||||||
github.com/disgoorg/disgo v0.18.0/go.mod h1:gkl6DBdbKUvmOOJayWPSvS52KPN/8uJGJ2f13gCEB1o=
|
|
||||||
github.com/disgoorg/disgo v0.18.1-0.20240408224120-2676e29d6e86 h1:hSRIjnKWL07TYxvZRxdSBpS78gJNf+JkAuzXY3O1Kos=
|
github.com/disgoorg/disgo v0.18.1-0.20240408224120-2676e29d6e86 h1:hSRIjnKWL07TYxvZRxdSBpS78gJNf+JkAuzXY3O1Kos=
|
||||||
github.com/disgoorg/disgo v0.18.1-0.20240408224120-2676e29d6e86/go.mod h1:gkl6DBdbKUvmOOJayWPSvS52KPN/8uJGJ2f13gCEB1o=
|
github.com/disgoorg/disgo v0.18.1-0.20240408224120-2676e29d6e86/go.mod h1:gkl6DBdbKUvmOOJayWPSvS52KPN/8uJGJ2f13gCEB1o=
|
||||||
|
github.com/disgoorg/disgo v0.18.1 h1:8g3ifRVlbdZ28bX2BAVkb04dvQnnRMwN89KUkclaniw=
|
||||||
|
github.com/disgoorg/disgo v0.18.1/go.mod h1:gkl6DBdbKUvmOOJayWPSvS52KPN/8uJGJ2f13gCEB1o=
|
||||||
github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys=
|
github.com/disgoorg/json v1.1.0 h1:7xigHvomlVA9PQw9bMGO02PHGJJPqvX5AnwlYg/Tnys=
|
||||||
github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
|
github.com/disgoorg/json v1.1.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
|
||||||
github.com/disgoorg/snowflake/v2 v2.0.1 h1:CuUxGLwggUxEswZOmZ+mZ5i0xSumQdXW9tXW7uGqe+0=
|
github.com/disgoorg/snowflake/v2 v2.0.1 h1:CuUxGLwggUxEswZOmZ+mZ5i0xSumQdXW9tXW7uGqe+0=
|
||||||
@@ -29,17 +27,11 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
|||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
|
|
||||||
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
|
|
||||||
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
|
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
|
||||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||||
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
|
|
||||||
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
|
|
||||||
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
||||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
|
|
||||||
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
||||||
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
|
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
|
||||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
@@ -25,7 +25,7 @@ type Command struct {
|
|||||||
DynamicComponentIDs func() []string
|
DynamicComponentIDs func() []string
|
||||||
}
|
}
|
||||||
|
|
||||||
var commands []Command = []Command{cmd_tag, cmd_tag_short, context_tag, cmd_sticky, context_sticky, cmd_ping, cmd_userinfo, cmd_form, cmd_ask, cmd_cat, cmd_dadjoke, cmd_ticket_form, cmd_autopublish, cmd_autojoinroles}
|
var commands []Command = []Command{cmd_tag, cmd_tag_short, context_tag, cmd_sticky, context_sticky, cmd_ping, cmd_userinfo, cmd_getemoji, cmd_form, cmd_ask, cmd_cat, cmd_dadjoke, cmd_ticket_form, cmd_autopublish, cmd_autojoinroles}
|
||||||
|
|
||||||
func ready(e *events.Ready) {
|
func ready(e *events.Ready) {
|
||||||
logrus.Info("Starting up...")
|
logrus.Info("Starting up...")
|
||||||
|
1
main.go
1
main.go
@@ -39,6 +39,7 @@ func main() {
|
|||||||
bot.WithGatewayConfigOpts(
|
bot.WithGatewayConfigOpts(
|
||||||
gateway.WithIntents(
|
gateway.WithIntents(
|
||||||
gateway.IntentGuilds,
|
gateway.IntentGuilds,
|
||||||
|
gateway.IntentGuildEmojisAndStickers,
|
||||||
gateway.IntentGuildMessages,
|
gateway.IntentGuildMessages,
|
||||||
gateway.IntentGuildMembers,
|
gateway.IntentGuildMembers,
|
||||||
gateway.IntentDirectMessages,
|
gateway.IntentDirectMessages,
|
||||||
|
15
tool.go
15
tool.go
@@ -201,3 +201,18 @@ func isIDRole(c bot.Client, guildID snowflake.ID, id snowflake.ID) bool {
|
|||||||
logrus.Error(err2)
|
logrus.Error(err2)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isGIFImage(imageData []byte) bool {
|
||||||
|
if len(imageData) < 6 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// Check for the GIF89a header at the beginning of the byte array
|
||||||
|
if string(imageData[0:6]) == "GIF89a" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Check for the GIF87a header at the beginning of the byte array
|
||||||
|
if string(imageData[0:6]) == "GIF87a" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user