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

Let me start by saying that I know I shouldn't be using Net::IRC since it is deprecated. So don't tell me to switch to POE. I am attempting to make a bot using Net::IRC to auto op certain users. This bot has be made an op in the channel. In it's on_join sub, it checks if the nick of the person joining matches a certain list (I know this isn't that secure). If it matches, it sends a private message to Chanserv telling it to op the user. Here is the command it is using to op the user: " $conn->privmsg("Chanserv", "OP $conn->{channel} $nick");". $conn->{channel} contains the channel name including the # at the beginning. $nick contains the nick of the user to be oped. Could someone either help me make this command work or suggest an alternate command to accomplish the same thing? And yes, I have read the documentation on cpan.

Replies are listed 'Best First'.
Re: Net::IRC Auto-OP
by jZed (Prior) on Jun 03, 2007 at 18:06 UTC
    You've told us more about what we shouldn't tell you then about what we should :-). For example, you didn't tell us what happens when you try what you've shown - is there an error message? nothing? somtehing unexpected? I assume you've tried printing out $comm->{channel} and $nick just before send $conn->privmsg() and they hold what you expect?
Re: Net::IRC Auto-OP
by betterworld (Curate) on Jun 03, 2007 at 19:27 UTC
    ...it sends a private message to Chanserv telling it to op the user

    If you have chanserv available, there are easier methods to automatically op users. See chanserv's "level" or "levels" command.

      I don't want to use the levels command. After viewing the help page, I learned that it involves changing the level of the user I want to be auto oped. I don't want to do that. I want to leave their level as is, and just send a command to op them. As for the output, there is none. No error in the terminal, no getting kicked out of irc, no crash, nothing. The user just doesn't get OPed.
        Does your bot handle incoming private messages? Chanserv may be replying to you with a useful error message.
Re: Net::IRC Auto-OP
by kunwon1 (Sexton) on Jun 03, 2007 at 20:50 UTC
    There are a lot of subtle security holes in what you're doing. You really should (re)consider using chanserv, it's almost always the best choice.

    Are you using strict and using warnings? If not, that should be your first step. As suggested above, you should check the value of $conn->{channel} and $nick before proceeding, and at least add a generic handler for unhandled events, maybe to redirect them to stderr, if you don't already have one.

    If you post more code this will be a lot easier to troubleshoot, at least the whole on_join subroutine.
      I've checked for private messages from Chanserv. There aren't any.

      I've checked the value of $conn->{channel} and $nick using print statements. They are set to the correct values. Here is the on_join sub:
      sub on_join { my ($conn, $event) = @_; my $nick = $event->{nick}; if ($nick eq ("xxx" || "yyy")) { $conn->privmsg("Chanserv", "OP $conn->{channel} $nick"); print "Auto-Op $nick\n"; $conn->privmsg($nick, "You have been Auto-Oped by $mynick"); $conn->me($conn->{channel}, "Auto-Ops $nick"); } $conn->privmsg($conn->{channel}, "Welcome, $nick!") unless ($ni +ck eq $mynick); print "[$mynick] Welcome, $nick!\n" unless ($nick eq $mynick); }
      $mynick is equal to the bot's nick.
      xxx and yyy are the nicks of the users to be OPed.
        This:
        if ($nick eq ("xxx" || "yyy"))
        doesn't make sense. You're checking $nick for string-equality with the logical-ORed value of "xxx" and "yyy" which is just going to be "xxx". What you probably meant was
        if ( $nick eq "xxx" or $nick eq "yyy" )
        If you have a bigger list of nicks you can use a hash, which is a lot easier than constructing a gigantic conditional.
        my %ops = ( xxx => 1, yyy => 1, zzz => 1 ); if ( $ops{$nick} == 1 ) { ... }
        Does this
        print "Auto-Op $nick\n";
        print statement print? If not, you're not getting into the if block.

        And again, are you using strict and warnings pragmas?