aboutsummaryrefslogtreecommitdiff
path: root/upsidedown.pl
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-12-26 17:08:34 -0500
committerB. Watson <urchlay@slackware.uk>2024-12-26 17:08:34 -0500
commit9eed830f296dab257759f5276d0963467007aa6b (patch)
tree83d6225d248ec8d4026b514d8b9b248e6c0fce32 /upsidedown.pl
downloadstupid-irssi-tricks-9eed830f296dab257759f5276d0963467007aa6b.tar.gz
initial commit
Diffstat (limited to 'upsidedown.pl')
-rw-r--r--upsidedown.pl242
1 files changed, 242 insertions, 0 deletions
diff --git a/upsidedown.pl b/upsidedown.pl
new file mode 100644
index 0000000..07960d8
--- /dev/null
+++ b/upsidedown.pl
@@ -0,0 +1,242 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Irssi qw/command command_bind/;
+
+our $VERSION = "0.1";
+our %IRSSI = (
+ authors => 'Urchlay',
+ contact => 'Urchlay on FreeNode',
+ name => 'upsidedown',
+ description => '',
+ license => 'WTFPL',
+ url => 'none',
+);
+
+my %flip_table = (
+ "\N{U+0021}" => "\N{U+00A1}",
+ "\N{U+0022}" => "\N{U+201E}",
+ "\N{U+0026}" => "\N{U+214B}",
+ "\N{U+0027}" => "\N{U+002C}",
+ "\N{U+0028}" => "\N{U+0029}",
+ "\N{U+002E}" => "\N{U+02D9}",
+ "\N{U+0033}" => "\N{U+0190}",
+ "\N{U+0034}" => "\N{U+152D}",
+ "\N{U+0036}" => "\N{U+0039}",
+ "\N{U+0037}" => "\N{U+2C62}",
+ "\N{U+003B}" => "\N{U+061B}",
+ "\N{U+003C}" => "\N{U+003E}",
+ "\N{U+003F}" => "\N{U+00BF}",
+ "\N{U+0041}" => "\N{U+2200}",
+ "\N{U+0042}" => "\N{U+10412}",
+ "\N{U+0043}" => "\N{U+2183}",
+ "\N{U+0044}" => "\N{U+25D6}",
+ "\N{U+0045}" => "\N{U+018E}",
+ "\N{U+0046}" => "\N{U+2132}",
+ "\N{U+0047}" => "\N{U+2141}",
+ "\N{U+004A}" => "\N{U+017F}",
+ "\N{U+004B}" => "\N{U+22CA}",
+ "\N{U+004C}" => "\N{U+2142}",
+ "\N{U+004D}" => "\N{U+0057}",
+ "\N{U+004E}" => "\N{U+1D0E}",
+ "\N{U+0050}" => "\N{U+0500}",
+ "\N{U+0051}" => "\N{U+038C}",
+ "\N{U+0052}" => "\N{U+1D1A}",
+ "\N{U+0054}" => "\N{U+22A5}",
+ "\N{U+0055}" => "\N{U+2229}",
+ "\N{U+0056}" => "\N{U+1D27}",
+ "\N{U+0059}" => "\N{U+2144}",
+ "\N{U+005B}" => "\N{U+005D}",
+ "\N{U+005F}" => "\N{U+203E}",
+ "\N{U+0061}" => "\N{U+0250}",
+ "\N{U+0062}" => "\N{U+0071}",
+ "\N{U+0063}" => "\N{U+0254}",
+ "\N{U+0064}" => "\N{U+0070}",
+ "\N{U+0065}" => "\N{U+01DD}",
+ "\N{U+0066}" => "\N{U+025F}",
+ "\N{U+0067}" => "\N{U+0183}",
+ "\N{U+0068}" => "\N{U+0265}",
+ "\N{U+0069}" => "\N{U+0131}",
+ "\N{U+006A}" => "\N{U+027E}",
+ "\N{U+006B}" => "\N{U+029E}",
+ "\N{U+006C}" => "\N{U+0283}",
+ "\N{U+006D}" => "\N{U+026F}",
+ "\N{U+006E}" => "\N{U+0075}",
+ "\N{U+0072}" => "\N{U+0279}",
+ "\N{U+0074}" => "\N{U+0287}",
+ "\N{U+0076}" => "\N{U+028C}",
+ "\N{U+0077}" => "\N{U+028D}",
+ "\N{U+0079}" => "\N{U+028E}",
+ "\N{U+007B}" => "\N{U+007D}",
+ "\N{U+203F}" => "\N{U+2040}",
+ "\N{U+2045}" => "\N{U+2046}",
+ "\N{U+2234}" => "\N{U+2235}",
+ "\N{U+00A1}" => "\N{U+0021}",
+ "\N{U+201E}" => "\N{U+0022}",
+ "\N{U+214B}" => "\N{U+0026}",
+ "\N{U+002C}" => "\N{U+0027}",
+ "\N{U+0029}" => "\N{U+0028}",
+ "\N{U+02D9}" => "\N{U+002E}",
+ "\N{U+0190}" => "\N{U+0033}",
+ "\N{U+152D}" => "\N{U+0034}",
+ "\N{U+0039}" => "\N{U+0036}",
+ "\N{U+2C62}" => "\N{U+0037}",
+ "\N{U+061B}" => "\N{U+003B}",
+ "\N{U+003E}" => "\N{U+003C}",
+ "\N{U+00BF}" => "\N{U+003F}",
+ "\N{U+2200}" => "\N{U+0041}",
+ "\N{U+10412}" => "\N{U+0042}",
+ "\N{U+2183}" => "\N{U+0043}",
+ "\N{U+25D6}" => "\N{U+0044}",
+ "\N{U+018E}" => "\N{U+0045}",
+ "\N{U+2132}" => "\N{U+0046}",
+ "\N{U+2141}" => "\N{U+0047}",
+ "\N{U+017F}" => "\N{U+004A}",
+ "\N{U+22CA}" => "\N{U+004B}",
+ "\N{U+2142}" => "\N{U+004C}",
+ "\N{U+0057}" => "\N{U+004D}",
+ "\N{U+1D0E}" => "\N{U+004E}",
+ "\N{U+0500}" => "\N{U+0050}",
+ "\N{U+038C}" => "\N{U+0051}",
+ "\N{U+1D1A}" => "\N{U+0052}",
+ "\N{U+22A5}" => "\N{U+0054}",
+ "\N{U+2229}" => "\N{U+0055}",
+ "\N{U+1D27}" => "\N{U+0056}",
+ "\N{U+2144}" => "\N{U+0059}",
+ "\N{U+005D}" => "\N{U+005B}",
+ "\N{U+203E}" => "\N{U+005F}",
+ "\N{U+0250}" => "\N{U+0061}",
+ "\N{U+0071}" => "\N{U+0062}",
+ "\N{U+0254}" => "\N{U+0063}",
+ "\N{U+0070}" => "\N{U+0064}",
+ "\N{U+01DD}" => "\N{U+0065}",
+ "\N{U+025F}" => "\N{U+0066}",
+ "\N{U+0183}" => "\N{U+0067}",
+ "\N{U+0265}" => "\N{U+0068}",
+ "\N{U+0131}" => "\N{U+0069}",
+ "\N{U+027E}" => "\N{U+006A}",
+ "\N{U+029E}" => "\N{U+006B}",
+ "\N{U+0283}" => "\N{U+006C}",
+ "\N{U+026F}" => "\N{U+006D}",
+ "\N{U+0075}" => "\N{U+006E}",
+ "\N{U+0279}" => "\N{U+0072}",
+ "\N{U+0287}" => "\N{U+0074}",
+ "\N{U+028C}" => "\N{U+0076}",
+ "\N{U+028D}" => "\N{U+0077}",
+ "\N{U+028E}" => "\N{U+0079}",
+ "\N{U+007D}" => "\N{U+007B}",
+ "\N{U+2040}" => "\N{U+203F}",
+ "\N{U+2046}" => "\N{U+2045}",
+ "\N{U+2235}" => "\N{U+2234}",
+);
+
+# originally from javascript code at
+# https://twiki.org/cgi-bin/view/Blog/BlogEntry201211x1
+# turned into perl and expanded upon somewhat.
+our %mirror_table = (
+ 'A' => 'A',
+ 'B' => "\N{U+A4ED}", #"\N{U+1660}",
+ 'C' => "\N{U+0186}",
+ 'D' => "\N{U+15E1}",
+ 'E' => "\N{U+018E}",
+ 'F' => "\N{U+A7FB}", #"\N{U+15B7}",
+ 'G' => "\N{U+2202}", # "\N{U+13AE}", # need better G
+ 'H' => 'H',
+ 'I' => 'I',
+ 'J' => "\N{U+10B1}", # same as lowercase :(
+ 'K' => "\N{U+A4D8}", # "\N{U+1434}",
+ 'L' => "\N{U+2143}",
+ 'M' => 'M',
+ 'N' => "\N{U+0418}",
+ 'O' => 'O',
+ 'P' => "\N{U+A7FC}", # may be \u146B
+ 'Q' => "O\N{U+0327}", # "\N{U+1ECC}",
+ 'R' => "\N{U+042F}",
+ 'S' => "\N{U+01A7}",
+ 'T' => 'T',
+ 'U' => 'U',
+ 'V' => 'V',
+ 'W' => 'W',
+ 'X' => 'X',
+ 'Y' => 'Y',
+ 'Z' => "\\\N{U+0305}\N{U+0332}", #"\N{U+01B8}",
+ 'a' => "\N{U+0252}",
+ 'b' => 'd',
+ 'c' => "\N{U+0254}",
+ 'd' => 'b',
+ 'e' => "\N{U+0258}",
+ 'f' => "\N{U+0287}",
+ 'g' => "\N{U+01EB}",
+ 'h' => "\N{U+029C}",
+ 'i' => 'i',
+ 'j' => "\N{U+10B1}", # same as uppercase
+ 'k' => "\N{U+029E}",
+ 'l' => "\N{U+222B}", #"\N{U+2321}", # not sure about this one
+ 'm' => 'm',
+ 'n' => 'n',
+ 'o' => 'o',
+ 'p' => 'q',
+ 'q' => 'p',
+ 'r' => "\N{U+027F}", # maybe U+1D19, ᴙ
+ 's' => "\N{U+01A8}",
+ 't' => "\N{U+019A}",
+ 'u' => 'u',
+ 'v' => 'v',
+ 'w' => 'w',
+ 'x' => 'x',
+ 'y' => 'y', # need better y
+ 'z' => 's', # need better z
+ '0' => '0',
+ '1' => '1', # need better 1
+ '2' => '2', # need better 2
+ '3' => "\N{U+01B8}", # or maybe 0664 or 0510
+ '4' => "\N{U+0662}",
+ '5' => '5', # need better 5
+ '6' => "\N{U+2202}",
+ '7' => "\N{U+0393}",
+ '?' => "\N{U+241A}",
+ ';' => "\N{U+204F}",
+ '(' => ')',
+ ')' => '(',
+ '[' => ']',
+ ']' => '[',
+ '<' => '>',
+ '>' => '<',
+ '{' => '}',
+ '}' => '{',
+ '\\' => '/',
+ '/' => '\\',
+ ',' => "\N{U+2E41}",
+ '~' => "\N{U+223D}",
+);
+
+sub mirror {
+ my ($text, $srv, $chan) = @_;
+ return unless $text;
+ return unless $srv;
+ return unless $chan;
+
+ $text = reverse $text;
+ $text =~ s/(.)/$mirror_table{$1}||$1/ge;
+ $chan->command('MSG ' . $chan->{name} . ' ' . $text);
+}
+
+sub flip_rev {
+ my ($text, $srv, $chan) = @_;
+ flip(scalar(reverse $text), $srv, $chan);
+}
+
+sub flip {
+ my ($text, $srv, $chan) = @_;
+ return unless $text;
+ return unless $srv;
+ return unless $chan;
+ $text =~ s/(.)/$flip_table{$1}||$1/ge;
+ $chan->command('MSG ' . $chan->{name} . ' ' . reverse($text));
+}
+
+command_bind("flip", \&flip_rev);
+command_bind("usd", \&flip);
+command_bind("mirror", \&mirror);