Document IRC code

pull/1/head
Mark Veidemanis 3 years ago
parent 6339e88385
commit 5350a2e44c
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -37,6 +37,10 @@ class IRCBot(irc.IRCClient):
def parse(self, user, host, channel, msg):
"""
Simple handler for IRC commands.
:param user: full user string with host
:param host: user's hostname
:param channel: channel the message was received on
:param msg: the message
"""
spl = msg.split()
# nick = user.split("!")[0]
@ -101,6 +105,7 @@ class IRCBot(irc.IRCClient):
Called when we have joined a channel.
Setup the Agora LoopingCall to get trades.
This is here to ensure the IRC client is initialised enough to send the trades.
:param channel: channel we joined
"""
self.agora.setup_loop()
self.log.info("Joined channel %s" % (channel))
@ -109,6 +114,9 @@ class IRCBot(irc.IRCClient):
"""
Called on received PRIVMSGs.
Pass through identified commands to the parse function.
:param user: full user string with host
:param channel: channel the message was received on
:param msg: the message
"""
nick = user.split("!")[0]
@ -126,14 +134,17 @@ class IRCBot(irc.IRCClient):
if msg.split()[0] != "!":
self.parse(user, host, channel, msg[1:])
def noticed(self, user, channel, message):
def noticed(self, user, channel, msg):
"""
Called on received NOTICEs.
:param user: full user string with host
:param channel: channel the notice was received on
:param msg: the message
"""
nick = user.split("!")[0]
if channel == self.nickname:
channel = nick
# self.log.info("[%s] %s: %s" % (channel, user, message))
# self.log.info("[%s] %s: %s" % (channel, user, msg))
class IRCBotFactory(protocol.ClientFactory):
@ -157,6 +168,8 @@ class IRCBotFactory(protocol.ClientFactory):
def clientConnectionLost(self, connector, reason):
"""
Called when connection to IRC server lost. Reconnect.
:param connector: connector object
:param reason: reason connection lost
"""
self.log.error("Lost connection (%s), reconnecting" % (reason))
connector.connect()
@ -164,13 +177,17 @@ class IRCBotFactory(protocol.ClientFactory):
def clientConnectionFailed(self, connector, reason):
"""
Called when connection to IRC server failed. Reconnect.
:param connector: connector object
:param reason: reason connection failed
"""
self.log.error("Could not connect: %s" % (reason))
connector.connect()
def bot():
# Load the certificates
context = ssl.DefaultOpenSSLContextFactory(settings.IRC.Cert, settings.IRC.Cert)
# Define the factory instance
factory = IRCBotFactory()
reactor.connectSSL(settings.IRC.Host, int(settings.IRC.Port), factory, context)
return factory

Loading…
Cancel
Save