html/kenny.pl


   1 # (c) 2002 by Gerfried Fuchs <alfie@channel.debian.de>
   2 
   3 use Irssi qw(command_bind command signal_add_last signal_stop settings_get_bool settings_add_bool);
   4 use strict;
   5 use vars qw($VERSION %IRSSI);
   6 
   7 $VERSION = '2.3.1';
   8 
   9 %IRSSI = (
  10   'authors'     => 'Gerfried Fuchs',
  11   'contact'     => 'alfie@channel.debian.de',
  12   'name'        => 'kenny speech',
  13   'description' => 'autodekennyfies /kenny, adds /kenny, /dekenny. Based on Jan-Pieter Cornets signature version',
  14   'license'     => 'BSD',
  15   'url'         => 'http://alfie.ist.org/projects/irssi/scripts/kenny.pl',
  16   'changed'     => '2002-06-13',
  17 );
  18 
  19 # Maintainer & original Author:  Gerfried Fuchs <alfie@channel.debian.de>
  20 # Based on signature kenny from: Jan-Pieter Cornet <johnpc@xs4all.nl>
  21 # Autodekenny-suggestion:        BC-bd <bd@bc-bd.org>
  22 
  23 # Sugguestions from darix: Add <$nick> to [kenny] line patch
  24 
  25 # This script offers you /kenny and /dekenny which both do the kenny-filter
  26 # magic on the argument you give it.  Despite it's name *both* do kenny/dekenny
  27 # the argument; the difference is that /kenny writes it to the channel/query
  28 # but /dekenny only to your screen.
  29 
  30 # Version-History:
  31 # ================
  32 # 2.3.1 -- fixed autodekenny in channels for people != yourself
  33 #
  34 # 2.3.0 -- fixed kenny in querys
  35 #          fixed dekenny in status window
  36 #
  37 # 2.2.3 -- fixed pattern matching for autokenny string ("\w" != "a-z" :/)
  38 #
  39 # 2.2.2 -- first version available to track history from...
  40 
  41 # TODO List
  42 # ... currently empty
  43 
  44 
  45 sub KennyIt {
  46    ($_)=@_;my($p,$f);$p=3-2*/[^\W\dmpf_]/i;s.[a-z]{$p}.vec($f=join('',$p-1?chr(
  47       sub{$_[0]*9+$_[1]*3+$_[2] }->(map {/p|f/i+/f/i}split//,$&)+97):('m','p','f')
  48       [map{((ord$&)%32-1)/$_%3}(9, 3,1)]),5,1)='`'lt$&;$f.eig;return ($_);
  49 };
  50 
  51 
  52 sub cmd_kenny {
  53    my ($msg, undef, $channel) = @_;
  54    $channel->command("msg $channel->{'name'} ".KennyIt($msg));
  55 }
  56 
  57 
  58 sub cmd_dekenny {
  59    my ($msg, undef, $channel) = @_;
  60 
  61    if ($channel) {
  62       $channel->print('[kenny] '.KennyIt($msg), MSGLEVEL_CRAP);
  63    } else {
  64       Irssi::print('[kenny] '.KennyIt($msg), MSGLEVEL_CRAP);
  65    }
  66 }
  67 
  68 
  69 sub sig_kenny {
  70    my ($server, $msg, $nick, $address, $target) = @_;
  71    if ($msg=~m/^[^a-z]*[mfp]{3}(?:[^a-z]|[mfp]{3})+$/i) {
  72       $target=$nick if $target eq "";
  73 
  74       # the address may _never_ be emtpy, if it is its own_public
  75       $nick=$server->{'nick'} if $address eq "";
  76 
  77       $server->window_item_find($target)->print("[kenny] <$nick> " .
  78                                                 KennyIt($msg), MSGLEVEL_CRAP);
  79       signal_stop if not settings_get_bool('show_kenny_too');
  80    }
  81 }
  82 
  83 
  84 command_bind('kenny',   'cmd_kenny');
  85 command_bind('dekenny', 'cmd_dekenny');
  86 
  87 signal_add_last('message own_public',  'sig_kenny');
  88 signal_add_last('message public',      'sig_kenny');
  89 signal_add_last('message own_private', 'sig_kenny');
  90 signal_add_last('message private',     'sig_kenny');
  91 
  92 settings_add_bool('lookandfeel', 'show_kenny_too', 0);