Skip to content

Commit

Permalink
add max-length option
Browse files Browse the repository at this point in the history
  • Loading branch information
kazeburo committed Mar 17, 2014
1 parent b04b381 commit d913f60
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions script/ikachan
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ my $parser = Getopt::Long::Parser->new(
);

my %options;
my($http_host, $http_port, $irc_server, $irc_port, $irc_keyword, $irc_nickname, $irc_user, $no_post_with_join, $irc_post_interval, $irc_reconnect_interval, $enable_ssl, $mount) =
('127.0.0.1', 4979, undef, 6667, undef, 'ikachan', undef, 0, 2, 3, 0, '');
my($http_host, $http_port, $irc_server, $irc_port, $irc_keyword, $irc_nickname, $irc_user, $no_post_with_join, $irc_post_interval, $irc_reconnect_interval, $enable_ssl, $mount, $max_length) =
('127.0.0.1', 4979, undef, 6667, undef, 'ikachan', undef, 0, 2, 3, 0, '', 0);
my @reverse_proxy;
$parser->getoptions(
'o|host=s' => \$http_host,
Expand All @@ -40,6 +40,7 @@ $parser->getoptions(
'enable-ssl' => \$enable_ssl,
'R|reconnect-interval=s' => \$irc_reconnect_interval,
'j|no-post-with-join' => \$no_post_with_join,
'l|max-length=i' => \$max_length,
'h|help' => \$options{help},
'v|version' => \$options{version},
);
Expand Down Expand Up @@ -106,6 +107,12 @@ sub join_channel {
};
}

sub truncate_message {
my ($message,$max_length) = @_;
return $message if ! $max_length;
substr($message, 0, $max_length)
}

my $code = sub {
my $req = Plack::Request->new(shift);
my $method = $req->method;
Expand Down Expand Up @@ -245,7 +252,7 @@ HTML
} elsif (not $join_channels->{$channel}) {
join_channel($channel);
}
my $message = $req->param('message');
my $message = truncate_message($req->param('message'), $max_length);
$irc->send_message( $message, channel => $channel );
return rendar(200, "message sent channel: $channel $message");
} elsif ($path eq '/privmsg') {
Expand All @@ -254,7 +261,7 @@ HTML
} elsif (not $join_channels->{$channel}) {
join_channel($channel);
}
my $message = $req->param('message');
my $message = truncate_message($req->param('message'), $max_length);
$irc->send_message( $message, channel => $channel, privmsg => 1 );
return rendar(200, "message sent channel: $channel $message");
}
Expand Down Expand Up @@ -6521,6 +6528,10 @@ disable to irc message post with channel join
provide TCP based server daemon with path. Default do nothing.
=item -l, --max-length
truncate message after a given length. Do not truncate by default.
=back
=head1 AUTHOR
Expand Down

0 comments on commit d913f60

Please sign in to comment.