| 1 | package POE::Component::IRC::Plugin::WubWubWub; | ||
| 2 | |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 0 | ▶ | use POE::Component::IRC::Plugin qw(:ALL); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 6 | |||
| 7 | sub new { | ||
| 8 | my $package = shift; | ||
| 9 | my $args = shift; | ||
| 10 | my $self = { | ||
| 11 | threshold => 0.5, #Threshold to limit unnecessary wubs. | ||
| 12 | period => 30, #A time period to rate limit wubs. | ||
| 13 | last_wub => 0, | ||
| 14 | max_wubs => 20, #maximum amount of wubs in one message | ||
| 15 | min_wubs => 5, #minimum amount of wubs in one message. | ||
| 16 | wub_str => "WUB", #wubstr | ||
| 17 | }; | ||
| 18 | $self->{threshold} ||= $args->{threshold}; | ||
| 19 | $self->{threshold} = 0.5 if $self->{threshold} >= 1 or $self->{threshold} <= 0; #sanity check lol. | ||
| 20 | $self->{period} ||= $args->{period}; | ||
| 21 | $self->{period} = 30 if $self->{period} <= 0; #same | ||
| 22 | $self->{max_wubs} ||= $args->{max_wubs}; | ||
| 23 | $self->{max_wubs} = 20 if $self->{max_wubs} <= 0; #same, chap. | ||
| 24 | $self->{min_wubs} ||= $args->{min_wubs}; | ||
| 25 | $self->{min_wubs} = 5 if $self->{min_wubs} <= 0; #no sense in having 0 as minimum amirite | ||
| 26 | $self->{min_wubs} = $self->{max_wubs} - 1 if $self->{min_wubs} > $self->{max_wubs}; #don't want minimum > maximum | ||
| 27 | $self->{max_wubs} = $self->{min_wubs} + 5 if $self->{min_wubs} > $self->{max_wubs}; #same except different. | ||
| 28 | $self->{wub_str} ||= $args->{wub_str}; | ||
| 29 | return bless $self, $package; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub S_public { | ||
| 33 | my($self, $irc) = splice @_, 0, 2; | ||
| 34 | my $channel = ${ $_[0] }->[0]; | ||
| 35 | my $cur_time = time; | ||
| 36 | my $old_time = $self->{last_wub}; | ||
| 37 | my $chance = rand; | ||
| 38 | my $retval = PCI_EAT_NONE; | ||
| 39 | if($cur_time - $old_time > $self->{period} && | ||
| 40 | $chance > $self->{threshold}) { | ||
| 41 | my $repetitions = (int rand($self->{max_wubs}-$self->{min_wubs})+$self->{min_wubs}); | ||
| 42 | my $wubstr = $self->{wub_str}x$repetitions; | ||
| 43 | $irc->yield(privmsg => $channel => $wubstr); | ||
| 44 | $self->{last_wub} = time; | ||
| 45 | $retval = PCI_EAT_PLUGIN; | ||
| 46 | } | ||
| 47 | |||
| 48 | return $retval; | ||
| 49 | } | ||
| 50 | |||
| 51 | 1; | ||
| 52 | |||
| 53 | |||
| 54 | =head1 NAME | ||
| 55 | |||
| 56 | POE::Component::IRC::Plugin::WubWubWub - Wubbalize your IRC bots! | ||
| 57 | |||
| 58 | =head1 VERSION | ||
| 59 | |||
| 60 | Version 0.1 | ||
| 61 | |||
| 62 | =cut | ||
| 63 | |||
| 64 | our $VERSION = '0.1'; | ||
| 65 | |||
| 66 | |||
| 67 | =head1 SYNOPSIS | ||
| 68 | |||
| 69 | This plugin was designed to make your IRC bots 1000x cooler by integrating | ||
| 70 | this strange phenomenon referred to as dubstep into them. The manner in | ||
| 71 | which it achieves this, is of course, by randomly WUBBING into your chat rooms! | ||
| 72 | |||
| 73 | use POE::Component::IRC; | ||
| 74 | use POE::Component::IRC::Plugin::WubWubWub; | ||
| 75 | |||
| 76 | my $WubWubWub = POE::Component::IRC::Plugin::WubWubWub->new({ | ||
| 77 | #options, documented below | ||
| 78 | }); | ||
| 79 | $irc->plugin_add( 'WubWubWub', $WubWubWUb ); | ||
| 80 | ... | ||
| 81 | |||
| 82 | =head1 METHODS | ||
| 83 | |||
| 84 | =over 4 | ||
| 85 | |||
| 86 | =item B<new> | ||
| 87 | |||
| 88 | Creates a new WubWubWub object. View the arguments below to grok everything | ||
| 89 | you could ever need to know. Calling syntax expects a hashref of arguments. | ||
| 90 | |||
| 91 | =back | ||
| 92 | |||
| 93 | =head1 ARGUMENTS | ||
| 94 | |||
| 95 | =over 4 | ||
| 96 | |||
| 97 | =item B<threshold> | ||
| 98 | |||
| 99 | A threshold at which, when exceeded, will tell your bot it's okay to wub. | ||
| 100 | Defaults to 0.5; should be 0 < threshold < 1. | ||
| 101 | |||
| 102 | =item B<period> | ||
| 103 | |||
| 104 | A rate limiting mechanism in seconds; if the bot detects that it's been | ||
| 105 | less than the amount of seconds you specify, it'll stay quiet, | ||
| 106 | Defaults to 30 seconds. | ||
| 107 | |||
| 108 | =item B<min_wubs> | ||
| 109 | |||
| 110 | The minimum amount of wubs to send at any given moment when wubs are to be sent! | ||
| 111 | Defaults to be 5. Should be 0 < min_wubs < max_wubs | ||
| 112 | |||
| 113 | =item B<max_wubs> | ||
| 114 | |||
| 115 | The maximum amount of wubs to send at any given moment when wubs are to be sent! | ||
| 116 | Defaults to be 20. Should be max_wubs > min_wubs > 0. | ||
| 117 | |||
| 118 | =item B<wub_str> | ||
| 119 | |||
| 120 | The string to emit to the channel. Defaults to WUB. | ||
| 121 | |||
| 122 | =back | ||
| 123 | |||
| 124 | =head1 AUTHOR | ||
| 125 | |||
| 126 | Gary Warman, C<< <sirmxe at cpan.org> >> | ||
| 127 | |||
| 128 | =head1 BUGS | ||
| 129 | |||
| 130 | Please report any bugs or feature requests to C<bug-poe-component-irc-plugin-wubwubwub at rt.cpan.org>, or through | ||
| 131 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Component-IRC-Plugin-WubWubWub>. I will be notified, and then you'll | ||
| 132 | automatically be notified of progress on your bug as I make changes. | ||
| 133 | |||
| 134 | |||
| 135 | |||
| 136 | =head1 SUPPORT | ||
| 137 | |||
| 138 | You can find documentation for this module with the perldoc command. | ||
| 139 | |||
| 140 | perldoc POE::Component::IRC::Plugin::WubWubWub | ||
| 141 | |||
| 142 | |||
| 143 | You can also look for information at: | ||
| 144 | |||
| 145 | =over 4 | ||
| 146 | |||
| 147 | =item * RT: CPAN's request tracker | ||
| 148 | |||
| 149 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-IRC-Plugin-WubWubWub> | ||
| 150 | |||
| 151 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 152 | |||
| 153 | L<http://annocpan.org/dist/POE-Component-IRC-Plugin-WubWubWub> | ||
| 154 | |||
| 155 | =item * CPAN Ratings | ||
| 156 | |||
| 157 | L<http://cpanratings.perl.org/d/POE-Component-IRC-Plugin-WubWubWub> | ||
| 158 | |||
| 159 | =item * Search CPAN | ||
| 160 | |||
| 161 | L<http://search.cpan.org/dist/POE-Component-IRC-Plugin-WubWubWub/> | ||
| 162 | |||
| 163 | =back | ||
| 164 | |||
| 165 | |||
| 166 | =head1 ACKNOWLEDGEMENTS | ||
| 167 | |||
| 168 | |||
| 169 | =head1 LICENSE AND COPYRIGHT | ||
| 170 | |||
| 171 | Copyright 2012 Gary Warman. | ||
| 172 | |||
| 173 | This program is free software; you can redistribute it and/or modify it | ||
| 174 | under the terms of either: the GNU General Public License as published | ||
| 175 | by the Free Software Foundation; or the Artistic License. | ||
| 176 | |||
| 177 | See http://dev.perl.org/licenses/ for more information. | ||
| 178 | |||
| 179 | |||
| 180 | =cut | ||
| 181 | |||
| 182 | 1; # End of POE::Component::IRC::Plugin::WubWubWub | ||