Timbus / Net--IRC

A simple and easy to use IRC Bot framework for Perl 6
ISC License
15 stars 10 forks source link

Getting going? #3

Closed MattOates closed 11 years ago

MattOates commented 11 years ago

Hi I'm trying to write a simple bot using your library. The example code you give has a typo at: Net::IRC::DefaultHandlers.new() should be Net::IRC::Handlers::Default.new() after I fixed this I still get an error with the Event class not having a .reply(). Has everything changed since your documentation? Any help you can pass along would be much appreciated. I'll try using the source, in the meantime :) Thanks for your efforts on this! Using a grammar appears to be a really clean mechanism for creating libraries of this kind! Exciting stuff.

No such method 'reply' for invocant of type 'Net::IRC::Event' in method joined at ./echo.p6:17 in sub METAOP_HYPER_CALL at src/gen/CORE.setting:11943 in block at lib/Net/IRC/Bot.pm:163 in method reify at src/gen/CORE.setting:5186 in method reify at src/gen/CORE.setting:5088 in method reify at src/gen/CORE.setting:5088 in method gimme at src/gen/CORE.setting:5466 in method eager at src/gen/CORE.setting:5445 in method eager at src/gen/CORE.setting:1099 in sub eager at src/gen/CORE.setting:5730 in method do_dispatch at lib/Net/IRC/Bot.pm:161 in block at lib/Net/IRC/Bot.pm:146 in method dispatch at lib/Net/IRC/Bot.pm:115 in method run at lib/Net/IRC/Bot.pm:89 in block at ./echo.p6:29

The panda info for your library reads:

PROJECT LIST: "Net::IRC::Bot" => "0.9" "State" => "installed" "Source-url" => "git://github.com/TiMBuS/Net--IRC.git" "Description" => "An IRC bot framework" INSTALLED VERSION: "depends" => [] "description" => "An IRC bot framework" "name" => "Net::IRC::Bot" "source-revision" => "99e638d" "source-type" => "git" "source-url" => "git://github.com/TiMBuS/Net--IRC.git" "version" => "0.9"

Your example with my modification looks like (echo.p6):

!/usr/bin/env perl6

use Net::IRC::Bot;

Roles can let you break up large event handler modules into smaller ones.

role ExtraAnnoying { has %enemies = ('bob', 'sam', 'chanserv') X=> 1;

Magical type constraints only let this event be called when $e.who is an enemy

 multi method said ($e where {.who<nick> ~~ %enemies}) {
     $e.reply($e.msg); #Parrot back what was said;
 }

}

class AnnoyUsers does ExtraAnnoying {

Will be called when the bot gets a join event

 multi method joined ($e) {
      $e.reply("Hi there, {$e.who<nick>}!"); 
 }

}

Net::IRC::Bot.new( nick => 'blargh', server => 'irc.ivixor.net', channels => <#bots>,

    modules  => (
            Net::IRC::Handlers::Default.new(),
            AnnoyUsers.new(), 
    ),

).run;

Timbus commented 11 years ago

Ah, yes this is a problem with the documentation. use event.msg("your reply"), which by default contains $.where as the second argument. I will update the faulty docs, as well as the handler::default bug. Thanks!

Timbus commented 11 years ago

Fixed, but I should let you know that the latest rakudo builds have a broken io::socket::inet so, the bot probably still won't work (but it it out of my hands)

MattOates commented 11 years ago

Hi Jarrod, thanks for getting back to me it was helpful. I haven't updated to the latest Rakudo build I'm using Star from August which appears to work fine. Just to let you know, I really like the API structure you've decided on with this module, its quite a natural way of interacting with IRC.