Last active
April 7, 2017 12:11
-
-
Save wodim/68005ac44ea0992d6753 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Irssi; | |
use vars qw($VERSION %IRSSI); | |
use strict; | |
use warnings; | |
use Capture::Tiny ':all'; | |
$VERSION = '1.2'; # :D | |
%IRSSI = ( | |
authors => 'Adolf Hitler', | |
contact => '', | |
name => 'toalla', | |
description => 'Spits out a random ToAlla_ sentence', | |
license => 'public domain', | |
url => '', | |
); | |
my @colors = ('0', '4', '8', '9', '11', '12', '13'); | |
sub make_colors { | |
my ($string) = @_; | |
my $newstr = "\x02"; | |
my $last = 255; | |
my $color = 0; | |
$string = Encode::decode_utf8($string); | |
$string =~ s/\x1f|\x02|\x03\d\d?,\d\d?//g; | |
for (my $c = 0; $c < length($string); $c++) { | |
my $char = substr($string, $c, 1); | |
if ($char eq ' ') { | |
$newstr .= $char; | |
next; | |
} | |
while (($color = int(rand(scalar(@colors)))) == $last) {}; | |
$last = $color; | |
$newstr .= "\x03"; | |
if ($char =~ m/[0-9]/) { | |
$newstr .= sprintf("%02d", $colors[$color]); | |
} else { | |
$newstr .= sprintf("%d", $colors[$color]); | |
} | |
# $newstr .= (($char eq ",") ? ",," : $char); | |
$newstr .= $char; | |
} | |
return $newstr; | |
} | |
sub toalla_test { | |
; | |
} | |
sub do_toalla { | |
my ($kind, $args) = @_; | |
my ($filename, $params) = split(' ', $args, 2); | |
$filename = Irssi::get_irssi_dir() . '/scripts/' . $filename; | |
my $text = ''; | |
my ($stderr, $exit); | |
if ($kind eq 'markov') { | |
($text, $stderr, $exit) = capture { | |
system('python3', Irssi::get_irssi_dir() . '/scripts/markov.py', $filename); | |
}; | |
} else { | |
my $fh; | |
if (!open($fh, $filename)) { | |
Irssi::print "No se pudo leer el archivo $filename, fail"; | |
return; | |
} | |
srand; | |
rand($.) < 1 && ($text = $_) while <$fh>; | |
close $fh; | |
} | |
$text =~ s/[\r\n]//g; | |
my $mynick = 'ToAlla_'; | |
my $server = 'IRC-Hispano'; | |
if (Irssi::active_server()) { | |
$mynick = Irssi::active_server()->{nick}; | |
$server = Irssi::active_server()->{tag}; | |
} | |
my $rnick = 'manuÈ'; | |
if (Irssi::active_win->{active}->{type} and | |
Irssi::active_win->{active}->{type} eq 'CHANNEL') { | |
my @nicks = Irssi::active_win->{active}->nicks(); | |
if (scalar @nicks > 1) { | |
my $hash = { mykey => \@nicks }; | |
do { | |
$rnick = $hash->{mykey}[rand(@{$hash->{mykey}})]->{nick}; | |
} while ($rnick eq $mynick); | |
} | |
} | |
my $channel = Irssi::active_win()->{name}; | |
$params =~ s/\s+$//; | |
$text =~ s/\\%1%/, /g; | |
$text =~ s/\\o/SALUDONAZI/g; | |
$text =~ s/\\/, /g; | |
$text =~ s/SALUDONAZI/\\o/g; | |
$text =~ s/%1%|AAAAA/$params/g; | |
$text =~ s/%NICK%|BBBBB/$mynick/g; | |
$text =~ s/%RNICK%|CCCCC/$rnick/g; | |
$text =~ s/%CHAN%|DDDDD/$channel/g; | |
$text =~ s/%NETWORK%|EEEEE/$server/g; | |
$text =~ s/\bde el\b/del/g; | |
$text =~ s/\ba el\b/al/g; | |
$text =~ s/\$//g; | |
$text =~ s/^[=!,]//; | |
#$text = navidad($text); | |
if ($kind eq 'color') { | |
$text = make_colors($text); | |
} | |
if ($text =~ /^\^/) { | |
$text =~ s/\^//; | |
Irssi::active_win()->command("me $text"); | |
} else { | |
Irssi::active_win()->command("say $text"); | |
} | |
} | |
sub navidad { | |
my $text = shift; | |
$text =~ s/\bkolegas arios\b/sonrientes amigos/g; | |
$text =~ s/\bkolega ario\b/sonriente amigo/g; | |
$text =~ s/\bari[oa]s\b/felices/g; | |
$text =~ s/\bari[oa]\b/feliz/g; | |
$text =~ s/\bpoll(ones|as)\b/bombones de crema/g; | |
$text =~ s/\bpollon\b/bombon de crema/g; | |
$text =~ s/\b[kc]ul(ete|o|azo)\b/polvoron/g; | |
$text =~ s/\bmierdas|mojones\b/turrones de suchard/g; | |
$text =~ s/\bmierda|mierdecilla|mojon\b/turron de suchard/g; | |
$text =~ s/\buna\sturron\b/un turron/g; | |
$text =~ s/\bla\sturron\b/el turron/g; | |
$text =~ s/\bla\s[ck]abeza\b/el coco/g; | |
$text =~ s/\b[ck]abeza\b/coco/g; | |
$text =~ s/\b[ck]ara\b/tortilla/g; | |
$text =~ s/\bpalizas\b/golpizas/g; | |
$text =~ s/os\spalizones\b/as golpizas/g; | |
$text =~ s/\bpaliza\b/golpiza/g; | |
$text =~ s/\bel\spalizon\b/la golpiza/g; | |
$text =~ s/moko\sde\spavo/los reyes magos/g; | |
$text =~ s/un\s[ck]ontainer/el trineo de papa noel/; | |
$text =~ s/[ck]ontainer/trineo de papa noel/; | |
$text =~ s/\breventar/triturar/g; | |
$text =~ s/\bmoler/triturar/g; | |
$text =~ s/\bmoliendo/triturando/g; | |
$text =~ s/\b[ck]omer/engullir/g; | |
$text =~ s/\bpuñetazo/besito/g; | |
$text =~ s/\bguantazo/besito/g; | |
$text =~ s/\blas hostias/los besitos/g; | |
$text =~ s/\bla hostia/el besito/g; | |
$text =~ s/\bunas hostias/unos besitos/g; | |
$text =~ s/\buna hostia/un besito/g; | |
$text =~ s/\bhostia/besito/g; | |
$text =~ s/\bhostiones/besitos/g; | |
$text =~ s/\bhostion/besito/g; | |
if ($text !~ /[\?!]$/) { | |
my $rand = int(rand(30)); | |
if ($rand == 0) { | |
$text = "$text bajo el arbolito de navidad"; | |
} elsif ($rand == 1) { | |
$text = "$text con espiritu navideño"; | |
} elsif ($rand == 2) { | |
$text = "$text con paz y amor"; | |
} elsif ($rand == 3) { | |
$text = "$text en el portal de belen"; | |
} | |
} | |
$text; | |
} | |
Irssi::command_bind("do_toalla" => sub { do_toalla('nocolor', @_) }); | |
Irssi::command_bind("do_c_toalla" => sub { do_toalla('color', @_) }); | |
Irssi::command_bind("do_m_toalla" => sub { do_toalla('markov', @_) }); | |
Irssi::command_bind("_toalla_test", "toalla_test") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment