Last active
August 29, 2015 13:57
-
-
Save toritori0318/9691288 to your computer and use it in GitHub Desktop.
ikachanでメッセージをカラフルにするラッパー
This file contains hidden or 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
# example: | |
# perl ikachan_color_notice.pl ikachan-server.com \#main '%{red:hoge}%fuga%{yellow:piyo}%e' | |
# screenshot: | |
# http://gyazo.com/b7cb0bc5013b724d6ddbb9bf983a8ffa | |
use strict; | |
use warnings; | |
use LWP::UserAgent; | |
my $usage = 'usage: ikachan_color_notice.pl <host> <channel> <message>'; | |
my $host = shift or die $usage; | |
my $channel = shift or die $usage; | |
my $message = shift or die $usage; | |
sub convert_irc_color { | |
my ($color, $message) = @_; | |
my $color_code; | |
if($color eq 'write') { $color_code = '00'; } | |
elsif($color eq 'black') { $color_code = '01'; } | |
elsif($color eq 'blue') { $color_code = '02'; } | |
elsif($color eq 'green') { $color_code = '03'; } | |
elsif($color eq 'red') { $color_code = '04'; } | |
elsif($color eq 'brown') { $color_code = '05'; } | |
elsif($color eq 'purple') { $color_code = '06'; } | |
elsif($color eq 'orange') { $color_code = '07'; } | |
elsif($color eq 'yellow') { $color_code = '08'; } | |
elsif($color eq 'light green') { $color_code = '09'; } | |
elsif($color eq 'teal') { $color_code = '10'; } | |
elsif($color eq 'light cyan') { $color_code = '11'; } | |
elsif($color eq 'light blue') { $color_code = '12'; } | |
elsif($color eq 'pink') { $color_code = '13'; } | |
elsif($color eq 'grey') { $color_code = '14'; } | |
elsif($color eq 'light grey') { $color_code = '15'; } | |
else { return $message } | |
return "\x02\x0301,${color_code}${message}\x0f"; | |
} | |
# 色付きにするための置換 | |
# %{<color>:<message>}% | |
$message =~ s/%{([^:]+):([^}%]+)}%/{convert_irc_color($1,$2)}/eg; | |
my $ua = LWP::UserAgent->new; | |
my $response = $ua->post("http://$host/notice", { | |
'channel' => $channel, | |
'message' => $message, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment