Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:tadzik/a8bot

  • Loading branch information...
commit 65253169b9252179ea23988ca9b48a8a17a87d8b 2 parents da769bb + 22e4467
@lessmian lessmian authored
View
2  Redesign-Ideas
@@ -1,6 +1,4 @@
+ Plugins more user-controlled:
- - The actual app something more than a8bot->new->run
- - Stuff like $obj->add_plugin()
- Register plugins per keyword
· less calling, only the wanted plugins get called
· also no crap when 2 plugins start to respond
View
82 a8bot.pm
@@ -1,15 +1,10 @@
package a8bot;
use feature ':5.10';
use a8bot::Plugin;
-use threads;
use Moose;
use MooseX::NonMoose;
-use Module::Pluggable sub_name => 'pluggable', require => 1;
use AnyEvent;
use AnyEvent::IRC::Client;
-# temporary?
-use Carp::Always::Color;
-use Data::Dumper;
extends 'AnyEvent::IRC::Client';
@@ -75,13 +70,6 @@ has 'wantconnection' => (
sub BUILD {
my $self = shift;
- foreach my $plugin ($self->pluggable) {
- my $plug = a8bot::Plugin->new(
- bot => $self,
- plugin => $plugin,
- );
- $self->add_plugin($plug);
- }
$self->reg_cb(
disconnect => sub {
if ($self->wantconnection) {
@@ -97,12 +85,7 @@ sub BUILD {
publicmsg => sub {
my ($client, $channel, $params) = @_;
foreach my $plugin ($self->list_plugins) {
- my $thr = threads->create(
- sub { $plugin->publicmsg(@_) },
- $channel,
- $params,
- );
- $thr->detach();
+ $plugin->publicmsg($channel, $params);
}
},
registered => sub {
@@ -127,6 +110,15 @@ sub BUILD {
# exit 0;
#}
+sub load_plugin {
+ my ($self, $plugin) = @_;
+ my $plug = a8bot::Plugin->new(
+ bot => $self,
+ plugin => $plugin,
+ );
+ $self->add_plugin($plug);
+}
+
sub log {
my ($self, @args) = @_;
if ($self->verbose) {
@@ -149,57 +141,3 @@ sub run {
__PACKAGE__->meta->make_immutable;
1;
-
-__END__
-
-=pod
-
-=head2 Small guide to orders
-
-A plugin's callback function should return an array of orders for the bot to execute.
-Order is a hash, with an obligatory key 'type', and some other, depending on a type.
-Something like this:
-
- return [
- { type => 'privmsg', arg1 => 'foo', arg2 => 'bar' },
- { type => 'other', args => ['foo', 'bar', 'baz'] },
- ];
-
-Where type should be one of the following:
-
-=over 4
-
-=item privmsg
-
-Arguments for privmsg should be:
-
-=over 2
-
-=item to (string)
-
-User (or channel) to send a message to.
-
-=item msg (string)
-
-The message itself. Simple, huh?
-
-=back
-
-=item mode
-
-Arguments for mode
-
-=over 2
-
-=item args (array)
-
-Array of arguments for AnyEvent's MODE call.
-B<Note>: this is likely to suck less in the near future.
-
-Example: { type => 'mode', args = ['username', '+b'] }
-
-=back
-
-=back
-
-=cut
View
3  a8bot/Plugin.pm
@@ -1,7 +1,7 @@
package a8bot::Plugin;
use feature ':5.10';
+use lib 'plugins';
use Moose;
-use Data::Dumper;
has 'bot' => (
is => 'ro',
@@ -48,6 +48,7 @@ has '_registered' => (
sub BUILD {
my $self = shift;
+ require $self->plugin . '.pm';
my $events = $self->plugin->init;
$self->_disconnect($events->{disconnect} // sub {});
$self->_publicmsg($events->{publicmsg} // sub {});
View
2  app.pl
@@ -7,6 +7,8 @@
verbose => 1,
);
+$bot->load_plugin('Ping');
+
#$SIG{INT} = sub { $bot->cleanup };
#$SIG{TERM} = sub { $bot->cleanup };
View
8 a8bot/Plugin/Odzywki.pm → plugins/Odzywki.pm
@@ -1,4 +1,4 @@
-package a8bot::Plugin::Odzywki;
+package Odzywki;
use Tie::RegexpHash;
tie my %db, 'Tie::RegexpHash';
@@ -19,10 +19,10 @@ sub init {
sub pubmsg {
my ($bot, $data) = @_;
- if (my $resp = $db{$data->{msg}}->()) {
- return "$data->{nick}: " . $resp;
+ return if int(rand(2));
+ if (my $resp = $db{$data->{msg}}) {
+ return "$data->{nick}: " . &$resp;
}
-
}
sub chuj {
View
2  a8bot/Plugin/Ping.pm → plugins/Ping.pm
@@ -1,4 +1,4 @@
-package a8bot::Plugin::Ping;
+package Ping;
# example plugin for a8bot
# a plugin MUST have an 'init' subroutine, returning a hash with keys
View
2  a8bot/Plugin/Powiedz.pm → plugins/Powiedz.pm
@@ -1,4 +1,4 @@
-package a8bot::Plugin::Powiedz;
+package Powiedz;
use strict;
use warnings;
use Hash::MultiValue;
View
2  a8bot/Plugin/Seen.pm → plugins/Seen.pm
@@ -1,4 +1,4 @@
-package a8bot::Plugin::Seen;
+package Seen;
use POSIX 'strftime';
my %log;
View
2  a8bot/Plugin/WebTitle.pm → plugins/WebTitle.pm
@@ -1,4 +1,4 @@
-package a8bot::Plugin::WebTitle;
+package WebTitle;
use LWP::Simple qw /get $ua/;
sub init {

0 comments on commit 6525316

Please sign in to comment.
Something went wrong with that request. Please try again.