Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from ConfigParser import RawConfigParser as ConfParser
- from optparse import OptionParser
- from collections import deque
- from time import sleep, time, gmtime, strftime
- import ConfigParser
- import datetime
- import os
- import sys
- import socket
- import codecs
- from irc import *
- from select import select
- try:
- config = ConfigParser.RawConfigParser()
- config.readfp(codecs.open("config.ini", "r", "utf8"))
- except IOError as config:
- sys.exit()
- irc = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
- irc.connect ((config.get('connection', 'server'),config.getint('connection', 'port')))
- irc.send ('NICK %s\r\n' % config.get('irc-bot', 'nickname'))
- irc.send ('USER %s %s pybnc :%s\r\n' % (config.get('irc-bot', 'nickname'), config.get('irc-bot', 'ident'), config.get('irc-bot', 'realname')))
- while 1:
- (rl, wl, xl) = select([irc, bnc], [], [])
- for sock in rl:
- data = readline(sock)
- raw = parse(data)
- if sock == irc:
- if raw[0] == "PING":
- sock.send("PONG %s\r\n" % raw[1])
- if raw[1] == "376" and raw[3] == "End of /MOTD command.":
- irc.send('JOIN %s \r\n' % config.get('irc-bot', 'mainchan'))
- print('%s IRC Connection established.' % timestamp)
- if raw[0].startswith("NickServ!"):
- if raw[1] == "NOTICE" and "This nickname is registered" in raw[3]:
- irc.send('PRIVMSG NickServ :identify %s \r\n' % config.get('irc-bot', 'nickpass'))
- if raw[1] == "PRIVMSG":
- my.sender = raw[0]
- my.nick = raw[0].split("!")[0]
- my.auth = data.split('@')[0][1:]
- if len(raw) > 3:
- if raw[3] == "!uptime":
- chanQueue.append(raw[2])
- end = time()
- uptime = end - start
- bnc.send('PRIVMSG *status :uptime \r\n')
- irc.send('PRIVMSG %s :The bot is running for %s \r\n' % (raw[2], duration_human(uptime)))
- if raw[3] == "!rehash":
- try:
- if config.get('staff', my.auth) == 'admin':
- chanQueue.append(raw[2])
- bnc.send('PRIVMSG *status :rehash\r\n')
- irc.send('PRIVMSG %s :Bouncer successfuly rehashed!\r\n' % raw[2])
- except ConfigParser.NoOptionError:
- irc.send('PRIVMSG %s :I don\'t recognize you. \r\n' % raw[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement