Hello. This time I decided to make a bot that would every X seconds check the user list on some irc channel and give voice to those that don't have it. I mainly done this so the #evilzone channel could be more tidy
but....
<Satori> Kulverstukas, theres a reason why non registered people dont get voice
<@Satori> if we get like 200 bots flooding the channel
<@Satori> if they all have voice we cant mute the channel
Can't argue with that
Anyway, I'm releasing the code, bot might run sometimes on the channel... Notice: if anyone sees you with this bot trollin' you
will be banned.
The code is ugly, could be better, still doesn't do much good, just gives voice, sometimes receives crap and tries to send it... still needs work but does the job - I'm still learning...
http://newage.ql.lt/projects/python/Autovoice.py'''
Created: 2011-06-12
Last update: nil
This is a bot that will sit in a IRC channel and give voice every X seconds to non-voiced people;
Command line arguments: --server=irc.whatever.com -- server to connect to
--channel=#something -- channel to join and maintain
--name=Autovoice -- name for the bot
--interval=X -- interval in seconds for the bot to check for people without voice
--port=X -- port to connect to. Default is 6667, some servers might use other
'''
import socket
import sys
import string
import time
import re
#=========================
def GetFromArg(What, FromWhere):
for GotArg in FromWhere:
if string.find(GotArg, What) != -1:
GotArg = string.replace(GotArg, What, '')
break
return GotArg
#=========================
print 'Autovoice bot by Kulverstukas for Evilzone'.center(100)
print 'Command line arguments to run the script: --server=irc.whatever.com -- server to connect to'
print ' --channel=#something -- channel to join and maintain'
print ' --name=Autovoice -- name for the bot'
print ' --interval=X -- interval in seconds for the bot to check for people without voice'
print
#=========================
arguments = sys.argv[1:] # this will start from the second argument, because first is the script name and path
if len(arguments) < 5:
print 'Not all arguments were given. Please re-view and run again properly.'
exit()
#=========================
server = string.strip(GetFromArg('--server=',arguments))
if (server == ''): server = 'irc.evilzone.org'
channel = string.strip(GetFromArg('--channel=',arguments))
if (channel == ''): channel = '#test'
name = string.strip(GetFromArg('--name=',arguments))
if (name == ''): name = 'Autovoice'
interval = int(string.strip(GetFromArg('--interval=',arguments)))
if (interval == ''): interval = 10
port = int(string.strip(GetFromArg('--port=',arguments)))
if (port == ''): port = 6667
#=========================
irc = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
irc.connect((server,port)) # default irc port is 6667
ish = irc.recv(4096)
#print ish
irc.send('NICK '+name+'\r\n')
irc.send('USER Autovoice Autovoice Autovoice :Autovoicebawt\r\n')
if string.find(ish,'PING') != -1: irc.send('PONG '+ish.split()[1]+'\r\n')
#=========================
NoVoice = ''
userlist = ''
joined = False
TempData = ''
#=========================
while True:
data = ''
data = irc.recv(4096)
#print data
if string.find(data,'PING') != -1: irc.send('PONG '+data.split()[1]+'\r\n')
if joined == False:
irc.send('JOIN '+channel+'\r\n')
joined = True
time.sleep(interval)
irc.send('NAMES '+channel+'\r\n')
TempData = irc.recv(4096)
if TempData.find('353') != -1: data = TempData
data = data.splitlines()
for userlist in data:
if userlist.find('353') != -1:
userlist = re.sub(':.*:.\w*\s', '', userlist, 1)
userlist = string.split(userlist)
break
#print data
print userlist
for NoVoice in userlist:
if string.find(NoVoice,'+') == -1: irc.send('MODE %s +v %s\r\n' % (channel, NoVoice))
#=========================