Last active
December 11, 2017 20:27
-
-
Save json-m/ef0b23124138fc935186ad31c47e82a6 to your computer and use it in GitHub Desktop.
annoy everyone with ocd on irc
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 warnings; | |
use strict; | |
use IPC::Open3; | |
use Irssi; | |
use vars qw($VERSION %IRSSI); | |
$VERSION = '0.1'; | |
%IRSSI = ( | |
author => 'c|p', | |
name => 'h-ify', | |
description => 'applies bold formatting to every h' | |
); | |
sub sig_send_text | |
{ | |
my ($args, $server, $witem) = @_; | |
my $channel = Irssi::active_win()->get_active_name(); | |
if (Irssi::settings_get_bool('hify_enabled')) { | |
Irssi::signal_stop(); | |
$args =~ s/(h+)/\x02$1\x02/gi; | |
Irssi::signal_continue($args, $server, $witem); | |
} | |
} | |
sub cmd_hexec | |
{ | |
my ($args, $server, $witem) = @_; | |
my $target = $witem->{name}; | |
my $pid = open3(\*WRITE, \*READ, \*ERR, $args); | |
close WRITE; | |
my $text = join('', <READ>); | |
close READ; | |
close ERR; | |
waitpid($pid, 0); | |
for my $line (split(/\n/, $text)) { | |
$line = ' ' if $line eq ''; | |
$line =~ s/(h+)/\x02$1\x02/gi; | |
$witem->command("msg $target $line"); | |
} | |
} | |
Irssi::settings_add_bool('hify', 'hify_enabled', 0); | |
Irssi::signal_add_first('send text', \&sig_send_text); | |
Irssi::command_bind('hexec', 'cmd_hexec'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment