Message Highlighting Bot

This py bot script will join all of the channels given to it and sit there monitoring for messages containing any keywords provided to it. It will then forward those messages along to a given nick.

Edit: Last updated on June 30, 2011

pbot.py

import os
import re
import sys
import time

import lbot

def ircbmain():
	print(sys.argv)
	if (len(sys.argv) < 8):
		print("Usage: %s <nick> - <chan 0> ... <chan N> - <dest> - <srch 0> ... <srch N>" % (sys.argv[0]))
		sys.exit(0)
	
	nickname = ""
	chanlist = []
	destname = ""
	srchlist = []
	
	x = 1
	l = len(sys.argv)
	f = 0
	
	while (x < l):
		if (sys.argv[x] == "-"):
			f += 1
		
		elif (f == 0):
			nickname = sys.argv[x]
		
		elif (f == 1):
			chanlist.append(sys.argv[x])
		
		elif (f == 2):
			destname = sys.argv[x]
		
		elif (f == 3):
			srchlist.append(sys.argv[x])
		
		x += 1
	
	lbot.ircbinit(nickname, chanlist)
	
	while (1):
		ircdstri = lbot.ircbmain([], [])
		
		for srchstri in srchlist:
			regxobjc = re.match("^:?([^ ]+)![^ ]+ PRIVMSG ([^ ]+) :(.*%s.*)" % (srchstri), ircdstri, re.I)
			
			if (regxobjc):
				mesgstri = ("PRIVMSG %s :mesg detect: [%s] in [%s] mesg [ %s ]" % (destname, regxobjc.group(1), regxobjc.group(2), regxobjc.group(3)))
				lbot.waitsend(mesgstri)
				break
			
			regxobjc = re.match("^:?([^ ]*%s[^ ]*)![^ ]+ PRIVMSG ([^ ]+) :(.+)" % (srchstri), ircdstri, re.I)
			
			if (regxobjc):
				mesgstri = ("PRIVMSG %s :nick detect: [%s] in [%s] mesg [ %s ]" % (destname, regxobjc.group(1), regxobjc.group(2), regxobjc.group(3)))
				lbot.waitsend(mesgstri)
				break

ircbmain()

Advertisements
Message Highlighting Bot

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s