Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Copypaste sendmsg to Net::IRC::Bot

  • Loading branch information...
commit 37a21dd66ff0b6d7604f500673c745fac462f713 1 parent 57df4f7
Tadeusz Sośnierz authored August 24, 2012

Showing 1 changed file with 18 additions and 1 deletion. Show diff stats Hide diff stats

  1. 19  lib/Net/IRC/Bot.pm
19  lib/Net/IRC/Bot.pm
@@ -167,6 +167,23 @@ class Net::IRC::Bot {
167 167
 			}
168 168
 		}
169 169
 	}
170  
-}
  170
+
  171
+	method sendmsg($text, $to) {
  172
+		##IRC RFC specifies 510 bytes as the maximum allowed to send per line.
  173
+		#I'm going with 480, as 510 seems to get cut off on some servers.
  174
+
  175
+		my $prepend = "PRIVMSG $to :";
  176
+		my $maxlen = 480-$prepend.encode.bytes;
  177
+		for $text.split(/\c13?\c10/) -> $line is rw {
  178
+			while $line.encode.bytes > $maxlen {
  179
+				#Break up the line using a nearby space if possible.
  180
+				my $index = $line.rindex(" ", $maxlen) || $maxlen;
  181
+				$conn.sendln($prepend~$line.substr(0, $index));
  182
+				$line = $line.substr($index+1);
  183
+			}
  184
+			$conn.sendln($prepend~$line);
  185
+		}
  186
+	}
  187
+	}
171 188
 
172 189
 # vim: ft=perl6 sw=4 expandtab

0 notes on commit 37a21dd

Please sign in to comment.
Something went wrong with that request. Please try again.