Advertisement
Aha2Y

Untitled

Mar 9th, 2012
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.67 KB | None | 0 0
  1. #!/usr/bin/python
  2. version = '2.1.5'
  3. import sys
  4. import os
  5. import string
  6. import random  
  7. import urllib
  8. import socket
  9. import time
  10. import re
  11. import StringIO
  12. import getpass
  13. import shelve
  14. import traceback
  15. import csv
  16. import pickle
  17. from time import *
  18.  
  19. server = 'irc.rizon.net'      
  20. port = 6667                            
  21. myname = 'InfoBot'
  22. identd = 'Bot'
  23. real_name = "Python IRC Information Bot"    
  24. nickpass = 'secret555555555555555555555555'
  25. channels = ["#Aha2Y", "#Digital_Lemon"] # a list so it does the FOR properly :)
  26. version = '3.5'
  27.  
  28. irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
  29. irc.connect ( ( server, port) )
  30. irc.send ( 'NICK %s\r\n' % myname)
  31. irc.send ( 'USER %s %s %s :%s\r\n' % (identd, identd, identd, real_name))
  32.  
  33. connected = 1
  34. while True:
  35.    data = irc.recv ( 4096 )
  36.    raw = data.split()
  37.    print data
  38.    if connected == 3:
  39.       break
  40.    if data.find ( 'PING' ) != -1:
  41.       irc.send( 'PONG ' + data.split() [ 1 ] + '\r\n' )
  42.    if data.find('This nickname is registered and protected.') != -1:
  43.       identify()
  44.    if data.find('End of /MOTD command.') != -1:
  45.       perform()
  46.    def perform():
  47.       irc.send('mode %s +B\r\n' % myname)
  48.       irc.send('mode %s +B\r\n' % myname)
  49.       irc.send('mode %s +B\r\n' % myname)
  50.    for channel in channels:
  51.       irc.send('JOIN %s\r\n' % channel)
  52.       sleep(0.5)
  53.       connected = connected + 1
  54.    def identify():
  55.       irc.send('privmsg NickServ :Identify %s\r\n' % nickpass)
  56.       irc.send('privmsg NickServ :update\r\n')
  57.       connected = connected + 1
  58.  
  59. prefix = "!"
  60.  
  61. def _processMessage(raw):
  62.    sender = raw[0][1:] #SOME HARCORE CODING :D
  63.    data = {"nick": sender.split("!")[0], "ident": sender.split("!")[1].split("@")[0],
  64.                  "host": sender.split("@")[1], "type": raw[1], "source": raw[2],
  65.                  "command": raw[3][2:]}
  66.    if len(raw) > 3:
  67.       data["args"] = raw[3:][0]
  68.    return data
  69.  
  70. while True:
  71.    incoming = irc.recv ( 4096 )
  72.    raw = incoming.split()
  73.    print incoming
  74.    if incoming.find(':\001VERSION\001') != -1:
  75.       irc.send('NOTICE '+ raw[0].split('!')[0] +' :\001VERSION  OMG VERSION!\001\r\n')
  76.    if incoming.startswith('PING'): # We need to reply to ping, PONG!
  77.       irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' )
  78.       continue
  79.    try:
  80.       if not raw[3].startswith(":" + prefix):
  81.          continue
  82.    except:
  83.       continue
  84.    data = _processMessage(raw) # data is acquired here, if you want it on the upper level, process it manually.
  85.    if data['command'] == "ping": # Simple command to check if the bot works on trigger.
  86.       if len(raw) != 5:      
  87.          irc.send('privmsg %s :pong!\r\n' % raw[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement