62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
"""
|
|
Bot (GLaDOS)
|
|
============
|
|
|
|
Description
|
|
-----------
|
|
Allow to make and run a Bot instance which will communicate to the V5 server and IRC one.
|
|
"""
|
|
|
|
from secrets import USER, PASSWORD
|
|
from irc import IRC
|
|
from v5 import V5
|
|
|
|
|
|
class Bot:
|
|
"""Run the connexion between IRC's server and V5 one.
|
|
|
|
Attributes
|
|
----------
|
|
irc : IRC, public
|
|
IRC wrapper which handle communication with IRC server.
|
|
v5 : V5, public
|
|
V5 wrapper which handle communication with V5 server.
|
|
channels : list, public
|
|
The channels the bot will listen.
|
|
|
|
Methods
|
|
-------
|
|
start : NoneType, public
|
|
Runs the bot and connects it to IRC and V5 servers.
|
|
"""
|
|
def __init__(self, irc_params: tuple, v5_params: tuple, channels: list):
|
|
"""Initialize the Bot instance.
|
|
|
|
Parameters
|
|
----------
|
|
irc_params : tuple
|
|
Contains the IRC server informations (host, port)
|
|
v5_params : tuple
|
|
Contains the V5 server informations (host, port)
|
|
channels : list
|
|
Contains the names of the channels on which the bot will connect.
|
|
"""
|
|
self.irc = IRC(*irc_params)
|
|
self.channels = channels
|
|
self.v5 = V5(v5_params, self.irc)
|
|
|
|
def start(self):
|
|
"""Starts the bot and connect it to the given IRC and V5 servers."""
|
|
# Start IRC
|
|
self.irc.start(USER, PASSWORD)
|
|
|
|
# Join channels
|
|
for channel in self.channels:
|
|
self.irc.join(channel)
|
|
|
|
# Start v5 handler
|
|
self.v5.start()
|
|
|
|
# Run IRC
|
|
self.irc.run()
|