The good irc bot written on python ! Need download Python 2.6.1 !
# -*- coding: cp1251 -*-
import socket
import time
import httplib
from datetime import date
host='
channel=''
password=''
nicks=''
def tpars(txt):
q=txt.split('<span class="temp">') [1]
temp=q.split(' C') [0]
qq=txt.split('<span>') [1]
wind=qq.split('</span>') [0]
return temp, wind
def sendm(msg):
irc.send('PRIVMSG '+ channel + ' :' + str(msg) + '\r\n')
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect((host, 6667))
irc.send('USER py host servname : Python Bot\r\n')
irc.send('NICK '+ str(nicks) +'\r\n')
while 1:
text=irc.recv(2040)
if not text:
break
if text.find('Message of the Day') != -1:
irc.send('JOIN '+ channel +'\r\n')
if text.find('+iwR') != -1:
irc.send('NS IDENTIFY '+ str(password) +'\r\n')
if text.find('PING') != -1:
irc.send('PONG ' + text.split() [1] + '\r\n')
if text.find('armagidon!~null@armaggidon.ru PRIVMSG #DragStyle^ :!quit') != -1:
irc.send('QUIT :python bot\r\n')
if text.find(':KICK') != 1:
irc.send('JOIN '+ channel +'\r\n')
if text.find(':!date') != -1:
sendm('[+] Date: '+ time.strftime("%a, %b %d, %y", time.localtime()))
if text.find(':!time') != -1:
sendm('[+] Time: '+ time.strftime("%H:%M:%S", time.localtime()))
if text.find(':!weather') != -1:
tmp = text.split(':!weather')
city = tmp[1].strip()
reqest_str = '/laika_zinas/?city=' + city
c = httplib.HTTPConnection("www.1188.lv")
c.request("GET", reqest_str)
ra = c.getresponse()
datas = ra.read()
temp, wind = tpars(datas)
sendm('[+] Temp: '+ temp +' C | Wind: '+ wind +' m/s')
c.close()
if text.find(':!irclv') != -1:
tmps = text.split(':!irclv')
irclvs = tmps[1].strip()
if len(irclvs) < 1:
sendm('[+] Error ! Wrote !irclv nick')
else:
website = 'http://irc.lv/?nick=' + irclvs
sendm('[+] Home: '+ website)
sendm('[+] Perl: http://irc.lv/perl?nick=' + irclvs)
sendm('[+] Blog: http://irc.lv/blogs?nick=' + irclvs)
if text.find(':!say') != -1:
says = text.split(':!say')
sayse = says[1].strip()
sendm('.:: '+ str(sayse) +' ::.')
if text.find(':!join') != -1:
joins = text.split(':!join')
das = joins[1].strip()
irc.send('JOIN '+ str(das) +'\r\n')
if text.find(':!nick') != -1:
nickname = text.split(':!nick')
if len(nickname) < 2:
pass
else:
nicknames = nickname[1].strip()
irc.send('NICK '+ str(nicknames) +'\r\n')
if text.find(':!dns') != -1:
dns = text.split(':!dns')
dnsf = dns[1].strip()
dnserv = socket.gethostbyaddr(dnsf)
sendm('[+] DNS : '+ str(dnserv))
if text.find(':!part') != -1:
part = text.split(':!part')
parts = part[1].strip()
irc.send('PART '+ str(parts) +'\r\n')
if text.find(':!voice') != -1:
voice = text.split(':!voice')
voices = voice[1].strip()
irc.send('MODE '+ str(channel) +' +v '+ str(voices) +'\r\n')
if text.find(':!devoice') != -1:
devoice = text.split(':!devoice')
devoices = devoice[1].strip()
irc.send('MODE '+ str(channel) +' -v '+ str(devoices) +'\r\n')
if text.find(':@CO') != -1:
co = text.split(':@CO')
cos = co[1].strip()
sendm('(-(--)-) '+ str(cos) +' Sha Ibalo Razibu Cibe @.@ (P@UKI SCRIPT)')
if text.find(':@PAIBALU') != -1:
pai = text.split(':@PAIBALU')
paib = pai[1].strip()
irc.send('PRIVMSG '+ str(paib) +' :(-(--)-) Sha Ibalo Razibu Cibe @.@ (P@UKI SCRIPT)\r\n')
if text.find(':!wiki') != -1:
wiki = text.split(':!wiki')
wikis = wiki[1].strip()
if len(wikis) < 1:
sendm('[+] Error ! Wrote Name ! Example : !wiki Windows')
else:
sendm('[+] Wiki : http://ru.wikipedia.org/wiki/'+ str(wikis))
if text.find(':!topic') != -1:
topi = text.split(':!topic')
topic = topi[1].strip()
irc.send('TOPIC #DragStyle^ :'+ str(topic) +'\r\n')
if topic == topic:
sendm('[+] Topic change')
if text.find(':!image') != -1:
image = text.split(':!image')
images = image[1].strip()
if len(images) < 1:
sendm('[+] Error ! Wrote : !image world')
else:
sendm('[+] images url : http://images.google.lv/images?um=1&hl=ru&q='+ images +'&btnG')
if text.find(':!newyear') != -1:
now = date.today()
newyear = date(2009, 12, 31)
cik = now - newyear
newyears = cik.days
sendm('[+] До Нового Года осталось :'+ str(newyears) +' дней =)')
if text.find(':!help') != -1:
hel = text.split(':!help')
helps = hel[1].strip()
if len(helps) < 1:
sendm('[+] Error ! Wrote : !help nick ')
else:
irc.send('PRIVMSG '+ helps +' : !time, !date, !wiki, !weather, !norris, !rasha, !irclv, !image, !dns, !newyear\r\n')
Hey, I use your script.
But when I'm loading, I get this error.
Python interface loaded
Traceback (most recent call last):
File "C:\Users\Gast\Documents\test.py", line 63, in <module>
temp, wind = tpars(datas)
File "C:\Users\Gast\Documents\test.py", line 14, in tpars
q=txt.split('<span class="temp">') [1]
IndexError: list index out of range
Error loading module C:\Users\Gast\Documents\test.py
Someone who can help me?
Your !dns is not working...
When executing "!dns http://hi.com"
you will get:
Traceback (most recent call last):
File "bot.py", line 45, in
dnserv = socket.gethostbyaddr(dnsf)
socket.gaierror: [Errno -2] Name or service not known
Fixed version
if text.find( '!dns' ) != -1:
try:
dns = text.split( '!dns' )
dnsf = dns[1].strip()
dnserv = socket.gethostbyaddr(dnsf)
irc.send ( 'PRIVMSG '+ str(channel) +' :Address : '+ str(dnserv) +'\n' )
except:
irc.send ( 'PRIVMSG '+ str(channel) +' :[ERROR] Something is wrong here!!!\n' )