From 62cff6355b841bd60d9d6b4f0b3630ba11798062 Mon Sep 17 00:00:00 2001 From: sirrow Date: Fri, 3 Jul 2026 10:03:19 +0900 Subject: [PATCH] check 140 digits for twitter --- main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.go b/main.go index 97de111..eac893b 100644 --- a/main.go +++ b/main.go @@ -5,10 +5,13 @@ import ( "os" "tweetdistributor/discord" "tweetdistributor/output" + "unicode/utf8" "github.com/bwmarrin/discordgo" ) +const maxTweetLength = 140 + func main() { d := discord.Discord(os.Getenv("DISCORD_TOKEN"), os.Getenv("DISCORD_CHANNEL")) @@ -23,6 +26,12 @@ func main() { outputs = append(outputs, output.BlueskyOutput(os.Getenv("BSKY_IDENTIFIER"), os.Getenv("BSKY_PASSWORD"))) for tweet := range tweetchannel { + if length := utf8.RuneCountInString(tweet.Content); length > maxTweetLength { + errstr := fmt.Sprintf("Error: message is %d characters, exceeding the %d character limit; not posted", length, maxTweetLength) + fmt.Fprintln(os.Stderr, errstr) + d.Write(errstr) + continue + } for _, output := range outputs { err := output.Write(tweet.Content) if err != nil {