# react.pl by arza : React on messages # This program is free software: you can modify/redistribute it under the terms of # GNU General Public License by Free Software Foundation, either version 3 or later # which you can get from . # This program is distributed in the hope that it will be useful, but without any warranty. # This script is inspired by trigger.pl for irssi by Wouter Coekaerts weechat::register("react", "arza ", "0.1", "GPL3", "React on messages", "", ""); weechat::hook_command("react", "React on messages", "add||del||list", "help", "add||del||list", "react", ""); use Text::ParseWords; my $file=weechat::info_get("weechat_dir", "")."/react"; open FILE, ">>", $file; close FILE; sub react { my $arg=$_[2]; if($arg=~/^add (.+)/){ weechat::print("", $1); }elsif($arg=~/^del (.+)/){ weechat::print("", $1); }else{ open FILE, "<", $file; weechat::print("", $_) while(); close FILE; } } my (@hook_print, @hook_modifier); open FILE, "<", $file; while(){ next if /^#/; # a line, which isn't a comment my @parts=quotewords('\s+', 0, $_); # split my ($action, $cond, $hook, $suppress, $regexp) = ("", "", "", "", ""); while(my $part=shift(@parts)){ # a word if($part eq "-print"){ $hook="print"; $regexp=shift(@parts); }elsif($part eq "-signal"){ $hook="signal"; }elsif($part eq "-irc-in"){ $hook="irc-in"; $regexp=shift(@parts); }elsif($part eq "-command"){ $action="command"; $arg=shift(@parts); }elsif($part eq "-replace"){ $action="replace"; $arg=shift(@parts); }elsif($part eq "-suppress"){ $suppress=1; } } if($hook eq "print"){ #my ($buffer, $tags, $str, $nocolors, $regexp) = (@hook_args[0..3],$hook_args[4]) or return weechat::WEECHAT_RC_ERROR; #my ($regexp) = ($hook_args[4]) or return weechat::WEECHAT_RC_ERROR; #push(@hook_print, [$buffer, $tags, $str, $nocolors, $regexp, $action, $arg]); push(@hook_print, [$regexp]); }elsif($hook eq "irc-in"){ push(@hook_modifier, [$regexp, $suppress, $action, $arg]); } } close FILE; weechat::hook_print("", "", "", 0, "print", ""); weechat::hook_modifier("irc_in_privmsg", "irc_in", ""); sub print { for my $i (0..$#hook_print){ my ($regexp) = @{$hook_print[$i]}; #my ($buffer, $tags, $str, $nocolors, $regexp, $action, $arg) = @{$hook_print[$i]}; if($_[7] =~ /$regexp/){ weechat::command("", $arg); } } return weechat::WEECHAT_RC_OK; } sub irc_in { for my $i (0..$#hook_modifier){ my ($regexp, $suppress, $action, $arg) = @{$hook_modifier[$i]}; if($_[3] =~ /$regexp/){ if($action eq "replace"){ my $return = $_[3]; my ($arg1,$arg2) = split(/\//, $arg, 2); $return =~ s/$arg1/$arg2/; return $return; } my ($re1, $re2, $re3) = ($1, $2, $3); $arg=~s/\$1/$re1/; $arg=~s/\$2/$re2/; $arg=~s/\$3/$re3/; $arg=~s/\$server/$_[2]/; weechat::command("", $arg); if($suppress){ return ""; } } } return $_[3]; }