39 lines
1002 B
Python
39 lines
1002 B
Python
import sys
|
|
|
|
from twisted.words.protocols import irc
|
|
from twisted.internet import protocol, reactor
|
|
|
|
|
|
class IDRTBot(irc.IRCClient):
|
|
@property
|
|
def nickname(self):
|
|
return self.factory.nickname
|
|
|
|
def signedOn(self):
|
|
self.join(self.factory.channel)
|
|
print('signed on as {}.'.format(self.nickname))
|
|
|
|
def joined(self, channel):
|
|
print('joined {}'.format(channel))
|
|
|
|
def privmsg(self, user, channel, msg):
|
|
print('{} | {} | {}'.foramt(user, channel, msg))
|
|
|
|
|
|
class IDRTBotFactory(protocol.ClientFactory):
|
|
protocol = IDRTBot
|
|
|
|
def __init__(self, channel, nickname='idrt'):
|
|
self.channel = channel
|
|
self.nickname = nickname
|
|
|
|
def clientConnectionLost(self, connector, reason):
|
|
print('lost connection({}), reconnecting.'.format(reason))
|
|
|
|
def clientConnectionFailed(self, connector, reason):
|
|
print('could not connect: {}'.format(reason))
|
|
|
|
|
|
reactor.connectTCP('localhost', 6668, IDRTBotFactory('#smb'))
|
|
reactor.run()
|