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" "os"
"tweetdistributor/discord" "tweetdistributor/discord"
"tweetdistributor/output" "tweetdistributor/output"
"unicode/utf8"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
) )
const maxTweetLength = 140
func main() { func main() {
d := discord.Discord(os.Getenv("DISCORD_TOKEN"), os.Getenv("DISCORD_CHANNEL")) 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"))) outputs = append(outputs, output.BlueskyOutput(os.Getenv("BSKY_IDENTIFIER"), os.Getenv("BSKY_PASSWORD")))
for tweet := range tweetchannel { 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 { for _, output := range outputs {
err := output.Write(tweet.Content) err := output.Write(tweet.Content)
if err != nil { if err != nil {