diff --git a/gen_consts.go b/gen_consts.go index df523b9..772387b 100755 --- a/gen_consts.go +++ b/gen_consts.go @@ -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" @@ -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 = "๐Ÿ˜ก" ) diff --git a/go.mod b/go.mod index 52478bc..1ba26a9 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index e69de29..441722c 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/scripts/generate/consts.go b/scripts/generate/consts.go index 0f1b631..5fa7f49 100644 --- a/scripts/generate/consts.go +++ b/scripts/generate/consts.go @@ -5,6 +5,8 @@ import ( "fmt" "regexp" "strings" + + "github.com/forPelevin/gomoji" ) func generateConsts(d APIDescription) error { @@ -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) @@ -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") } @@ -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) }