ThorLarge |
|
Moderators: Ehlanna, Twerlinger
# ___
# / | _ __ ___ _____ ____ ____ ___ ___
# / /| | | | /| / / / _ \ / ___/ / __ \ / __ `__ \ / _ \
# / ___ | | |/ |/ / / __/ (__ ) / /_/ / / / / / / / / __/
# /_/ |_| |__/|__/ \___/ /____/ \____/ /_/ /_/ /_/ \___/
# ___ _ ___ _ _
# / __| _ _ | |_ / __| __ _ _ (_) _ __ | |_
# | (__ | || | | _| \__ \ / _| | '_| | | | '_ \ | _|
# \___| \_,_| \__| |___/ \__| |_| |_| | .__/ \__|
# |_|
# It's... a... cut script! ..That's awesome!
# +----------------------------------------------------------------------------+
# | This script is meant to provide you with the ability to customize the way |
# | X-Chat cuts text sent out to a channel, when it's over the IRC buffer |
# | limit. There are a few customizable variables included with this script, |
# | which should be explained in detail below. |
# | |
# | If you have any questions about this script, I am availalable at |
# | soleil+cutscript@tixen.net. |
# | |
# | As I have never coded in perl before this script, all work here was |
# | based off of "Action Splitter" by Khisanth. The original code is |
# | available here: http://forum.xchat.org/viewtopic.php?t=1136 |
# | |
# | Happy buffer breaking! |
# | - Soleil |
# +----------------------------------------------------------------------------+
##----------------------------- Configuration ------------------------------##
# The first cut text- shown at the end of each cut post
my $split_text_end = '...'; # Default: '...'
# Shown at the beginning of each cut post
my $split_text_start = '[Continued] '; # Default: '[Continued] '
# The third cut text- shown at the end of each cut post.
my $split_text_fin = ' [End]'; # Default: ' [End]'
# Enable/Disable the informational message at the end of the post
my $enable_end_info = 'true'; # Comment out or change to disable
##---------------------------------- Code -----------------------------------##
use strict; use warnings; use Xchat qw(:all);
register( "Awesome Cut Script", '1.2', "Cuts actions and regular messages into buffer sized chunks." );
hook_command( "me", \&awesomecs_run, { data => 'action' } ); hook_command( "", \&awesomecs_run, { data => 'say' } );
prnt "--- Awesome Cut Script Version 1.2 has been loaded. ---\n";
sub awesomecs_run {
my $max_length = awesomecs_max_length($_[2]);
my $count = 1;
my $text = '';
if(defined($_[0][0]) && $_[2] eq 'action') { $text = $_[1][1]; }
elsif(defined($_[0][0])) { $text = $_[1][0]; }
else{return EAT_NONE;}
if( length( $text ) > $max_length && defined($_[0][0]) && $_[0][0] ne awesomecs_trim($split_text_start)) {
my ($segments_ref, $count_ref) = awesomecs_segments( $text, $max_length, $count );
my @segments = @$segments_ref;
$count = $count_ref;
if($_[2] eq 'action') { commandf( "me %s", shift @segments ); }
else {commandf( "say %s", shift @segments ); }
command( [map { s/^/say /; $_ } @segments] );
if(defined $enable_end_info && $enable_end_info) {
prnt "--- Cut into $count mesages. ---";
}
return EAT_ALL;
} return EAT_NONE;
}
sub awesomecs_segments {
my ($text, $max, $count) = @_;
my @segments;
my $start = '';
if( length( $text ) > $max ) {
while( length( $text ) > $max ) { $count++;
my $end = rindex( $text, ' ', $max );
if( $end < 0 ) { $end = $max - 1; } # no space in the message
if($count > 2) { $start = $split_text_start;} else { my $start = '';}
push @segments, $start.substr( $text, 0, $end ).$split_text_end;
$text = substr( $text, $end + 1 );
} push @segments, $split_text_start.$text.$split_text_fin;
} else { push @segments, $text; }
return (\@segments, $count);
}
sub awesomecs_trim($) {
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
sub awesomecs_max_length {
my $max = 478;
if(@_ eq 'action') { $max += 9; }
$max -= length(get_info("nick")); $max -= length(get_info("channel"));
$max -= length($split_text_start);
if(length($split_text_fin) > length($split_text_end)) { $max -= length($split_text_fin); }
else{ $max -= length($split_text_end); }
if( defined(user_info) && defined(user_info->{host})) { $max -= length user_info->{host}; } else { $max -= 74; }
return $max;
}
Users browsing this forum: No registered users and 1 guest