0

I am trying to get the output data from a package_state in my IRC bot, which uses POE::Component::IRC as a base. But I just cannot seem to do it.

Basically, in a subroutine outside of the POE session, I wish to get the data from an event subroutine fired by POE when it receives the data from the server. I've tried saving the data in a global array and even external file, but the outer subroutine will read the old data from it before that data gets updated.

More specifically, I am trying to get this bot to check if someone is 'ison' and if they are, return true (or get all data ( @_ ) from irc_303).

Something like this:

sub check_ison {
    my $who = "someguy";
    $irc->yield(ison => $who);
    $data = (somehow retrieve data from irc_303);
    return $data; #or true if $data
}

1 Answers1

0

It sounds like you want a synchronous solution to an asynchronous problem. Due to the asynchronous nature of IRC (and POE, for that matter ...), you'll need to issue your ISON query and handle the numeric response as it comes in.

As far as I know, most client NOTIFY implementations issue an ISON periodically (POE::Component::IRC provides timer sugar via POE::Component::Syndicator), update their state, and tell the user if something changes.

You have options...

You could issue ISONs on a timer, save state appropriately in your numeric response handler, and provide a method to query the state. If your application looks more like a client (the user/something needs to be notified when something changes, that is) your numeric response handler could do some basic list comparison and issue appropriate events for users appearing/disappearing.

Otherwise, you could simply have a 'check_ison' that issues the ISON and yields some sort of 'response received' event from the numeric response handler, letting you know fresh data is available.

  • Unfortunately, neither options would work for the way I am calling ISON. ISON is being called just once when using a specific command. More specifically, after calling the command, I want to check if the user is actually connected and send them a message instead of a memo through MemoServ. – ashley.miller.475 Jan 08 '14 at 08:10
  • At the simplest, I want to intercept any or specific incoming messages from the IRC server inside a subroutine/function. In this case, I want to intercept irc_303 message after $irc->yield(ison => $who) is called during the check_ison subroutine where $who is also dynamic data, not static shown in the example. – ashley.miller.475 Jan 08 '14 at 09:22
  • So here's what really happens: you issue $irc->yield(foo => $bar), calling POE::Component::Syndicator's yield() method, which *eventually* (when POE is ready) issues an event to your POE::Component::IRC session, which *eventually* dispatches the actual ISON command to the server. There are potentially many other things happening in between -- this is all asynchronous. You don't receive a synchronous response from the server; nothing blocks waiting on a response unless you tell it to. – Jon Portnoy Jan 08 '14 at 14:54