Skip to content

Instantly share code, notes, and snippets.

@lkraav
Forked from jashmenn/gist:6206
Created November 16, 2009 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lkraav/236068 to your computer and use it in GitHub Desktop.
Save lkraav/236068 to your computer and use it in GitHub Desktop.
some modifications to irssi -> growl gateway
# == WHAT
# Simple script for growl notifications in irssi
#
# == WHO
# Nate Murray 2008
# Modif: Leho Kraav 2009
#
# == CONFIG
# /SET growl_on_regex [regex]
# /SET growl_channel_regex [regex]
#
# == EXAMPLES
#
# growl everything:
# /SET growl_on_regex .*
#
# ignore jdewey
# /SET growl_on_regex (?=^(?:(?!jdewey).)*$).*
#
# this is my setup to growl the nick regex below from all channels + all private messages
# not filtering out any channels
# 17:41 [misc]
# 17:41 growl_channel_regex = 0
# 17:41 growl_on_nick = 1
# 17:41 growl_on_regex = mac(ma|.*)
# == INSTALL
# Place in ~/.irssi/scripts/
# /script load growlnotify.pl
#
# == CONTRIBUTE
# If anyone has a better suggestion to DRY up the signals I would appreciate it.
#
# http://gist.github.com/236068
# or
# git clone git://gist.github.com/236068.git gist-236068
use strict;
use Irssi;
use vars qw($VERSION %IRSSI);
# use Config;
# Dev. info ^_^
$VERSION = "0.0";
%IRSSI = (
authors => "Nate Murray",
contact => "nate\@natemurray.com",
name => "Growl",
description => "Simple script that will growlnotify the messages",
license => "GPL",
url => "http://www.xcombinator.com",
changed => "Mon Sep 22 11:55:07 PDT 2008"
);
# All the works
sub do_growl {
my ($title, $data) = @_;
$data =~ s/["';]//g;
# if ($Config{useithreads}) {
# use threads;
# threads->new( sub {
# system("growlnotify -H localhost -m '$data' -t '$title'");
# }) # ->join ?
# } else {
system("growlnotify -t '$title' -m '$data' >> /dev/null 2>&1");
# }
return 1
}
sub growl_it {
my ($server, $title, $data, $channel, $nick) = @_;
my $filter = Irssi::settings_get_str('growl_on_regex');
my $channel_filter = Irssi::settings_get_str('growl_channel_regex');
my $growl_on_nick = Irssi::settings_get_str('growl_on_nick');
my $current_nick = $server->{nick};
#Some debuggin stuff
#while( my ($k, $v) = each %$server ) {
# Irssi::print("key: $k, value: $v.\n");
#}
#Irssi::print("%G>>%n server: $server");
#Irssi::print("%G>>%n data: $data");
#Irssi::print("%G>>%n channel: $channel");
#Irssi::print("%G>>%n nick: $nick");
#Irssi::print("%G>>%n title: $title");
#Irssi::print("%G>>%n -----------------------------------------");
if(($growl_on_nick =~ /true/i && $data =~ /$current_nick/) || !$channel) {
# if nick is said or privmsg sent (=no channel info): just growl, dont check anything else
} else {
if($filter) {
return 0 if $data !~ /$filter/;
}
if($channel_filter && $server->ischannel($channel)) {
return 0 if $channel !~ /$channel_filter/;
}
}
$title = "[$server->{chatnet}] " . $title . " " . $channel;
do_growl($title, $data);
}
# All the works
sub growl_message {
# Irssi::print("%G>>%n growl_message");
my ($server, $data, $nick, $mask, $target) = @_;
my ($goal, $text) = split(/ :/, $data, 2);
growl_it($server, $nick, $data, $target, $nick);
Irssi::signal_continue($server, $data, $nick, $mask, $target);
}
sub growl_join {
my ($server, $channel, $nick, $address) = @_;
growl_it($server, "Join", "$nick has joined", $channel, $nick);
Irssi::signal_continue($server, $channel, $nick, $address);
}
sub growl_part {
my ($server, $channel, $nick, $address) = @_;
growl_it($server, "Part", "$nick has parted", $channel, $nick);
Irssi::signal_continue($server, $channel, $nick, $address);
}
sub growl_quit {
my ($server, $nick, $address, $reason) = @_;
growl_it($server, "Quit", "$nick has quit: $reason", $server, $nick);
Irssi::signal_continue($server, $nick, $address, $reason);
}
sub growl_invite {
my ($server, $channel, $nick, $address) = @_;
growl_it($server, "Invite", "$nick has invited you on $channel", $channel, $nick);
Irssi::signal_continue($server, $channel, $address);
}
sub growl_topic {
my ($server, $channel, $topic, $nick, $address) = @_;
growl_it($server, "Topic: $topic", "$nick has changed the topic to $topic on $channel", $channel, $nick);
Irssi::signal_continue($server, $channel, $topic, $nick, $address);
}
sub growl_privmsg {
# $server = server record where the message came
# $data = the raw data received from server, with PRIVMSGs it is:
# "target :text" where target is either your nick or #channel
# $nick = the nick who sent the message
# $host = host of the nick who sent the message
# Irssi::print("%G>>%n growl_privmsg");
my ($server, $data, $nick, $host) = @_;
my ($target, $text) = split(/ :/, $data, 2);
# growl_it($server, $nick, $data, $target, $nick); # actually, don't do this.
Irssi::signal_continue($server, $data, $nick, $host);
}
# Hook me up
Irssi::settings_add_str('misc', 'growl_on_regex', 0); # false
Irssi::settings_add_str('misc', 'growl_channel_regex', 0); # false
Irssi::settings_add_str('misc', 'growl_on_nick', 1); # true
Irssi::signal_add('message public', 'growl_message');
Irssi::signal_add('message private', 'growl_message');
#Irssi::signal_add('message join', 'growl_join');
#Irssi::signal_add('message part', 'growl_part');
#Irssi::signal_add('message quit', 'growl_quit');
#Irssi::signal_add('message invite', 'growl_invite');
#Irssi::signal_add('message topic', 'growl_topic');
#Irssi::signal_add('event privmsg', 'growl_privmsg');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment