Skip to content

Instantly share code, notes, and snippets.

@Timbus
Created September 28, 2010 00:47
Show Gist options
  • Save Timbus/600193 to your computer and use it in GitHub Desktop.
Save Timbus/600193 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
my $name = "EvalScript";
my $version = '0.1';
Xchat::register($name, $version);
Xchat::print "$name version $version loaded\n";
my $__evalerror = 1;
my ($a, $b, @arr, %hash);
sub EvalText{
return Xchat::EAT_NONE unless ($_[1][1]);
my $cmd = $_[1][1];
my $context = Xchat::get_context();
Xchat::hook_timer(0, sub {
Xchat::set_context($context);
my @ret = eval $cmd;
if ($@ && $__evalerror) {
chomp $@;
Xchat::command "say $@";
return Xchat::REMOVE;
}
for my $result (@ret){
chomp $result;
next unless ($result);
my @lines = split "\n", $result;
@_ && Xchat::command "say $_" for (@lines);
}
return Xchat::REMOVE;
});
return Xchat::EAT_NONE;
}
Xchat::hook_command('eval', \&EvalText);
sub CheckEval{
return Xchat::EAT_NONE unless (lc($_[0][0]) eq '!eval');
EvalText(@_);
}
Xchat::hook_command('', \&CheckEval);
sub EvalErr {
$__evalerror = 1 if $_[0][1] =~ /^(?:1|on)$/i;
$__evalerror = 0 if $_[0][1] =~ /^(?:0|off)$/i;
return Xchat::EAT_NONE;
}
Xchat::hook_command('evalerr', \&EvalErr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment