Attachment 'ulatrus.pl'

Download

   1 # ulatrus.pl                             ru_RU.UTF-8 description
   2 # to run it if it is here:               Запуск скрипта командой:
   3 #
   4 # /script load ~/.irssi/scripts/ulatrus.pl
   5 #
   6 # you can simply remove the script:      Выгружается скрипт командой:
   7 # /script unload ulatrus
   8 #
   9 #######################################  ######################################
  10 # Script work in UTF-8!                  Скрипт работает в UTF-8!
  11 # 66 symbols are rusificated.            русифицирует 66 символов.
  12 # russian characters in windows-1251     Русские буквы в Windows-1251
  13 # are misinterpreted (by bitlbee) as     интерпретированные как ISO-8859-1
  14 # ISO-8859-1 and are placed to accented  и помещённые в уникодовскую страницу
  15 # european unicode page. This script     с европейскими акцентами. Эта
  16 # returns them to russian page, keeping  программа возвращает их в русскую
  17 # all other characters untouched.        страницу уникода, не трогая остальных.
  18 #--------------------------------------  --------------------------------------
  19 # you also can:                          Также вы можете:
  20 # Turn conversion on/off separately:     вкл/выкл преобразование отдельно для:
  21 #/set ulatrus_strip_in  <ON|off> -- входящих (по умолчанию вкл)
  22 #/set ulatrus_strip_out <on|OFF> -- исходящих (по умолчанию выкл)
  23 #
  24 # Change tag for converted strings:      Изменить пометку преобразованного:
  25 #/set ulatrus_tag_in  <string, default: [ulatrus]> входящих.
  26 #/set ulatrus_tag_out <string, default: [ulatrus]> исходящих.
  27 #
  28 # Change table of conversion:           Изменить таблицу преобразования:
  29 #/set ulatrus_lat <string> what         какие символы конвертировать
  30 # default: "ÀÁÂÃÄŨÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäå¸æçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
  31 #/set ulatrus_rus <string> to what      в какие символы конвертировать
  32 # default: "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя"
  33 #
  34 # Turn on/off debugging:                Вкл/выкл отладочную печать:
  35 #/set ulatrus_debug <on|off> -- if you have a problem try to turn this on
  36 
  37 use strict;
  38 use vars qw($VERSION %IRSSI);
  39 
  40 use utf8;
  41 use Encode qw(encode decode is_utf8);
  42 use encoding 'UTF-8', STDOUT => 'UTF-8', STDIN => 'UTF-8';
  43 
  44 use Irssi;
  45 $VERSION = '$Id: ulatrus.pl,v 1.00 2011/09/12 19:20:00 Sergej Qkowlew $';
  46 %IRSSI = (
  47 	authors     => 'Sergej Qkowlew',
  48 	contact     => 'sergej_at_irssi_qkowlew1@qkowlew.org',
  49 	name        => 'ulatrus',
  50 	description => 'Script Changes latin1 ÀÁÂÃÄŨÆ...þÿ to russian АБВГДЕЁ...юя UTF-8',
  51 	license     => 'GPL',
  52 );
  53 
  54 my $stripped_out = 0;
  55 my $stripped_in  = 0;
  56 
  57 sub ulatrus_out {
  58 	if(Irssi::settings_get_bool('ulatrus_strip_out') && !$stripped_out) {
  59 		my $ulatrus_tag = Irssi::settings_get_str('ulatrus_tag_out');
  60 
  61 		my $debug=Irssi::settings_get_bool('ulatrus_debug');
  62 		
  63 		my $ulatrus_lat = Irssi::settings_get_str('ulatrus_lat');
  64 		my $ulatrus_rus = Irssi::settings_get_str('ulatrus_rus');
  65 		if (length($ulatrus_lat) != length($ulatrus_rus)) {
  66 			if ($debug) {
  67 				Irssi::print("`$ulatrus_lat' and `$ulatrus_rus' hasn't same length");
  68 			}
  69 		}
  70 		else {
  71 			my $emitted_signal = Irssi::signal_get_emitted();
  72 			my ($msg, $dummy1, $dummy2) = @_;
  73 
  74 			if ($debug) {
  75 				Irssi::print("signal emitted: $emitted_signal");
  76 			}
  77 			Encode::_utf8_on($msg);
  78 			if ( $msg =~ /[$ulatrus_lat]/ ) {
  79 				if ($debug) {
  80 					Irssi::print("outgoing contains ulatrus: $msg");
  81 				}
  82 				eval "\$msg =~ tr/$ulatrus_lat/$ulatrus_rus/;";
  83 				Encode::_utf8_on($msg);
  84 				$msg = $msg . ' ' . $ulatrus_tag;
  85 				Encode::_utf8_on($msg);
  86 				$stripped_out=1;
  87 				
  88 				Irssi::signal_emit("$emitted_signal", $msg, $dummy1, $dummy2 );
  89 				Irssi::signal_stop();
  90 				$stripped_out=0;
  91 			}
  92 		}
  93 	}
  94 }
  95 
  96 sub ulatrus_in {
  97 	if(Irssi::settings_get_bool('ulatrus_strip_in') && !$stripped_in) {
  98 		my $ulatrus_tag = Irssi::settings_get_str('ulatrus_tag_in');
  99 
 100 		my $debug=Irssi::settings_get_bool('ulatrus_debug');
 101 		
 102 		my $ulatrus_lat = Irssi::settings_get_str('ulatrus_lat');
 103 		my $ulatrus_rus = Irssi::settings_get_str('ulatrus_rus');
 104 		if (length($ulatrus_lat) != length($ulatrus_rus)) {
 105 			if ($debug) {
 106 				Irssi::print("`$ulatrus_lat' and `$ulatrus_rus' hasn't same length");
 107 			}
 108 		}
 109 		else {
 110 			my $emitted_signal = Irssi::signal_get_emitted();
 111 
 112 			my ($dummy0, $text, $dummy3, $dummy4, $dummy5) = @_;
 113 			if ($debug) {
 114 				Irssi::print("signal emitted: $emitted_signal");
 115 			}
 116 			Encode::_utf8_on($text);
 117 			if ( $text =~ /[$ulatrus_lat]/ ) {
 118 				if ($debug) {
 119 					Irssi::print("incoming contains ulatrus: $text");
 120 				}
 121 				if ($debug) {
 122 					Irssi::print("text=$text");
 123 				}
 124 				#no idea why w/o eval doesn't work:
 125 				eval "\$text =~ tr/$ulatrus_lat/$ulatrus_rus/;";
 126 				Encode::_utf8_on($text);
 127 				$text = $text . ' ' . $ulatrus_tag;
 128 				Encode::_utf8_on($text);
 129 				$stripped_in=1;
 130 
 131 				if ($debug) {
 132 					Irssi::print("text=$text");
 133 				}
 134 				Irssi::signal_emit("$emitted_signal", $dummy0, $text, $dummy3, $dummy4, $dummy5 );
 135 				Irssi::signal_stop();
 136 				$stripped_in=0;
 137 			}
 138 		}
 139 	}
 140 }
 141 
 142 #main():
 143 
 144 #default settings /set ulatrus_in ON && ulatrus_out OFF:
 145 Irssi::settings_add_bool('lookandfeel', 'ulatrus_strip_in', 1);
 146 Irssi::settings_add_bool('lookandfeel', 'ulatrus_strip_out', 0);
 147 
 148 #define the default tags for the filtered text:
 149 Irssi::settings_add_str('lookandfeel', 'ulatrus_tag_in', '[ulatrus]');
 150 Irssi::settings_add_str('lookandfeel', 'ulatrus_tag_out', '[ulatrus]');
 151 
 152 #define which chars will be changed:
 153 Irssi::settings_add_str('lookandfeel', 'ulatrus_lat', "ÀÁÂÃÄŨÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäå¸æçèéêëìíîïðñòóôõö÷øùúûüýþÿ");
 154 Irssi::settings_add_str('lookandfeel', 'ulatrus_rus', "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя");
 155 
 156 #define wheather debug or not (default OFF):
 157 Irssi::settings_add_bool('lookandfeel', 'ulatrus_debug', 0);
 158 
 159 #filters:
 160 #incoming filters:
 161 Irssi::signal_add_first('server event', 'ulatrus_in');
 162 
 163 #output filters:
 164 Irssi::signal_add_first('send command', 'ulatrus_out');
 165 #Irssi::signal_add_first('message own_public', 'ulatrus_out');
 166 #Irssi::signal_add_first('message own_private', 'ulatrus_out');
 167 
 168 #startup info:
 169 Irssi::print("latin1 to cp1251 unicode stripper by Qkowlew based on accent.pl by Tamas SZERB toma\@rulez.org");
 170 Irssi::print("Version: $VERSION");

New Attachment

File to upload
Rename to
Overwrite existing attachment of same name
What's the /topic of the &bitlbee channel? (Or at least the first sentence. Sorry, the spammers figured out previous textchas and I'm tired of hosting payday loan websites..)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2011-09-12 16:16:18, 6.8 KB) [[attachment:ulatrus.pl]]
 All files | Selected Files: delete move to page copy to page