initial twisted bot
This commit is contained in:
commit
c9a85cdaa7
38
tbot.py
Normal file
38
tbot.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
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()
|
Loading…
Reference in New Issue
Block a user