Permalink
Browse files

Added .irssi scripts

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
  • Loading branch information...
1 parent 4589246 commit 587c12bce28b791fb25058597ab7e38ebfd43302 @trofi committed Oct 15, 2011
@@ -0,0 +1,27 @@
+#!/usr/bin/perl
+
+use Irssi;
+use strict;
+use vars qw($VERSION %IRSSI);
+use integer;
+use utf8;
+
+$VERSION = "0.0.2";
+%IRSSI = (
+ authors => 'slyfox',
+ name => 'opme',
+ description => 'alias for ^msg chanserv #current_channel <cmd>',
+ license => 'Public Domain'
+);
+
+sub cmd_cs
+{
+ my ($data, $server, $witem) = @_;
+
+ my @data_arr = split / /, $data;
+ my $first = shift @data_arr;
+ my $command = "$first ".'$C'." @data_arr;";
+ $witem->command('/eval ^msg chanserv '.$command);
+}
+
+Irssi::command_bind('cs', 'cmd_cs');
@@ -0,0 +1,156 @@
+use strict;
+use Irssi 20020101.0250 ();
+use vars qw($VERSION %IRSSI);
+$VERSION = "1";
+%IRSSI = (
+ authors => "Timo Sirainen, Ian Peters",
+ contact => "tss\@iki.fi",
+ name => "Nick Color",
+ description => "assign a different color for each nick",
+ license => "Public Domain",
+ url => "http://irssi.org/",
+ changed => "2002-03-04T22:47+0100"
+);
+
+# hm.. i should make it possible to use the existing one..
+Irssi::theme_register([
+ 'pubmsg_hilight', '{pubmsghinick $0 $3 $1}$2'
+]);
+
+my %saved_colors;
+my %session_colors = {};
+my @colors = qw/3 4 5 6 7 9 10 11 12 13 14/;
+
+sub load_colors {
+ open COLORS, "$ENV{HOME}/.irssi/saved_colors";
+
+ while (<COLORS>) {
+ # I don't know why this is necessary only inside of irssi
+ my @lines = split "\n";
+ foreach my $line (@lines) {
+ my($nick, $color) = split ":", $line;
+ $saved_colors{$nick} = $color;
+ }
+ }
+
+ close COLORS;
+}
+
+sub save_colors {
+ open COLORS, ">$ENV{HOME}/.irssi/saved_colors";
+
+ foreach my $nick (keys %saved_colors) {
+ print COLORS "$nick:$saved_colors{$nick}\n";
+ }
+
+ close COLORS;
+}
+
+# If someone we've colored (either through the saved colors, or the hash
+# function) changes their nick, we'd like to keep the same color associated
+# with them (but only in the session_colors, ie a temporary mapping).
+
+sub sig_nick {
+ my ($server, $newnick, $nick, $address) = @_;
+ my $color;
+
+ $newnick = substr ($newnick, 1) if ($newnick =~ /^:/);
+
+ if ($color = $saved_colors{$nick}) {
+ $session_colors{$newnick} = $color;
+ } elsif ($color = $session_colors{$nick}) {
+ $session_colors{$newnick} = $color;
+ }
+}
+
+# This gave reasonable distribution values when run across
+# /usr/share/dict/words
+
+sub simple_hash {
+ my ($string) = @_;
+ chomp $string;
+ my @chars = split //, $string;
+ my $counter;
+
+ foreach my $char (@chars) {
+ $counter += ord $char;
+ }
+
+ $counter = $colors[$counter % 11];
+
+ return $counter;
+}
+
+# FIXME: breaks /HILIGHT etc.
+sub sig_public {
+ my ($server, $msg, $nick, $address, $target) = @_;
+ my $chanrec = $server->channel_find($target);
+ return if not $chanrec;
+ my $nickrec = $chanrec->nick_find($nick);
+ return if not $nickrec;
+ my $nickmode = $nickrec->{op} ? "@" : $nickrec->{voice} ? "+" : "";
+
+ # Has the user assigned this nick a color?
+ my $color = $saved_colors{$nick};
+
+ # Have -we- already assigned this nick a color?
+ if (!$color) {
+ $color = $session_colors{$nick};
+ }
+
+ # Let's assign this nick a color
+ if (!$color) {
+ $color = simple_hash $nick;
+ $session_colors{$nick} = $color;
+ }
+
+ $color = "0".$color if ($color < 10);
+ $server->command('/^format pubmsg {pubmsgnick $2 {pubnick '.chr(3).$color.'$0}}$1');
+}
+
+sub cmd_color {
+ my ($data, $server, $witem) = @_;
+ my ($op, $nick, $color) = split " ", $data;
+
+ $op = lc $op;
+
+ if (!$op) {
+ Irssi::print ("No operation given");
+ } elsif ($op eq "save") {
+ save_colors;
+ } elsif ($op eq "set") {
+ if (!$nick) {
+ Irssi::print ("Nick not given");
+ } elsif (!$color) {
+ Irssi::print ("Color not given");
+ } elsif ($color < 2 || $color > 14) {
+ Irssi::print ("Color must be between 2 and 14 inclusive");
+ } else {
+ $saved_colors{$nick} = $color;
+ }
+ } elsif ($op eq "clear") {
+ if (!$nick) {
+ Irssi::print ("Nick not given");
+ } else {
+ delete ($saved_colors{$nick});
+ }
+ } elsif ($op eq "list") {
+ Irssi::print ("\nSaved Colors:");
+ foreach my $nick (keys %saved_colors) {
+ Irssi::print (chr (3) . "$saved_colors{$nick}$nick" .
+ chr (3) . "1 ($saved_colors{$nick})");
+ }
+ } elsif ($op eq "preview") {
+ Irssi::print ("\nAvailable colors:");
+ foreach my $i (2..14) {
+ Irssi::print (chr (3) . "$i" . "Color #$i");
+ }
+ }
+}
+
+load_colors;
+
+Irssi::command_bind('color', 'cmd_color');
+
+Irssi::signal_add('message public', 'sig_public');
+Irssi::signal_add('event nick', 'sig_nick');
@@ -0,0 +1,22 @@
+
+
+use Irssi;
+use strict;
+use vars qw($VERSION %IRSSI);
+use utf8;
+
+$VERSION = "0.0.1";
+%IRSSI = (
+ authors => 'slyfox',
+ name => 'private message signal',
+ description => 'wave sound player on PRIVMSG <us>',
+ license => 'Public Domain'
+);
+
+sub query_up
+{
+ my $sound="privmsg.wav";
+ `aplay ~/.irssi/sounds/$sound >& /dev/null &`;
+}
+
+Irssi::signal_add_last('message private', 'query_up');
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+
+use Irssi;
+use strict;
+use vars qw($VERSION %IRSSI);
+use utf8;
+
+$VERSION = "0.0.1";
+%IRSSI = (
+ authors => 'slyfox',
+ name => 'signal on QUERY',
+ description => 'wave sound player on QUERY',
+ license => 'Public Domain'
+);
+
+sub toc_toc
+{
+ my $sound="query_open.wav";
+ `aplay ~/.irssi/sounds/$sound >& /dev/null &`;
+}
+
+Irssi::signal_add_last('query created', 'toc_toc');
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+# /re [some text]
+
+use Irssi;
+use strict;
+use vars qw($VERSION %IRSSI);
+use integer;
+use utf8;
+
+$VERSION = "0.0.2";
+%IRSSI = (
+ authors => 'slyfox',
+ name => 're',
+ description => 'en2ru n vice versa',
+ license => 'Public Domain'
+);
+
+sub cmd_re
+{
+ my ($data, $server, $witem) = @_;
+ if($data)
+ {
+ $witem->command("/say ".`echo "$data" | conv`);
+ }
+}
+
+Irssi::command_bind('re', 'cmd_re');
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+
+# /xmms2info [some text]
+# shows currently playing sound
+
+use Irssi;
+use strict;
+use vars qw($VERSION %IRSSI);
+use integer;
+use utf8;
+
+$VERSION = "0.0.2";
+%IRSSI = (
+ authors => 'slyfox',
+ name => 'xmm2info',
+ description => 'Shows currently playing by xmms2d sound',
+ license => 'Public Domain'
+);
+
+sub cmd_xmms2info
+{
+ my ($data, $server, $witem) = @_;
+ if($data)
+ {
+ }
+ else
+ {
+ my $text = `~/bin/player-status-entry.py irc`;
+ $witem->command("me $text");
+ }
+}
+
+Irssi::command_bind('xmms2info', 'cmd_xmms2info');
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+
+# /yoda [some text]
+
+use Irssi;
+use strict;
+use vars qw($VERSION %IRSSI);
+use integer;
+use utf8;
+
+$VERSION = "0.0.1";
+%IRSSI = (
+ authors => 'slyfox',
+ name => 'yoda',
+ description => 'reverses words in sentence',
+ license => 'Public Domain'
+);
+
+sub cmd_yoda
+{
+ my ($data, $server, $witem) = @_;
+ if($data)
+ {
+ my $result = join(" ", reverse(split(/\s/, $data)));
+ $witem->command("/say ".$result);
+ }
+}
+
+Irssi::command_bind('yoda', 'cmd_yoda');
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.

0 comments on commit 587c12b

Please sign in to comment.