File tree 1 file changed +23
-1
lines changed
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,9 @@ package irc
2
2
3
3
import (
4
4
"net"
5
+ "strings"
5
6
"time"
7
+ "unicode/utf8"
6
8
7
9
"github.com/lrstanley/girc"
8
10
"github.com/ritlug/teleirc/internal"
@@ -91,7 +93,27 @@ func (c Client) ConnectDialer(dialer girc.Dialer) error {
91
93
Message sends a PRIVMSG to target (either channel, service, or user).
92
94
*/
93
95
func (c Client ) Message (channel string , msg string ) {
94
- c .Cmd .Message (channel , msg )
96
+ maxLength := c .MaxEventLength ()
97
+
98
+ if len (msg ) <= maxLength {
99
+ c .Cmd .Message (channel , msg )
100
+ return
101
+ }
102
+
103
+ var msgPart strings.Builder
104
+
105
+ for _ , r := range msg {
106
+ if nextLen := msgPart .Len () + utf8 .RuneLen (r ); nextLen > maxLength {
107
+ c .Cmd .Message (channel , msgPart .String ())
108
+ msgPart .Reset ()
109
+ }
110
+
111
+ msgPart .WriteRune (r )
112
+ }
113
+
114
+ if msgPart .Len () > 0 {
115
+ c .Cmd .Message (channel , msgPart .String ())
116
+ }
95
117
}
96
118
97
119
/*
You can’t perform that action at this time.
0 commit comments