Yns
01/10/2006, 21:29
Bir ara python irc botu yazmaya baslamistim, cikan sorunlar nedeniyle yazmayi biraktim.Belki gelistirmek, kodlari incelemek isteyen olur.
import socket,re,httplib,time
# --------------------------------------------
# --- Terlik v0.1, Python IRC Bot ------------
# --- Author: Yns_ || http://yns.zaxaz.com ---
# --------------------------------------------
# configuration files
network = 'irc.freenode.net'
port = 6667
nick = 'Terlik_'
channel = '#ceviz.net'
log_file = 'log.txt'
owner = 'Yns_'
execpw = 'cvz3'
auth = ''
nick_regex = re.compile(":(.*?)!")
message_regex = re.compile(channel + " :(.*)")
url_regex = re.compile('<a class=l href="(.*?)">')
pm_regex = re.compile(nick + " :(.*?)")
def control():
global data,pm,nick,auth
# --- Private messages --- #
if data.find ( 'PRIVMSG ' + nick ) != -1:
pm = data.split('!')[2].replace('\r','').replace('\n','')
if(pm == execpw):
auth = 'yep'
else:
auth = '_'
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( network, port ) )
print irc.recv ( 4096 )
irc.send ( "NICK " + nick + "\r\n" )
irc.send ( "USER " + nick + " " + nick + " " + nick + " :yns.zaxaz.com/terlik/ \r\n" )
irc.send ( "JOIN " + channel +" \r\n" )
irc.send ( "PRIVMSG " + channel + " :selamlar.. \r\n" )
pointer = True
while pointer == True:
data = irc.recv ( 4096 )
# -- Logging In progress -- #
filehandle = open(log_file, "a+")
filehandle.write(data)
filehandle.close()
print data
# -- pin(g) - pon(g) -- #
if data.find ( 'PING' ) != -1:
irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' )
# explode the data
if data.find ( 'PRIVMSG ' + channel ) != -1:
# -- regex on the fly! --
message = ""
nick = re.search(nick_regex,data).group(1).replace('\r',' ').replace('\n','')
message = re.search(message_regex,data).group(1).replace('\r ','').replace('\n','')
# --- Getting commands --- #
if(message.find('!') != -1):
control()
command = message.split(' ')[0]
if(command == '!slap'):
kisi = ""
kisi = message.split(' ')[1]
try:
arac = message.split(' ')[2]
except:
arac = 'vatoz baligi'
if(kisi != ""):
irc.send ( " PRIVMSG " +channel+ " :\001ACTION " + kisi + " kisisini bir " +arac+ " ile tokatlar!! .\001" + "\r\n" )
if command == '!quit' and nick == owner:
irc.send ( "PRIVMSG " + channel + " : Iyi gunler \r\n" )
irc.send ( 'QUIT\r\n' )
irc.close()
pointer = False
if command == '!google':
arg = ""
arg = message.split(' ')[1]
if(arg != ""):
conn = httplib.HTTPConnection("www.google.com")
conn.request("GET","/search?hl=tr&meta=&num=1&q=" + arg + "&btnG=search")
r1 = conn.getresponse()
response = r1.read()
url = ""
try:
url = re.search(url_regex,response).group(1)
except:
url = "Google'da aradim, lakin bulamadim " + nick
if(url != ""):
irc.send ( "PRIVMSG " + channel + " :" + url + "\r\n" )
if command == '!kick' and nick == owner:
control()
if(auth == 'yep'):
kisi = ""
kisi = message.split(' ')[1]
sebep = ""
try:
sebep = message.split(' ')[2]
except:
sebep = '...'
if(kisi !=""):
irc.send ( "KICK " + channel + " " + kisi + " :"+ sebep + "\r\n" )
if command == '!voice' and nick == owner and auth == 'yep':
kisi = ""
kisi = message.split(' ')[1]
if(kisi != ""):
irc.send("MODE " + channel + " +v " + kisi + "\r\n" )
if command == '!devoice' and nick == owner and auth == 'yep':
kisi = ""
kisi = message.split(' ')[1]
if(kisi != ""):
irc.send("MODE " + channel + " -v " + kisi + "\r\n" )
if command == '!ban' and nick == owner and auth == 'yep':
kisi = ""
kisi = message.split(' ')[1]
if(kisi != ""):
irc.send("MODE " + channel + " +b " + kisi + "\r\n" )
if command == '!unban' and nick == owner and auth == 'yep':
kisi = ""
kisi = message.split(' ')[1]
if(kisi != ""):
irc.send("MODE " + channel + " -b " + kisi + "\r\n" )
if command == '!op' and nick == owner and auth == 'yep':
kisi = ""
kisi = message.split(' ')[1]
if(kisi != ""):
irc.send("MODE " + channel + " +o " + kisi + "\r\n" )
if command == '!deop' and nick == owner and auth == 'yep':
kisi = ""
kisi = message.split(' ')[1]
if(kisi != ""):
irc.send("MODE " + channel + " -o " + kisi + "\r\n" )
import socket,re,httplib,time
# --------------------------------------------
# --- Terlik v0.1, Python IRC Bot ------------
# --- Author: Yns_ || http://yns.zaxaz.com ---
# --------------------------------------------
# configuration files
network = 'irc.freenode.net'
port = 6667
nick = 'Terlik_'
channel = '#ceviz.net'
log_file = 'log.txt'
owner = 'Yns_'
execpw = 'cvz3'
auth = ''
nick_regex = re.compile(":(.*?)!")
message_regex = re.compile(channel + " :(.*)")
url_regex = re.compile('<a class=l href="(.*?)">')
pm_regex = re.compile(nick + " :(.*?)")
def control():
global data,pm,nick,auth
# --- Private messages --- #
if data.find ( 'PRIVMSG ' + nick ) != -1:
pm = data.split('!')[2].replace('\r','').replace('\n','')
if(pm == execpw):
auth = 'yep'
else:
auth = '_'
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( network, port ) )
print irc.recv ( 4096 )
irc.send ( "NICK " + nick + "\r\n" )
irc.send ( "USER " + nick + " " + nick + " " + nick + " :yns.zaxaz.com/terlik/ \r\n" )
irc.send ( "JOIN " + channel +" \r\n" )
irc.send ( "PRIVMSG " + channel + " :selamlar.. \r\n" )
pointer = True
while pointer == True:
data = irc.recv ( 4096 )
# -- Logging In progress -- #
filehandle = open(log_file, "a+")
filehandle.write(data)
filehandle.close()
print data
# -- pin(g) - pon(g) -- #
if data.find ( 'PING' ) != -1:
irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' )
# explode the data
if data.find ( 'PRIVMSG ' + channel ) != -1:
# -- regex on the fly! --
message = ""
nick = re.search(nick_regex,data).group(1).replace('\r',' ').replace('\n','')
message = re.search(message_regex,data).group(1).replace('\r ','').replace('\n','')
# --- Getting commands --- #
if(message.find('!') != -1):
control()
command = message.split(' ')[0]
if(command == '!slap'):
kisi = ""
kisi = message.split(' ')[1]
try:
arac = message.split(' ')[2]
except:
arac = 'vatoz baligi'
if(kisi != ""):
irc.send ( " PRIVMSG " +channel+ " :\001ACTION " + kisi + " kisisini bir " +arac+ " ile tokatlar!! .\001" + "\r\n" )
if command == '!quit' and nick == owner:
irc.send ( "PRIVMSG " + channel + " : Iyi gunler \r\n" )
irc.send ( 'QUIT\r\n' )
irc.close()
pointer = False
if command == '!google':
arg = ""
arg = message.split(' ')[1]
if(arg != ""):
conn = httplib.HTTPConnection("www.google.com")
conn.request("GET","/search?hl=tr&meta=&num=1&q=" + arg + "&btnG=search")
r1 = conn.getresponse()
response = r1.read()
url = ""
try:
url = re.search(url_regex,response).group(1)
except:
url = "Google'da aradim, lakin bulamadim " + nick
if(url != ""):
irc.send ( "PRIVMSG " + channel + " :" + url + "\r\n" )
if command == '!kick' and nick == owner:
control()
if(auth == 'yep'):
kisi = ""
kisi = message.split(' ')[1]
sebep = ""
try:
sebep = message.split(' ')[2]
except:
sebep = '...'
if(kisi !=""):
irc.send ( "KICK " + channel + " " + kisi + " :"+ sebep + "\r\n" )
if command == '!voice' and nick == owner and auth == 'yep':
kisi = ""
kisi = message.split(' ')[1]
if(kisi != ""):
irc.send("MODE " + channel + " +v " + kisi + "\r\n" )
if command == '!devoice' and nick == owner and auth == 'yep':
kisi = ""
kisi = message.split(' ')[1]
if(kisi != ""):
irc.send("MODE " + channel + " -v " + kisi + "\r\n" )
if command == '!ban' and nick == owner and auth == 'yep':
kisi = ""
kisi = message.split(' ')[1]
if(kisi != ""):
irc.send("MODE " + channel + " +b " + kisi + "\r\n" )
if command == '!unban' and nick == owner and auth == 'yep':
kisi = ""
kisi = message.split(' ')[1]
if(kisi != ""):
irc.send("MODE " + channel + " -b " + kisi + "\r\n" )
if command == '!op' and nick == owner and auth == 'yep':
kisi = ""
kisi = message.split(' ')[1]
if(kisi != ""):
irc.send("MODE " + channel + " +o " + kisi + "\r\n" )
if command == '!deop' and nick == owner and auth == 'yep':
kisi = ""
kisi = message.split(' ')[1]
if(kisi != ""):
irc.send("MODE " + channel + " -o " + kisi + "\r\n" )