Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Small net::irc questions

by coldfingertips (Pilgrim)
on May 03, 2005 at 06:17 UTC ( [id://453488]=perlquestion: print w/replies, xml ) Need Help??

coldfingertips has asked for the wisdom of the Perl Monks concerning the following question:

Seeing a post on here about this module yesterday I thought it might be interesting to see what all it could do since I used to spend all my time over on MIRC.

I have 2 questions.

1) How do you issue commands from the bot such as voicing a user by +v? $conn->privmsg($conn->{channel}, "/mode #HiddenRoom +v $nick"); printed literally the entire line. So I'm assuming there's a specific way to issue commands and it's not by privmsg but I couldn't find it on the docs. Can someone fill me in?

2) From the command line after you issue all the sub routines on what to do when someone joins, leaves or sends a message, it "halts" after you issue $irc->start();. I tried to ask for more input after this but the script doesn't go further.

I want to be able to set it up so I can issue commands to the script WHILE it's live so does anyone know of a way to do this? It keeps pausing after you tell it to start().

Replies are listed 'Best First'.
Re: Small net::irc questions
by Forsaken (Friar) on May 03, 2005 at 08:32 UTC
    1) The NET::IRC folks don't seem to have gotten around to it yet, but eventually this information should be in the docs for NET::IRC::Connection. For the moment your answers can only be found in the source...

    More specifically, a PRIVMSG is just that, a PRIVMSG to either a channel or a specific nick. If you really want to dive into it I would suggest the good ol' RFC 1459.

    Now as for your actual question(yes, yes, I will answer it :)), from the source of NET::IRC::Connection :

    # Change channel and user modes (this one is easy... the handler is a +bitch.) # Takes at least 1 arg: the target of the command (channel or nick) # (optional) the mode string (i.e., "-boo+i") # (optional) operands of the mode string (nicks, hostmask +s, etc.) sub mode { my $self = shift; unless (@_ >= 1) { croak "Not enough arguments to mode()"; } $self->sl("MODE $_[0] " . CORE::join(" ", @_[1..$#_])); }
    So the answer would be: $conn->mode('#channel', '+v', 'nickname');

    2) $irc->start() permanently yields control to the module. Like it says in the docs for NET::IRC:

    Getting Connected

    When you've set up all your handlers, the following command will put your program in an infinite loop, grabbing input from all open connections and passing it off to the proper handlers:

    $irc->start;

    Note that new connections can be added and old ones dropped from within your handlers even after you call this. Just don't expect any code below the call to start() to ever get executed.

    If you're tying Net::IRC into another event-based module, such as perl/Tk, there's a nifty do_one_loop() method provided for your convenience. Calling $irc->do_one_loop() runs through the IRC.pm event loop once, hands all ready filehandles over to the appropriate handler subs, then returns control to your program.

    There you have it, hope that helps you get underway :-)

    Remember rule one...

      Thanks for yoru help, I really appreciate.

      After trying $conn->mode("$channel", '+v', "$nickname") as you suggested, it had the same results as printing it as a prvmsg. It prints /#channel name +v UserName .

      I went back and changed use Net::IRC to use Net::IRC::Connection thinking this was the solution. Doing this created an error "Can't locate object new..". So from that, I went ahead and changed my $irc = new Net::IRC; to my $irc = new Net::IRC::Connection; and it errors out with "No method called "newconn" for object.". Any idea what's going wrong or why it's printing as text?

      Thanks! I haven't tried the loop thing yet, I'm still trying to get the commands to work.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://453488]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-04-18 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found