check 140 digits for twitter

This commit is contained in:
2026-07-03 10:03:19 +09:00
parent 68981e9eb5
commit 62cff6355b

View File

@@ -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 {