Advertisement
Aha2Y

Untitled

Apr 2nd, 2012
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.50 KB | None | 0 0
  1. #!/usr/bin/python
  2. from ConfigParser import RawConfigParser as ConfParser
  3. from optparse import OptionParser
  4. from collections import deque
  5. from time import sleep, time, gmtime, strftime
  6. import ConfigParser
  7. import datetime
  8. import os
  9. import sys
  10. import socket
  11. import codecs
  12. from irc import *
  13. from select import select
  14.  
  15. try:
  16.    config = ConfigParser.RawConfigParser()
  17.    config.readfp(codecs.open("config.ini", "r", "utf8"))
  18. except IOError as config:
  19.    sys.exit()
  20.    
  21. irc = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
  22. irc.connect ((config.get('connection', 'server'),config.getint('connection', 'port')))
  23. irc.send ('NICK %s\r\n' % config.get('irc-bot', 'nickname'))
  24. irc.send ('USER %s %s pybnc :%s\r\n' % (config.get('irc-bot', 'nickname'), config.get('irc-bot', 'ident'), config.get('irc-bot', 'realname')))
  25. while 1:
  26.     (rl, wl, xl) = select([irc, bnc], [], [])
  27.     for sock in rl:
  28.         data = readline(sock)
  29.         raw = parse(data)
  30.         if sock == irc:
  31.             if raw[0] == "PING":
  32.                sock.send("PONG %s\r\n" % raw[1])
  33.             if raw[1] == "376" and raw[3] == "End of /MOTD command.":
  34.                irc.send('JOIN %s \r\n' % config.get('irc-bot', 'mainchan'))
  35.                print('%s IRC Connection established.' % timestamp)
  36.             if raw[0].startswith("NickServ!"):
  37.                if raw[1] == "NOTICE" and "This nickname is registered" in raw[3]:
  38.                   irc.send('PRIVMSG NickServ :identify %s \r\n' % config.get('irc-bot', 'nickpass'))
  39.             if raw[1] == "PRIVMSG":
  40.                my.sender = raw[0]
  41.                my.nick = raw[0].split("!")[0]
  42.                my.auth = data.split('@')[0][1:]
  43.                if len(raw) > 3:
  44.                   if raw[3] == "!uptime":
  45.                      chanQueue.append(raw[2])
  46.                      end = time()
  47.                      uptime = end - start
  48.                      bnc.send('PRIVMSG *status :uptime \r\n')
  49.                      irc.send('PRIVMSG %s :The bot is running for %s \r\n' % (raw[2], duration_human(uptime)))
  50.                if raw[3] == "!rehash":
  51.                   try:
  52.                      if config.get('staff', my.auth) == 'admin':
  53.                         chanQueue.append(raw[2])
  54.                         bnc.send('PRIVMSG *status :rehash\r\n')
  55.                         irc.send('PRIVMSG %s :Bouncer successfuly rehashed!\r\n' % raw[2])
  56.                   except ConfigParser.NoOptionError:
  57.                      irc.send('PRIVMSG %s :I don\'t recognize you. \r\n' % raw[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement