Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- version = '2.1.5'
- import sys
- import os
- import string
- import random
- import urllib
- import socket
- import time
- import re
- import StringIO
- import getpass
- import shelve
- import traceback
- import csv
- import pickle
- from time import *
- server = 'irc.rizon.net'
- port = 6667
- myname = 'InfoBot'
- identd = 'Bot'
- real_name = "Python IRC Information Bot"
- nickpass = 'secret555555555555555555555555'
- channels = ["#Aha2Y", "#Digital_Lemon"] # a list so it does the FOR properly :)
- version = '3.5'
- irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
- irc.connect ( ( server, port) )
- irc.send ( 'NICK %s\r\n' % myname)
- irc.send ( 'USER %s %s %s :%s\r\n' % (identd, identd, identd, real_name))
- connected = 1
- while True:
- data = irc.recv ( 4096 )
- raw = data.split()
- print data
- if connected == 3:
- break
- if data.find ( 'PING' ) != -1:
- irc.send( 'PONG ' + data.split() [ 1 ] + '\r\n' )
- if data.find('This nickname is registered and protected.') != -1:
- identify()
- if data.find('End of /MOTD command.') != -1:
- perform()
- def perform():
- irc.send('mode %s +B\r\n' % myname)
- irc.send('mode %s +B\r\n' % myname)
- irc.send('mode %s +B\r\n' % myname)
- for channel in channels:
- irc.send('JOIN %s\r\n' % channel)
- sleep(0.5)
- connected = connected + 1
- def identify():
- irc.send('privmsg NickServ :Identify %s\r\n' % nickpass)
- irc.send('privmsg NickServ :update\r\n')
- connected = connected + 1
- prefix = "!"
- def _processMessage(raw):
- sender = raw[0][1:] #SOME HARCORE CODING :D
- data = {"nick": sender.split("!")[0], "ident": sender.split("!")[1].split("@")[0],
- "host": sender.split("@")[1], "type": raw[1], "source": raw[2],
- "command": raw[3][2:]}
- if len(raw) > 3:
- data["args"] = raw[3:][0]
- return data
- while True:
- incoming = irc.recv ( 4096 )
- raw = incoming.split()
- print incoming
- if incoming.find(':\001VERSION\001') != -1:
- irc.send('NOTICE '+ raw[0].split('!')[0] +' :\001VERSION OMG VERSION!\001\r\n')
- if incoming.startswith('PING'): # We need to reply to ping, PONG!
- irc.send ( 'PONG ' + data.split() [ 1 ] + '\r\n' )
- continue
- try:
- if not raw[3].startswith(":" + prefix):
- continue
- except:
- continue
- data = _processMessage(raw) # data is acquired here, if you want it on the upper level, process it manually.
- if data['command'] == "ping": # Simple command to check if the bot works on trigger.
- if len(raw) != 5:
- irc.send('privmsg %s :pong!\r\n' % raw[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement