Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Mar 26th, 2010  |  syntax: Python  |  size: 2.33 KB  |  views: 232  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. from twisted.application import internet, service
  2. from twisted.internet import protocol, reactor, defer
  3. from twisted.words.protocols import irc
  4. from twisted.protocols import basic
  5. from twisted.web import resource, server, static
  6.  
  7. from twisted.internet.protocol import Protocol
  8.  
  9.  
  10. class ircProtocol(irc.IRCClient):
  11.     def _get_nickname(self):
  12.         return self.factory.nickname
  13.     nickname = property(_get_nickname)
  14.  
  15.     def signedOn(self):
  16.         self.join(self.factory.channel)
  17.  
  18. #    def privmsg(self, user, channel, msg):
  19. #        user = user.split('!')[0]
  20. #        d = self.factory.msgAlert(msg)
  21.  
  22. #        def onError(err):
  23. #            return 'Internal error in server'
  24. #        d.addErrback(onError)
  25.  
  26. #        def writeResponse(message):
  27. #            irc.IRCClient.msg(self, channel, msg+': '+message)
  28. #        d.addCallback(writeResponse)
  29.  
  30. #    def msgAlert(self, alert):
  31. #        self.factory.
  32.     def dupa1(self, msg):
  33.         print msg
  34.         #irc.IRCClient.msg(self, '#asdf666', msg)
  35.         self.IRCClient.msg('#asdf666', msg)
  36.  
  37. class ircFactory(protocol.ClientFactory):
  38.     protocol = ircProtocol
  39.  
  40.     def __init__(self, nickname, channel):
  41.         self.nickname = nickname
  42.         self.channel = channel
  43.  
  44.     def dupa(self, msg):
  45.         self.protocol.dupa1(msg)
  46.  
  47. #    def msgAlert(self, alert):
  48. #        print "alert=> " + alert
  49.  
  50. class nagiosProtocol(Protocol):
  51.  
  52.     def connectionMade(self):
  53.         print "New connection from nagios"
  54.  
  55.     def connectionLost(self, reason):
  56.         print "Lost connection from nagios: %s" % reason
  57.  
  58.     def dataReceived(self, line):
  59.        self.factory.irc.dupa(line)
  60.  
  61.  
  62. class nagiosFactory(protocol.ServerFactory):
  63.     protocol = nagiosProtocol
  64.  
  65.     def __init__(self, irc):
  66.         self.irc = irc
  67.  
  68. #    def sendAlert(self, alert):
  69. #        print "sendAlert"
  70. #        self.ircFactory.msgAlert(alert)
  71.  
  72. #b = internet.TCPServer(6666, nagiosFactory())
  73. #b.setName('fnagios')
  74. #b.setServiceParent(myservice)
  75.  
  76. #myservice.setServiceParent(application)
  77.  
  78. application = service.Application("dupa")
  79.  
  80. ircf = ircFactory('asdfasdf', '#asdf666')
  81. irc = internet.TCPClient('irc.freenode.net', 6667, ircf)
  82. irc.setName('irc')
  83. irc.setServiceParent(application)
  84.  
  85. nagios = internet.TCPServer(6666, nagiosFactory(ircf))
  86. nagios.setName("Nagios")
  87. nagios.setServiceParent(application)
clone this paste RAW Paste Data