1. Xchat -> Load plugin or script...
2. /serveme_channel #channel_where_both_you_and_serveme_are_present
#!/usr/bin/perl
use strict;
use warnings;
# --------------------------------------------------------------------------------
# Documentation
# --------------------------------------------------------------------------------
#
# Intercepts messages from ServeMe-bots and displays them in separate query
# windows, <qw> and <spam>.
#
# Commands:
#
# serveme_channel - Sets channel from where to read ServeMe-messages. The default
# channel is #quakeworld you must be on the channel for the
# script to work. Ex. /serveme_channel #quakeworld
#
# serveme_channel_current - Prints current channel in the active window
#
# Contact:
#
# QuakeNet, #clan-sm, apa
#
# --------------------------------------------------------------------------------
# Configuration
my $serveme_channel = "#quakeworld";
# Script info
my $name = "ServeMe";
my $version = "0.1";
Xchat::register($name, $version, "ServeMe messages are intercepted and put in separate query windows."

;
Xchat::print("Loaded $name $version"

;
serveme_channel_current();
open_query_windows();
# Hooks
Xchat::hook_print("Channel Message", \&channel_message_callback);
Xchat::hook_print("Channel Msg Hilight", \&channel_message_callback);
Xchat::hook_print("Connected", \&connected_callback);
Xchat::hook_command("serveme_channel", \&set_serveme_channel, {help_text => "Sets channel where ServeMe messages are intercepted."});
Xchat::hook_command("serveme_channel_current", \&serveme_channel_current, {help_text => "Prints the current ServeMe channel."});
# Methods
sub channel_message_callback
{
my $nick = Xchat::strip_code($_[0][0]);
# Check if the message is from a ServeMe user
if ($nick =~ m/^\[ServeMe\]\d\d$/i)
{
my $msg = Xchat::strip_code($_[0][1]);
# Info message "mnet: Message sent to 1338 users in 155 channels."
if ($msg =~ m/^mnet/i)
{
return Xchat::EAT_NONE;
}
# Check if the ServeMe message is from the input channel
if (Xchat::get_context() == Xchat::find_context($serveme_channel))
{
open_query_windows();
my $context = Xchat::get_context();
if ($msg =~ m/^-qw-/i)
{
Xchat::set_context(Xchat::find_context("<qw>"

);
}
elsif ($msg =~ m/^-spam-/i)
{
Xchat::set_context(Xchat::find_context("<spam>"

);
}
else
{
# this should never happen
if (!Xchat::find_context("<unknown>"

)
{
Xchat::command("query <unknown>"

;
}
Xchat::set_context(Xchat::find_context("<unknown>"

);
}
Xchat::emit_print("Channel Message", $nick, $msg, $_[0][2], $_[0][3]);
Xchat::set_context($context);
}
return Xchat::EAT_ALL;
}
else
{
return Xchat::EAT_NONE;
}
}
sub connected_callback
{
open_query_windows();
}
sub set_serveme_channel
{
if ($_[0][1] =~ m/^#[a-z0-9_]+/i)
{
$serveme_channel = $_[0][1];
serveme_channel_current();
}
else
{
Xchat::print("Invalid channel name $_[0][1]."

;
}
}
sub serveme_channel_current
{
Xchat::print("ServeMe channel: $serveme_channel"

;
}
sub open_query_windows
{
if (!Xchat::find_context("<qw>"

)
{
Xchat::command("query <qw>"

;
}
if (!Xchat::find_context("<spam>"

)
{
Xchat::command("query <spam>"

;
}
}