To create new wiki account, please join us on #znc at Libera.Chat and ask admins to create a wiki account for you. You can say thanks to spambots for this inconvenience.

Savebuff/XChat-Perl

From ZNC
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
XChat Perl Plugin

Freman: I had troubles getting the plugin above to compile on my mac for XChat-Aqua so I re-wrote it as perl, works identically to the one above (I think)

  1. Copy and paste this script to ~/.xchat/znc-buffer.pl or ~/Applications/X-Chat Aqua/Plugins/znc-buffer.pl
  2. Restart xchat
#!/usr/bin/perl

my $ShowMode = "mode \00310%s\003 \002%s\002 by \002%s\002";
my $ModName = "*savebuff";

Xchat::register('ZNC-Buffer','1.00','Display the on-join buffer for ZNC nicely');

Xchat::hook_server('PRIVMSG',\&ProcessPMSG);
Xchat::hook_server('MODE',\&ShowModes);
Xchat::hook_print('Channel Operator',\&DontDisplay);
Xchat::hook_print('Channel DeOp',\&DontDisplay);
Xchat::hook_print('Channel Voice',\&DontDisplay);
Xchat::hook_print('Channel DeVoice',\&DontDisplay);
Xchat::hook_print('Channel Ban',\&DontDisplay);
Xchat::hook_print('Channel UnBan',\&DontDisplay);
Xchat::hook_print('Channel Mode Generic',\&DontDisplay);
Xchat::hook_print('Channel Set Key',\&DontDisplay);
Xchat::hook_print('Channel Set Limit',\&DontDisplay);
Xchat::hook_print('Channel Remove Keyword',\&DontDisplay);
Xchat::hook_print('Channel Remove Limit',\&DontDisplay);

sub ShowMode {
        my ($Channel,$Modes,$Nick) = @_;

        my $Output = sprintf($ShowMode,$Channel,$Modes,$Nick);
        Xchat::emit_print("Generic Message","-\00310-\002-\002\003",$Output,null);
}

sub ProcessPMSG {
        my @Word = @{$_[0]};
        my @Word_EOL = @{$_[1]};
        if ((substr($Word[0],1,length($ModName)) eq $ModName) && ($Word[3]) && ($Word[4]) && ($Word[5])) {
                my $Channel = $Word[2];
                my $Hostmask = $Word[4];
                my $Type = $Word[5];
                my $Args = ($Word[6]) ? $Word_EOL[6] : undef;

                my ($Nick, $Host) = ($Hostmask =~ /^([^\!]+)!(.+)$/g);

                if ($Type eq 'MODE') {
                       ShowMode($Channel,$Args,$Nick);
                } elsif ($Type eq 'JOIN') {
                        Xchat::emit_print("Join",$Nick,$Channel,$Host,null);
                } elsif ($Type eq 'PART') {
                        Xchat::emit_print("Part",$Nick,$Host,$Channel,null);
                } elsif ($Type eq 'NICK') {
                        if ($Args) {
                                Xchat::emit_print("Change Nick",$Nick,$Args,null);
                        } else {
                                Xchat::emit_print("Change Nick",$Nick,"*shrug*",null);
                        }
                } elsif ($Type eq 'QUIT') {
                        if ($Args) {
                                Xchat::emit_print("Quit",$Nick,$Args,null);
                        } else {
                                Xchat::emit_print("Quit",$Nick,"No Reason",null);
                        }
                } elsif ($Type eq 'KICK') {
                        my ($bNick,$bHost) = ($Word[6] =~ /^([^\!]+)!(.+)$/g);

                        if ($Word[7]) {
                                Xchat::emit_print("Kick",$bNick,$Nick,$Channel,$Word_EOL[7],null);
                        } else {
                                Xchat::emit_print("Kick",$bNick,$Nick,$Channel,"No Reason",null);
                        }
                } else {
                        printf STDERR "Unhandled Text! [%s]\n", $Word_EOL[3];
                }

                return Xchat::EAT_ALL;
        }

        return Xchat::EAT_NONE;
}

sub DontDisplay {
        return Xchat::EAT_XCHAT;
}

sub ShowModes {
        my @Word = @{$_[0]};
        my @Word_EOL = @{$_[1]};

        my $Channel = $Word[2];
        $Word[0] =~ /^:([^\!]+)!.*/;
        $Nick = $1;
        my $Modes = $Word_EOL[3];

        ShowMode($Channel,$Modes,$Nick);

        return Xchat::EAT_NONE; 
}