Menu

#3 Join more than one Channel

v1.0_(example)
open
nobody
None
5
2017-06-02
2017-05-31
Danny Zedd
No

How can the Bot join more than one channel?

sub CHANNELS() { '#VtM' } works with no problem he is joining #VtM

sub CHANNELS() { '#VtM; #WtA' } dont work
sub CHANNELS() { '#VtM'; '#WtA' } dont work

in the best situation it work for one channel and it dont join the second channel

What iam doing wrong?

Greeting Mordekain

Discussion

  • Danny Zedd

    Danny Zedd - 2017-05-31

    i forgot to say i use tge latest version

     
  • ClearsTheScreen

    ClearsTheScreen - 2017-06-01

    Hello Mordekain,

    good spot! This is a bug in 2.0.1. I'll try to update the package soon. You're not doing anything wrong; the "join" event seems to take only one channel per command.

    Until I publish the next alpha version, you could do this as workaround:

    Use

    our @channels = ['#channel1', '#channel2'];
    

    to turn it into an array of channel names..

    Then replace the line $irc->yield(join => CHANNELS); with this:

    $irc->yield( join => $_ ) for @channels;
    
     
  • Danny Zedd

    Danny Zedd - 2017-06-02

    Hi ClearsTheScreen,

    now my Code is looking like this:

    our @channels = ['#VtM', '#WtA'];
    =for settings
    Some parameters to tweak around.
    There is no need to do anything here, but allows for some customisation.
    =cut

    our %settings = (
    'log non-commands' => 0,
    'require nick prefix' => 1,
    );

    =for noone to touch
    Here be dragons.
    Touch only when you know what you do.
    =cut

    our $VERSION = 2.0;

    sub make_log {
    my $text = shift;
    my $ts = scalar localtime;
    print "[$ts] <Dicebot> $text\n";
    }

    make_log("Starting dicebot " . $VERSION . "...");

    my ($irc) = POE::Component::IRC->spawn('plugin_debug' => 1, 'debug' => 0);

    sub prepare_cmd_hub() {
    my $cmd_hub = Dicebot::Plugins::CommandHub->new();
    $cmd_hub->registerPlugins();
    $cmd_hub->setting('require nick prefix', $settings{'require nick prefix'});
    $cmd_hub->setting('nick', $NICK);
    $cmd_hub->setting('log non-commands', $settings{'log non-commands'});

    $irc->plugin_add('CommandHub', $cmd_hub );
    }

    sub lag_o_meter {
    my ($kernel,$heap) = @_[KERNEL,HEAP];
    print 'Time: ' . time() . ' Lag: ' . $heap->{connector}->lag() . "\n";
    $kernel->delay('lag_o_meter' => 60 );
    return;
    }

    sub bot_start {
    my ($kernel,$heap) = @_[KERNEL,HEAP];
    make_log("Connecting ...");
    $irc->yield(register => "all");

    $heap->{connector} = POE::Component::IRC::Plugin::Connector->new();
    $irc->plugin_add('Connector' => $heap->{connector} );

    $irc->yield(
    connect => {
    Nick => $NICK,
    Username => $IDENT,
    Ircname => $REALNAME,
    Server => $SERVER,
    Port => $PORT,
    }
    );

    $kernel->delay('lag_o_meter' => 60 );
    }

    sub on_connect {
    make_log("Connected. Joining channels.");
    $irc->yield( join => $_ ) for @channels;
    }

    make_log("Creating irc session ...");

    POE::Session->create(
    inline_states => {
    _start => \&bot_start,
    irc_001 => \&on_connect,
    },
    );

    make_log("Preparing command hub ...");
    prepare_cmd_hub();

    make_log("Running.");
    $poe_kernel->run();
    exit 0;

    But now the Bot is not connecting to a channel :(

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.