automate management of loading emote
All checks were successful
Build only (for PRs) / build-only (pull_request) Successful in 4m52s
All checks were successful
Build only (for PRs) / build-only (pull_request) Successful in 4m52s
This commit is contained in:
BIN
app/assets/loading.webp
Normal file
BIN
app/assets/loading.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
@@ -371,6 +371,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
log.Println("Initialize loading emoji")
|
||||||
|
initLoadingEmoji(s)
|
||||||
|
|
||||||
|
|
||||||
log.Println("Adding commands")
|
log.Println("Adding commands")
|
||||||
registeredCommands := make([]*discordgo.ApplicationCommand, len(commands))
|
registeredCommands := make([]*discordgo.ApplicationCommand, len(commands))
|
||||||
for i, v := range commands {
|
for i, v := range commands {
|
||||||
|
|||||||
38
app/misc.go
38
app/misc.go
@@ -2,11 +2,45 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"log"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
_ "embed"
|
||||||
|
"encoding/base64"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var loading_emoji = os.Getenv("LOADING_EMOJI")
|
var loading_emoji string
|
||||||
|
|
||||||
|
//go:embed assets/loading.webp
|
||||||
|
var rawLoadingEmoji []byte
|
||||||
|
|
||||||
|
var loadingEmojiBase64 = func() string {
|
||||||
|
s := "data:image/webp;base64," + base64.StdEncoding.EncodeToString(rawLoadingEmoji)
|
||||||
|
rawLoadingEmoji = nil
|
||||||
|
return s
|
||||||
|
}()
|
||||||
|
|
||||||
|
func initLoadingEmoji(s *discordgo.Session) {
|
||||||
|
emojis, err := s.ApplicationEmojis(s.State.User.ID)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("Cannot get emojis")
|
||||||
|
}
|
||||||
|
for _, e := range emojis {
|
||||||
|
if e.Name == "loading" {
|
||||||
|
loading_emoji = fmt.Sprintf("<a:%s:%s>", e.Name, e.ID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e, err := s.ApplicationEmojiCreate(s.State.User.ID, &discordgo.EmojiParams{
|
||||||
|
Name: "loading",
|
||||||
|
Image: loadingEmojiBase64,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Panicf("Cannot create loading emoji: %s", err)
|
||||||
|
}
|
||||||
|
loading_emoji = fmt.Sprintf("<a:%s:%s>", e.Name, e.ID)
|
||||||
|
}
|
||||||
|
|
||||||
var urlPattern = regexp.MustCompile(`https?://\S+`)
|
var urlPattern = regexp.MustCompile(`https?://\S+`)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user