Thursday, June 14, 2018

Auto-answering friend/buddy requests

I use a combination of Bitlbee and ZNC to maintain a persistent presence on Jabber and IRC, even when I'm not actually online. Bitlbee will convert a number of non-IRC chat services (Facebook, Twitter, Jabber, Gtalk) into IRC channels and ZNC provides the ability to cache any/all incoming messages. My setup:

   chat client -> ZNC -> Bitlbee -> multiple non-IRC servers
                     \-> multiple IRC servers

The problem: One of the problems with public chat servers is that your receive a lot of buddy/friend requests from people you don't know. Bitlbee requires that you type the word "no" in response to each request (there is no group-answer function).

The solution: The following script leverages another ZNC feature, where multiple concurrent connections are allowed. This means that you can run the following script while being connected with your favorite IRC client. It will watch for the phrase "You can use the yes/no commands to accept/reject this request." and send "no" in response.


  • Assumes that you're already logged onto Bitlbee, from your IRC client, via ZNC,
  • Run this script once you're on a Bitlbee channel which has a number of friend/buddy requests.
  • You must type the first "no".
  • Recommendation: only turn on one Bitlbee channel at a time.

The script:


use IO::Socket;

# set up the connection
$con = IO::Socket::INET->new(PeerAddr=>'',
        Proto=>'tcp') || print "Error! $!\n";
print $con "User tim\r\n";

# allow time for any server side stuff to happen
sleep 3;

# connect to the bitlbee channel on ZNC
print $con "PASS tim/bitlbee:PASSWORD\r\n";

# following shouldn't be needed
#print $con "NICK tim\r\n";

# join the bitlbee command channel
print $con "JOIN \&bitlbee\r\n";

# loop and process messages from the server
while ($answer = <$con>) {

        if($answer =~ /^PING(.*)$/i) {
                print $con "PONG $1\r\n";

        # following 2 lines should be on 1
        if($answer =~ /\:root\!root\@cubietruck PRIVMSG \&bitlbee :You can \
use the \^Byes\^B\/\^Bno\^B commands to accept\/reject this request/){
                print $con "PRIVMSG &bitlbee :no\r\n";

No comments:

Post a Comment