уже зделал что получше =)) если есть какие-нибудь маленькие ошибочки скажите исправлю =)
# -*- coding: cp1251 -*-
import socket
import time
import httplib
host='irc.lv'
channel='#dragstyle^'
admin='armagidon!local@armaggidon.ru'
def parsing(txt):
y=txt.split('<sup>') [1]
online=y.split('</sup>') [0]
u=txt.split('<title>') [1]
ref=u.split('</title>') [0]
return online, ref
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 importlife\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('PING') != -1:
irc.send('PONG ' + text.split() [1] + '\r\n')
if text.find(':!quit') != -1:
irc.send('QUIT :python bot\r\n')
if text.find('bot') != -1:
sendm('no , you are bot')
if text.find('JOIN :'+ channel) != -1:
sendm('Hello')
if text.find(':KICK') != 1:
irc.send('JOIN '+ channel +'\r\n')
if text.find(':!date') != -1:
sendm('[+] '+ time.strftime("%a, %b %d, %y", time.localtime()))
if text.find(':!time') != -1:
sendm('[+] '+ time.strftime("%H:%M:%S", time.localtime()))
if text.find(':!weather') != -1:
tmp = text.split(':!weather')
if len(tmp) < 2:
pass
else:
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')
if len(tmps) < 2:
pass
else:
irclvs = tmps[1].strip()
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')
if len(says) < 2:
pass
else:
sayse = says[1].strip()
sendm('.:: '+ sayse +' ::.')
if text.find(':!join') != -1:
joins = text.split(':!join')
if len(joins) < 2:
pass
else:
das = joins[1].strip()
irc.send('JOIN '+ 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 '+ nicknames +'\r\n')
if text.find(':!file.lv') != -1:
conn = httplib.HTTPConnection("dev.wegame.lv")
conn.request("GET", None)
connect = conn.getresponse()
games = connect.read()
online, ref = parsing(games)
sendm('[+] '+ ref +' | ONLINE: '+ online)
conn.close
if text.find(':!dns') != -1:
dns = text.split(':!dns')
if len(dns) < 2:
pass
else:
dnsf = dns[1].strip()
dnserv = socket.gethostbyaddr(dnsf)
sendm('[+] DNS : '+ str(dnserv))
print '[+]', text