Add more detail in IRC docstrings

This commit is contained in:
Mark Veidemanis 2021-12-27 21:27:41 +00:00
parent 661582a97d
commit 7c8f77df40
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 27 additions and 2 deletions

View File

@ -12,6 +12,11 @@ from settings import settings
class IRCBot(irc.IRCClient): class IRCBot(irc.IRCClient):
def __init__(self, log): def __init__(self, log):
"""
Initialise IRC bot.
:param log: logger instance
:type log: Logger
"""
self.log = log self.log = log
self.nickname = settings.IRC.Nick self.nickname = settings.IRC.Nick
self.password = settings.IRC.Pass self.password = settings.IRC.Pass
@ -41,6 +46,10 @@ class IRCBot(irc.IRCClient):
:param host: user's hostname :param host: user's hostname
:param channel: channel the message was received on :param channel: channel the message was received on
:param msg: the message :param msg: the message
:type user: string
:type host: string
:type channel: string
:type msg: string
""" """
spl = msg.split() spl = msg.split()
# nick = user.split("!")[0] # nick = user.split("!")[0]
@ -106,6 +115,7 @@ class IRCBot(irc.IRCClient):
Setup the Agora LoopingCall to get trades. Setup the Agora LoopingCall to get trades.
This is here to ensure the IRC client is initialised enough to send the trades. This is here to ensure the IRC client is initialised enough to send the trades.
:param channel: channel we joined :param channel: channel we joined
:type channel: string
""" """
self.agora.setup_loop() self.agora.setup_loop()
self.log.info("Joined channel %s" % (channel)) self.log.info("Joined channel %s" % (channel))
@ -117,6 +127,9 @@ class IRCBot(irc.IRCClient):
:param user: full user string with host :param user: full user string with host
:param channel: channel the message was received on :param channel: channel the message was received on
:param msg: the message :param msg: the message
:type user: string
:type channel: string
:type msg: string
""" """
nick = user.split("!")[0] nick = user.split("!")[0]
@ -140,6 +153,9 @@ class IRCBot(irc.IRCClient):
:param user: full user string with host :param user: full user string with host
:param channel: channel the notice was received on :param channel: channel the notice was received on
:param msg: the message :param msg: the message
:type user: string
:type channel: string
:type msg: string
""" """
nick = user.split("!")[0] nick = user.split("!")[0]
if channel == self.nickname: if channel == self.nickname:
@ -170,8 +186,10 @@ class IRCBotFactory(protocol.ClientFactory):
Called when connection to IRC server lost. Reconnect. Called when connection to IRC server lost. Reconnect.
:param connector: connector object :param connector: connector object
:param reason: reason connection lost :param reason: reason connection lost
:type connector: object
:type reason: string
""" """
self.log.error("Lost connection (%s), reconnecting" % (reason)) self.log.error("Lost connection: {reason}, reconnecting", reason=reason)
connector.connect() connector.connect()
def clientConnectionFailed(self, connector, reason): def clientConnectionFailed(self, connector, reason):
@ -179,12 +197,19 @@ class IRCBotFactory(protocol.ClientFactory):
Called when connection to IRC server failed. Reconnect. Called when connection to IRC server failed. Reconnect.
:param connector: connector object :param connector: connector object
:param reason: reason connection failed :param reason: reason connection failed
:type connector: object
:type reason: string
""" """
self.log.error("Could not connect: %s" % (reason)) self.log.error("Could not connect: {reason}", reason=reason)
connector.connect() connector.connect()
def bot(): def bot():
"""
Load the certificates, start the Bot Factory and connect it to the IRC server.
:return: Factory instance
:rtype: Factory
"""
# Load the certificates # Load the certificates
context = ssl.DefaultOpenSSLContextFactory(settings.IRC.Cert, settings.IRC.Cert) context = ssl.DefaultOpenSSLContextFactory(settings.IRC.Cert, settings.IRC.Cert)
# Define the factory instance # Define the factory instance