view release on metacpan or search on metacpan
lib/Bot/Cobalt/Plugin/Extras/CPAN.pm view on Meta::CPAN
unless ($d_hash && ref $d_hash eq 'HASH') {
broadcast( 'message',
$hints->{Context}, $hints->{Channel},
"thaw failure for $dist; expected a HASH but got '$d_hash'"
);
return PLUGIN_EAT_ALL
}
my $resp;
my $prefix = color bold => 'mCPAN';
TYPE: {
if ($type eq 'abstract') {
my $abs = $d_hash->{abstract} || 'No abstract available.';
my $vers = $d_hash->{version};
$resp = "$prefix: ($dist $vers) $abs ; $link";
last TYPE
}
lib/Bot/Cobalt/Plugin/Extras/TempConv.pm view on Meta::CPAN
( ($f, $k, $c) = ( _c2f($temp), _c2k($temp), $temp ) and last )
if $upper eq 'C';
( ($f, $k, $c) = ( _k2f($temp), $temp, _k2c($temp) ) and last )
if $upper eq 'K';
}
$_ = sprintf("%.2f", $_) for ($f, $k, $c);
my $resp = color( 'bold', "(${f}F)" )
. " == " .
color( 'bold', "(${c}C)" )
. " == " .
color( 'bold', "(${k}K)" );
my $channel = $msg->channel;
$core->send_event( 'message', $context, $channel, $resp );
return PLUGIN_EAT_ALL
}
## Conversion functions:
sub _f2c { (shift(@_) - 32 ) * (5/9) }
lib/Bot/Cobalt/Plugin/Games/Dice.pm view on Meta::CPAN
$modifier = undef unless $modify_by and $modify_by =~ /^\d+$/;
if ($modifier) {
$modifier eq '+' ? $total += $modify_by
: $modifier eq '-' ? $total -= $modify_by
: ()
}
my $resp = "Rolled "
.color('bold', $n_dice)
.($sides > 1 ? ' dice of ' : ' die of ')
.color('bold', $sides)
." sides: " . join ' ', @rolls;
my $potential = $n_dice * $sides;
$resp .= " [total: ".color('bold', $total)." / $potential]";
return $resp
}
if ($dice =~ /^\d+$/) {
my $total = (int rand $dice) + 1;
$modifier = undef unless $modify_by and $modify_by =~ /^\d+$/;
if ($modifier) {
$modifier eq '+' ? $total += $modify_by
: $modifier eq '-' ? $total -= $modify_by
: ()
}
my $resp = "Rolled single die of "
.color('bold', $dice)
." sides: "
.color('bold', $total) ;
return $resp
}
"Syntax: roll XdY [ +/- <modifier> ]"
}
1;
__END__
=pod
lib/Bot/Cobalt/Plugin/Games/Roulette.pm view on Meta::CPAN
my $irc = core->get_irc_obj($context);
my $bot = $irc->nick_name;
my $chan = $msg->channel;
if ( $irc->is_channel_operator($chan, $bot)
|| $irc->is_channel_admin($chan, $bot)
|| $irc->is_channel_owner($chan, $bot) ) {
broadcast( 'kick', $context, $chan, $nick, "BANG!" );
}
return color bold => 'BANG! ' . _suicide($nick)
}
--$self->{$context}->{$nick}->{Loaded};
return "${nick}: Click . . ."
}
sub expire {
my ($self) = @_;
for my $context (keys %$self) {
lib/Bot/Cobalt/Plugin/OutputFilters/StripColor.pm view on Meta::CPAN
!plugin load StripColor Bot::Cobalt::Plugin::OutputFilters::StripColor
=head1 DESCRIPTION
Cobalt output filter plugin.
Strips color codes from any outgoing IRC messages (including actions and
notices).
Does not strip formatting (bold, underline, ...); see
L<Bot::Cobalt::Plugin::OutputFilters::StripFormat>
=head1 AUTHOR
Jon Portnoy <avenj@cobaltirc.org>
L<http://www.cobaltirc.org>
=cut
lib/Bot/Cobalt/Plugin/OutputFilters/StripFormat.pm view on Meta::CPAN
return PLUGIN_EAT_NONE
}
1;
__END__
=pod
=head1 NAME
Bot::Cobalt::Plugin::OutputFilters::StripFormat - strip bold/underline/italics
=head1 SYNOPSIS
!plugin load StripFormat Bot::Cobalt::Plugin::OutputFilters::StripFormat
=head1 DESCRIPTION
Cobalt output filter plugin.
Strips any formatting codes from outgoing messages, such as bold, underline,
reverse, etc.
Does not strip color codes; see L<Bot::Cobalt::Plugin::OutputFilters::StripColor>
=head1 AUTHOR
Jon Portnoy <avenj@cobaltirc.org>
L<http://www.cobaltirc.org>
lib/Bot/Cobalt/Utils.pm view on Meta::CPAN
$re
}
## IRC color codes:
sub color ($;$) {
## color($format, $str)
## implements mirc formatting codes, against my better judgement
## if format is unspecified, returns NORMAL
## interpolate bold, reset to NORMAL after:
## $str = color('bold') . "Text" . color;
## -or-
## format specified strings, resetting NORMAL after:
## $str = color('bold', "Some text"); # bold text ending in normal
my ($format, $str) = @_;
$format = uc($format||'normal');
my $selected = $COLORS{$format};
carp "Invalid COLOR $format passed to color()"
unless $selected;
return $selected . $str . $COLORS{NORMAL} if $str;
lib/Bot/Cobalt/Utils.pm view on Meta::CPAN
WHITE BLACK BLUE GREEN RED BROWN PURPLE ORANGE YELLOW TEAL PINK
LIGHT_CYAN LIGHT_BLUE LIGHT_GRAY LIGHT_GREEN
Format/color type can be passed in upper or lower case.
If passed just a color or format name, returns the control code.
If passed nothing at all, returns the 'NORMAL' reset code:
my $str = color('bold') . "bold text" . color() . "normal text";
If passed a color or format name and a string, returns the formatted
string, terminated by NORMAL:
my $formatted = color('red', "red text") . "normal text";
If you need to retrieve (or alter via C<local>, for example) the actual
control characters themselves, they are accessible via the C<<
%Bot::Cobalt::Utils::COLORS >> hash:
share/etc/plugins.conf view on Meta::CPAN
####################### Output Filters #######################
## Loading an output filter alters outgoing messages from the bot.
## These examples have NoAutoLoad specified.
StripColor:
## Strip any color in outgoing messages
NoAutoLoad: 1
Module: Bot::Cobalt::Plugin::OutputFilters::StripColor
StripFormat:
## Strip bold/underline/etc format codes from outgoing messages.
NoAutoLoad: 1
Module: Bot::Cobalt::Plugin::OutputFilters::StripFormat
##############################################################
# End of core set.
##############################################################
### You could define your own set of plugins here.
### In theory, they should live somewhere under Bot::Cobalt::Plugin::
t/01_utils/02_rplprintf.t view on Meta::CPAN
ok($formatted = rplprintf( $tmpl, $vars ), 'rplprintf format str');
ok($formatted eq $expect, 'compare formatted str');
undef $formatted;
ok($formatted = rplprintf( $tmpl, %$vars ), 'rplprintf passed list' );
ok($formatted eq $expect, 'compare formatted str (list-style args)');
undef $formatted;
undef $tmpl;
my $c_vars = {
somebold => "Some bold text",
};
$tmpl = 'String %C_BOLD %somebold %C_NORMAL%normal text %C_BLUE colored';
ok($formatted = rplprintf( $tmpl, $c_vars ), 'rplprintf C_ vars (ref)' );
ok( has_formatting($formatted), 'rplprintf C_ vars has_formatting' );
ok( has_color($formatted), 'rplprintf C_ vars has_color' );
t/01_utils/05_color.t view on Meta::CPAN
BEGIN {
use_ok( 'Bot::Cobalt::Utils', qw/
color
/ );
}
use IRC::Utils qw/has_color has_formatting/;
my $format;
ok(
$format = color('bold')
. "Bold text"
. color('teal')
. "Teal text"
. color('normal'),
"Format string: bold, teal"
);
ok( has_formatting($format), "color() string has formatting" );
ok( has_color($format), "color() string has color" );
{
my $warning;
local $SIG{__WARN__} = sub { $warning = $_[0] };
$format = color('foo') . "Some text";
like $warning, qr/invalid color/i, 'bad format warned';