Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.60 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3.  
  4. from twisted.words.protocols import irc
  5. from twisted.internet import reactor, protocol
  6. from twisted.python import log
  7.  
  8.  
  9. class ircclient(irc.IRCClient):
  10.     #Nick
  11.     nickname = "cj"
  12.     #Real name
  13.     realname = "Carl Johnson"
  14.     #Username
  15.     username = "carl"
  16.     ##Nickserv password
  17.     #password = "NONE"
  18.     #CTCP VERSION reply
  19.     versionName = "GSF test"
  20.     def signedOn(self):
  21.         self.join(self.factory.channel)
  22.     def privmsg(self, user, channel, msg):
  23.         hostmask = user
  24.         nick = user.split('!', 1)[0]
  25.         parts = msg.split(' ')
  26.         if (list(parts[0])[0] == '!'):
  27.             command = ''.join(list(parts[0])[1:])
  28.             try:
  29.                 method = getattr(self, ('cmd_' + command))
  30.                 print method
  31.                 method(self, hostmask, nick, parts, channel)
  32.             except NameError, AttributeError:
  33.                     print "Error ocurred while trying to run %s" % ('cmd_' + command)
  34.                     pass
  35.                
  36.     def cmd_ascii(self, irc, hostmask, nick, parts, channel):
  37.             #if args[1].find('..\\') == True:
  38.                 #self.msg(channel, 'NOPE.')
  39.             #else:
  40.             text = open('C:\\Users\\j\\Desktop\\python\\irc\\a\\%s.txt' % parts[1], 'r')
  41.             for line in text:
  42.                 line = line[0:len(line)-1]
  43.                 irc.msg(channel, line)
  44.  
  45. class ircprotocol(protocol.ClientFactory):
  46.     protocol = ircclient
  47.    
  48.     def __init__(self, channel):
  49.         self.channel = channel
  50.     def clientConnectionLost(self, connector, reason):
  51.         connector.connect()
  52.     def clientConnectionFailed(self, connector, reason):
  53.         print "connection failed:", reason
  54.         reactor.start()
  55. if __name__ == '__main__':
  56.     f = ircprotocol("#bzb")
  57.     reactor.connectTCP("irc.gorf.us", 6667, f)
  58.     reactor.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement