-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't truncate text #28
Labels
Comments
Here’s a patch to do this if anybody’s interested |
Thank you very much! --- go-discord-irc/bridge/irc_manager.go Thu Jul 16 14:03:07 2020
+++ /home/puto/go-discord-irc/bridge/irc_manager.go Thu Jul 16 13:56:36 2020
@@ -5,6 +5,7 @@
"regexp"
"strings"
"time"
+ "math"
"github.com/mozillazg/go-unidecode"
"github.com/pkg/errors"
@@ -298,6 +291,25 @@
return newNick
}
+
+func splitByWidthMake(str string, size int) []string {
+ strLength := len(str)
+ splitedLength := int(math.Ceil(float64(strLength) / float64(size)))
+ splited := make([]string, splitedLength)
+ var start, stop int
+ for i := 0; i < splitedLength; i += 1 {
+ start = i * size
+ stop = start + size
+ if stop > strLength {
+ stop = strLength
+ }
+ splited[i] = str[start : stop]
+ }
+ return splited
+}
+
+
// SendMessage sends a broken down Discord Message to a particular IRC channel.
func (m *IRCManager) SendMessage(channel string, msg *DiscordMessage) {
con, ok := m.ircConnections[msg.Author.ID]
@@ -310,12 +322,15 @@
if !ok {
length := len(msg.Author.Username)
for _, line := range strings.Split(content, "\n") {
- m.bridge.ircListener.Privmsg(channel, fmt.Sprintf(
- "<%s#%s> %s",
- msg.Author.Username[:1]+"\u200B"+msg.Author.Username[1:length],
- msg.Author.Discriminator,
- line,
- ))
+ chunks := splitByWidthMake(line, 400)
+ for _, s := range chunks {
+ m.bridge.ircListener.Privmsg(channel, fmt.Sprintf(
+ "<%s#%s> %s",
+ msg.Author.Username[:1]+"\u200B"+msg.Author.Username[1:length],
+ msg.Author.Discriminator,
+ s,
+ ))
+ }
}
return
}
@@ -326,20 +341,23 @@
}
for _, line := range strings.Split(content, "\n") {
- ircMessage := IRCMessage{
- IRCChannel: channel,
- Message: line,
- IsAction: msg.IsAction,
- }
+ chunks := splitByWidthMake(line, 400)
+ for _, s := range chunks {
+ ircMessage := IRCMessage{
+ IRCChannel: channel,
+ Message: s,
+ IsAction: msg.IsAction,
+ }
- select {
- // Try to send the message immediately
- case con.messages <- ircMessage:
- // If it can't after 5ms, do it in a separate goroutine
- case <-time.After(time.Millisecond * 5):
- go func() {
- con.messages <- ircMessage
- }()
+ select {
+ // Try to send the message immediately
+ case con.messages <- ircMessage:
+ // If it can't after 5ms, do it in a separate goroutine
+ case <-time.After(time.Millisecond * 5):
+ go func() {
+ con.messages <- ircMessage
+ }()
+ }
}
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If text is too long for one line on IRC, split it into multiple lines
The text was updated successfully, but these errors were encountered: