Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions emoji/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,3 @@
This directory contains all the emoji used by the Boost Bot application. The emoji are used to represent the various types of activities that can be performed in the application.

The emoji are in PNG or animated GIF format.

## Backup pull utility

This directory contains a utility that can be used to pull the emoji from the Boost Bot application and store them in this directory. This utility is useful for backing up the emoji in case they are lost or need to be restored.

The full list of emoji can be found in the botemoji.txt file. This file contains the emoji name and the URL of the emoji image.

The utility getemoji.sh will read the botemoji.txt file and download the emoji images to this directory.
86 changes: 0 additions & 86 deletions emoji/botemoji.txt

This file was deleted.

23 changes: 0 additions & 23 deletions emoji/getemoji.sh

This file was deleted.

Binary file added emoji/st_Li1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added emoji/st_Li2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added emoji/st_Li3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added emoji/st_Li4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
55 changes: 9 additions & 46 deletions src/bottools/app_emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
return EnsureEmojiFromLocalRepo(s, name)
})

EmoteMapNew := make(map[string]ei.Emotes)

Check failure on line 54 in src/bottools/app_emoji.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to EmoteMapNew (ineffassign)

Check failure on line 54 in src/bottools/app_emoji.go

View workflow job for this annotation

GitHub Actions / audit

this value of EmoteMapNew is never used (SA4006)

Check failure on line 54 in src/bottools/app_emoji.go

View workflow job for this annotation

GitHub Actions / audit

this value of EmoteMapNew is never used (SA4006)

Check failure on line 54 in src/bottools/app_emoji.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to EmoteMapNew (ineffassign)

fileInfo, err := os.Stat(emoteFilePath)
if force || err != nil {
Expand Down Expand Up @@ -106,17 +106,13 @@
}
}

// If still missing after Discord fetch, look up image in local emoji/ directory
emojiPath, ok := findLocalEmojiPath(emojiName)
if !ok {
// Download missing emoji file directly from GitHub repository into emoji/ folder
downloadedPath, downloaded := downloadMissingEmojiFromGit(emojiName)
if downloaded {
emojiPath = downloadedPath
ok = true
}
// If running on dev bot, do not read or import missing emojis from local emoji/ directory
if config.IsDevBot() {
return ei.Emotes{}, false
}

// If still missing after Discord fetch, look up image in local emoji/ directory
emojiPath, ok := findLocalEmojiPath(emojiName)
if !ok {
return ei.Emotes{}, false
}
Expand All @@ -142,43 +138,6 @@
return createdEmoji, true
}



func downloadMissingEmojiFromGit(emojiName string) (string, bool) {
baseURL := "https://raw.githubusercontent.com/mkmccarty/TokenTimeBoostBot/refs/heads/main/emoji/"
extensions := []string{".png", ".gif"}

for _, ext := range extensions {
fileURL := fmt.Sprintf("%s%s%s", baseURL, emojiName, ext)
resp, err := http.Get(fileURL)
if err != nil || resp.StatusCode != http.StatusOK {
if resp != nil && resp.Body != nil {
_ = resp.Body.Close()
}
continue
}

_ = os.MkdirAll("emoji", 0755)
localPath := filepath.Join("emoji", fmt.Sprintf("%s%s", emojiName, ext))
outFile, err := os.Create(localPath)
if err != nil {
_ = resp.Body.Close()
continue
}

_, err = io.Copy(outFile, resp.Body)
_ = outFile.Close()
_ = resp.Body.Close()

if err == nil {
log.Printf("Successfully pulled missing emoji %s%s from GitHub repo", emojiName, ext)
return localPath, true
}
}

return "", false
}

func findLocalEmojiPath(emojiName string) (string, bool) {
files, err := os.ReadDir("emoji")
if err != nil {
Expand Down Expand Up @@ -364,6 +323,10 @@

// ImportNewEmojis will import new emojis from the emoji directory into the discord app
func ImportNewEmojis(s *discordgo.Session) {
if config.IsDevBot() {
return
}

// Get a list of all files in the emoji directory
files, err := os.ReadDir("emoji")
if err != nil {
Expand Down
Loading