Esempio n. 1
0
class IRCClient(patterns.Subscriber):

    def __init__(self, HOST, PORT, music):
        super().__init__()
        self.username = str()
        self._run = True
        self._s = SocketClient(HOST, PORT)
        self._s.set_irc(self)
        self.music = music

    def set_view(self, view):
        self.view = view

    def set_username(self, username):
        self.username = username

    def update(self, msg):
        # TODO Will need to modify this
        if not isinstance(msg, str):
            raise TypeError(f"Update argument needs to be a string")
        elif not len(msg):
            # Empty string
            return
        logger.info(f"IRCClient.update -> msg: {msg}")
        self.process_input(msg)

    def process_input(self, msg):
        # TODO Will need to modify this
        self.add_msg(msg)
        self._s.setMsg(msg)

        if msg.lower().startswith('/quit'):
            # Command that leads to the closure of the process
            raise KeyboardInterrupt

    def add_msg(self, msg):
        self.view.add_msg(self.username, msg)

    async def run(self):
        """
        Driver of your IRC Client
        """
        self._s.start()

    def close(self):
        # Terminate connection
        logger.debug(f"Closing IRC Client object")
        pass
Esempio n. 2
0
from socket_client import SocketClient

socket_client = SocketClient()
socket_client.start("192.168.0.15", 65432)
from socket_client import SocketClient

socket_client = SocketClient(socket_numbers=2)
socket_client.add_socket({
    "host": "192.168.1.163",
    "port": 12345
}).add_socket({
    "host": "192.168.1.211",
    "port": 12345
})
socket_client.start()