Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Add reaction constants #182

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
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
101 changes: 89 additions & 12 deletions gen_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ const (
ParseModeNone = ""
)

// The consts listed below represent all the sticker types that can be obtained from telegram.
const (
StickerTypeRegular = "regular"
StickerTypeMask = "mask"
StickerTypeCustomEmoji = "custom_emoji"
)

// The consts listed below represent all the chat types that can be obtained from telegram.
const (
ChatTypePrivate = "private"
ChatTypeGroup = "group"
ChatTypeSupergroup = "supergroup"
ChatTypeChannel = "channel"
)

// The consts listed below represent all the chat action options that can be sent to telegram.
const (
ChatActionTyping = "typing"
Expand All @@ -126,17 +141,79 @@ const (
ChatActionUploadVideoNote = "upload_video_note"
)

// The consts listed below represent all the sticker types that can be obtained from telegram.
// The consts listed below represent all the reaction options that can be sent to telegram as ReactionTypeEmoji.
const (
StickerTypeRegular = "regular"
StickerTypeMask = "mask"
StickerTypeCustomEmoji = "custom_emoji"
)

// The consts listed below represent all the chat types that can be obtained from telegram.
const (
ChatTypePrivate = "private"
ChatTypeGroup = "group"
ChatTypeSupergroup = "supergroup"
ChatTypeChannel = "channel"
ReactionThumbsUp = "👍"
ReactionThumbsDown = "👎"
ReactionRedHeart = "❤"
ReactionFire = "🔥"
ReactionSmilingFaceWithHearts = "🥰"
ReactionClappingHands = "👏"
ReactionBeamingFaceWithSmilingEyes = "😁"
ReactionThinkingFace = "🤔"
ReactionExplodingHead = "🤯"
ReactionFaceScreamingInFear = "😱"
ReactionFaceWithSymbolsOnMouth = "🤬"
ReactionCryingFace = "😢"
ReactionPartyPopper = "🎉"
ReactionStarStruck = "🤩"
ReactionFaceVomiting = "🤮"
ReactionPileOfPoo = "💩"
ReactionFoldedHands = "🙏"
ReactionOkHand = "👌"
ReactionDove = "🕊"
ReactionClownFace = "🤡"
ReactionYawningFace = "🥱"
ReactionWoozyFace = "🥴"
ReactionSmilingFaceWithHeartEyes = "😍"
ReactionSpoutingWhale = "🐳"
ReactionHeartOnFire = "❤‍🔥"
ReactionNewMoonFace = "🌚"
ReactionHotDog = "🌭"
ReactionHundredPoints = "💯"
ReactionRollingOnTheFloorLaughing = "🤣"
ReactionHighVoltage = "⚡"
ReactionBanana = "🍌"
ReactionTrophy = "🏆"
ReactionBrokenHeart = "💔"
ReactionFaceWithRaisedEyebrow = "🤨"
ReactionNeutralFace = "😐"
ReactionStrawberry = "🍓"
ReactionBottleWithPoppingCork = "🍾"
ReactionKissMark = "💋"
ReactionMiddleFinger = "🖕"
ReactionSmilingFaceWithHorns = "😈"
ReactionSleepingFace = "😴"
ReactionLoudlyCryingFace = "😭"
ReactionNerdFace = "🤓"
ReactionGhost = "👻"
ReactionManTechnologist = "👨‍💻"
ReactionEyes = "👀"
ReactionJackOLantern = "🎃"
ReactionSeeNoEvilMonkey = "🙈"
ReactionSmilingFaceWithHalo = "😇"
ReactionFearfulFace = "😨"
ReactionHandshake = "🤝"
ReactionWritingHand = "✍"
ReactionSmilingFaceWithOpenHands = "🤗"
ReactionSalutingFace = "🫡"
ReactionSantaClaus = "🎅"
ReactionChristmasTree = "🎄"
ReactionSnowman = "☃"
ReactionNailPolish = "💅"
ReactionZanyFace = "🤪"
ReactionMoai = "🗿"
ReactionCoolButton = "🆒"
ReactionHeartWithArrow = "💘"
ReactionHearNoEvilMonkey = "🙉"
ReactionUnicorn = "🦄"
ReactionFaceBlowingAKiss = "😘"
ReactionPill = "💊"
ReactionSpeakNoEvilMonkey = "🙊"
ReactionSmilingFaceWithSunglasses = "😎"
ReactionAlienMonster = "👾"
ReactionManShrugging = "🤷‍♂"
ReactionPersonShrugging = "🤷"
ReactionWomanShrugging = "🤷‍♀"
ReactionEnragedFace = "😡"
)
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module github.com/PaulSonOfLars/gotgbot/v2

go 1.19

require github.com/forPelevin/gomoji v1.2.0

require github.com/rivo/uniseg v0.4.7 // indirect
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/forPelevin/gomoji v1.2.0 h1:9k4WVSSkE1ARO/BWywxgEUBvR/jMnao6EZzrql5nxJ8=
github.com/forPelevin/gomoji v1.2.0/go.mod h1:8+Z3KNGkdslmeGZBC3tCrwMrcPy5GRzAD+gL9NAwMXg=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
77 changes: 71 additions & 6 deletions scripts/generate/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"regexp"
"strings"

"github.com/forPelevin/gomoji"
)

func generateConsts(d APIDescription) error {
Expand All @@ -25,12 +27,6 @@ package gotgbot

consts.WriteString(generateParseModeConsts())

chatActions, err := generateChatActionConsts(d)
if err != nil {
return fmt.Errorf("failed to generate consts for chat actions: %w", err)
}
consts.WriteString(chatActions)

stickerTypeConsts, err := generateTypeConsts(d, "Sticker")
if err != nil {
return fmt.Errorf("failed to generate consts for sticker types: %w", err)
Expand All @@ -43,6 +39,18 @@ package gotgbot
}
consts.WriteString(chatTypeConsts)

chatActions, err := generateChatActionConsts(d)
if err != nil {
return fmt.Errorf("failed to generate consts for chat actions: %w", err)
}
consts.WriteString(chatActions)

reactions, err := generateReactionConsts(d)
if err != nil {
return fmt.Errorf("failed to generate consts for reactions: %w", err)
}
consts.WriteString(reactions)

return writeGenToFile(consts, "gen_consts.go")
}

Expand Down Expand Up @@ -176,6 +184,63 @@ func generateChatActionConsts(d APIDescription) (string, error) {
return out.String(), nil
}

func generateReactionConsts(d APIDescription) (string, error) {
typeName := "ReactionTypeEmoji"
fieldName := "emoji"

reactionEmojiType, ok := d.Types[typeName]
if !ok {
return "", errors.New("missing '" + typeName + "' type data")
}

var description string

for _, field := range reactionEmojiType.Fields {
if field.Name == fieldName {
description = field.Description

break
}
}

if description == "" {
return "", errors.New("missing '" + fieldName + "' type field")
}

// Parse emojis from the description
var emojis []string

re := regexp.MustCompile(`"(.+)"`)
for _, s := range strings.Split(description, ",") {
result := re.FindStringSubmatch(s)
if len(result) < 2 {
continue
}

e := result[1]

emojis = append(emojis, e)
}

out := strings.Builder{}
out.WriteString("\n// The consts listed below represent all the reaction options that can be sent to telegram as ReactionTypeEmoji.")
out.WriteString("\nconst (")

for _, e := range emojis {
emoji, err := gomoji.GetInfo(e)
if err != nil {
return "", fmt.Errorf("failed to get emoji info for %q: %w", e, err)
}

constName := "Reaction" + snakeToTitle(strings.ReplaceAll(emoji.Slug, "-", "_"))
out.WriteString(writeConst(constName, e))
}

out.WriteString(")\n\n")

return out.String(), nil
}

func writeConst(name string, value string) string {
return fmt.Sprintf("\n%s = \"%s\"", name, value)
}
Loading