Xchat cutscript?

Useful items for all visitors - virus warnings, firewalls, IRC scripts etc

Moderators: Ehlanna, Twerlinger

Xchat cutscript?

Postby Eraelabryn on Thu Jun 16, 2011 7:55 pm

Does anyone have, or know of one to be used? Thanks!
Eraelabryn
Op
Op
 
Posts: 524
Joined: Thu Mar 09, 2006 6:27 pm

Re: Xchat cutscript?

Postby Ehlanna on Thu Jun 16, 2011 9:30 pm

I have to admit I thougth X-chat implemented cuts by default. Patently it doesn't!
What OS is this running on?
User avatar
Ehlanna
High Council
High Council
 
Posts: 2494
Joined: Sat Apr 09, 2005 9:23 pm

Re: Xchat cutscript?

Postby Ylith on Fri Jun 17, 2011 5:20 pm

Been through this with it before, X-chat doesn't have a cutscript to use on windows systems.

x-chat was designed to be used on linux/unix systems, where it does cut , it does have a windows version of the basic chat client, but it is very different from the linux version.
Ylith
Novice
Novice
 
Posts: 23
Joined: Sat Feb 26, 2011 5:53 pm

Re: Xchat cutscript?

Postby Ehlanna on Sun Apr 01, 2012 5:07 pm

Have tracked down, tried and tested a cut script for Xchat2 running under Linux. It works for both normal /say style text as well as /me actions.

You can find the script here, but for convenience I replicate it here:
Code: Select all
    #             ___
    #            /   |  _      __   ___     _____   ____     ____ ___    ___
    #           / /| | | | /| / /  / _ \   / ___/  / __ \   / __ `__ \  / _ \
    #          / ___ | | |/ |/ /  /  __/  (__  )  / /_/ /  / / / / / / /  __/
    #         /_/  |_| |__/|__/   \___/  /____/   \____/  /_/ /_/ /_/  \___/
    #              ___          _        ___              _          _   
    #             / __|  _  _  | |_     / __|  __   _ _  (_)  _ __  | |_           
    #            | (__  | || | |  _|    \__ \ / _| | '_| | | | '_ \ |  _|           
    #             \___|  \_,_|  \__|    |___/ \__| |_|   |_| | .__/  \__|           
    #                                                        |_|                   
    #                  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;
    }

Now, how to get it to work ...
The answer is simple! In plain, basic terms, copy the above code and paste it into a text file. Save the text file, start xchat2 and voila ... :)
Now, in more depth:
1) Copy the above code - I hope you can mange this! Click on the "Select All" at the top of the code display, then use whatever mechanism you have to copy (Ctrl-C, Edit> Copy, etc.)
2) Paste into a text file. Ok, many ways of doing this.
2.0a) Easiest would be to use the graphical interface, fire up a text editor and paste the code into place.
2.0b) Use the command line editor vi (or vim) to Insert the code.
2.1) Saving the file in the right place - again, should be simple, but all things reference putting it in your 'plugins' directory, so ... where is the right place? If it goes into the right place the script will load whenever xchat2 starts so you will not need to manually load it each time. Which is good!
2.1a) In Windows (I am assuming this will work in WIndows) you will find a plugin directory under the location where Xchat2 is installed. I am guessing that is where it should go.
2.1b) In *nix there will be a directory called .xchat2 in your home directory. Files and directories starting with a . are usually hidden in *nix, but do not worry it will (should!) be there. In a Terminal session just type: cd ~/.xchat2
2.2 What do I call it? Whilst *nix does not normally what a file is called, I'd recommend for either Windows or *nix that you call it something like cut.pl

So, assuming a version of *nix and using command line, do:
Copy above code
Start a Terminal session
cd ~/.chat2
vi cut.pl
i (to enter insert mode)
Paste the code (Edit> Paste or Right-click, Paste)
Press Esc (to go back to command mode)
:xq (to save and quit editor)
The files does not seem to need to be executable, so that should be all that is needed.
It announces it's loading (in the status window) when Xchat2 starts, so you can use that as a check it has all worked.

Apart from the above instructions, none of this is my work!
User avatar
Ehlanna
High Council
High Council
 
Posts: 2494
Joined: Sat Apr 09, 2005 9:23 pm

Re: Xchat cutscript?

Postby Sativa on Tue May 08, 2012 5:55 pm

That's pretty cool. Does anyone have one for mibbit?
Sativa, Oread
Lidanya, little Swan Maiden
Lillandra, Sylvan Elf
Terpsichore, blue-skinned Magi
Irena, Barbarian
Siloen, Moriel
Organa, Tribeswoman Barbarian
Nala, Minoess
Breanna, sexy, busty mermaid
Janeth, maskless Sheyka healer slut
Asheerah, the hottest, sluttiest, most submissive Barbarian you'll ever meet
Sarina, Tribeswoman with a bit of a chip on her shoulder and not much else
Sativa
Novice
Novice
 
Posts: 12
Joined: Thu Jul 03, 2008 11:38 pm


Return to Public Service

Who is online

Users browsing this forum: No registered users and 1 guest