GithubHelp home page GithubHelp logo

net--irc's Introduction

Net::IRC

Elegant. Simple. Probably compiles.

Synopsis

use Net::IRC::Bot;
use Net::IRC::Modules::Autoident;

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>}!"); 
    }
}

#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;
    }
}


Net::IRC::Bot.new(
        nick     => 'KickMe',
        server   => 'irc.freenode.net',
        channels => <#bottest>,
        
        modules  => (
                Net::IRC::DefaultHandlers.new(),
                AnnoyUsers.new(), 
                Autoident.new(password => 'nspassw0rd')
        ),
).run;

Description

Its an IRC Bot framework! Theres not much else to it. It's currently in active development, but it is mostly stable until perl 6 implements either threads or async I/O so it can work correctly as a bot (timed events and things that block the runtime are not possible yet.)

The framework makes extensive use of the added features perl 6 provides, and is an excellent example of how concise and powerful the language is... With emphasis on concise:- The core code is only about 350 lines!

Methods and Attributes

Net::IRC::Bot only really has one needed method: run(). Everything else is setup using parameters to new()

List of attributes + their defaults:

$nick = "Rakudobot";
@altnicks = $nick Z~ ("_","__",^10);
$username = "Clunky";
$realname = '$@%# yeah, perl 6!';

$server = "irc.perl.org";
$port = 6667;
$password;
@channels = [];

@modules;

$debug = False;

Callbacks

Callbacks are event handlers created by you, the bot maker. They are dispatched to by name when an appropriate IRC event is fired.

There are currently six 'main' types of events: said, acted, joined, noticed, nickchanged and connected. They will be called with a Net::IRC::Event object containing every detail possible about the event. [Details to come soon]

For any event that doesn't fit into the above category, you will need to set up a raw event handler. Raw handlers begin with 'irc_' and won't have their Event objects properly filled [TODO: List what will be filled] The method irc_433 for example, will be called when ERR_NICKNAMEINUSE is thrown. irc_privmsg will be just like said, except it will be called first.

Untidy collection of event object contents for each handler:

said: .who said .what in channel .where (if it was a private message, .where will be our nickname. If you dont want to check .state<nick\> for equality then you can always test if .where starts with a hash)

nickchange: .who changed nick to .what

Helper methods

Helper methods are kept in the Event that every callback is provided with. The current three methods are .msg, .act and .send_ctcp. [details on each to come soon]

net--irc's People

Contributors

jnthn avatar timbus avatar

Watchers

Carl Mäsak avatar  avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.