diff options
| author | uakci <uakci@uakci.pl> | 2022-08-29 22:17:27 +0200 |
|---|---|---|
| committer | uakci <uakci@uakci.pl> | 2022-08-29 22:17:27 +0200 |
| commit | 8ca2081fecc91ec047b835116df595d9a9c12a7b (patch) | |
| tree | 31eefc874803ae6f0a16e508e44b808854ba54da | |
| parent | remove more vietoaq code; don't respond to ??? (diff) | |
| download | nuogai-8ca2081fecc91ec047b835116df595d9a9c12a7b.tar.gz nuogai-8ca2081fecc91ec047b835116df595d9a9c12a7b.zip | |
add overflow protection on send
| -rw-r--r-- | bot.go | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -118,8 +118,23 @@ func Respond(dg *discordgo.Session, ms *discordgo.MessageCreate) { Reader: bytes.NewReader(r.Image), }) } + var content string + if len(r.Text) <= 2000 { + content = r.Text + } else { + reader := strings.NewReader(r.Text) + i, offset := 0, 0 + for i < 2000 { + _, size, err := reader.ReadRune() + if err != nil { + break + } + offset, i = offset+size, i+1 + } + content = r.Text[:offset] + } dg.ChannelMessageSendComplex(ms.Message.ChannelID, &discordgo.MessageSend{ - Content: r.Text, + Content: content, Files: files, }) }) |
