All pastes #140345 Raw Edit

Stuff

public text v1 · immutable
#140345 ·published 2006-08-20 12:12 UTC
rendered paste body
import socket,re

# --------------------------------------------
# --- Terlik v0.1, Python IRC Bot ------------
# --- Author: Yns_ || http://yns.zaxaz.com ---
# --------------------------------------------

# configuration files
network  = 'irc.freenode.net'
port     = 6667
nick     = 'Terlik'
channel  = '#hekir'
log_file = 'log.txt'
owner    = 'Yns_'

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 + " :selam.\r\n" )
while True:
   data = irc.recv ( 4096 )
   # -- Logging In progress -- #
   filehandle = open(log_file, "a+")
   filehandle.write(data)
   filehandle.close()
   
   # -- 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! --
      nick_regex    = re.compile(":(.*)!n")
      message_regex = re.compile(channel + " :(.*)")
      nick    = re.search(nick_regex,data)
      message = re.search(message_regex,data)
      irc.send ( "PRIVMSG " + channel + " :senin nickin " + nick.group(1) + " mesajin :" + message.group(1) + ".\r\n" )
      # -- Close the bot! -- #
      if(message.group(1) and nick.group(1)):
         print message.group(1)
         print nick.group(1)
         if(message.group(1) == "!quit" and nick.group(1) == "owner"):
            irc.send ( 'QUIT\r\n' )
            irc.close()