52 lines
1.4 KiB
Python
Executable File
52 lines
1.4 KiB
Python
Executable File
"""
|
|
|
|
IRC Socket Client
|
|
=================
|
|
|
|
Formatted to read and write IRC socket data
|
|
|
|
"""
|
|
|
|
from abots.net import SocketClient
|
|
|
|
from socket import timeout as sock_timeout
|
|
|
|
class IRCSocketClient(SocketClient):
|
|
def __init__(self, *args, **kwargs):
|
|
kwargs["buffer_size"] = 512
|
|
super().__init__(*args, **kwargs)
|
|
|
|
def _format_message(self, message, *args):
|
|
if len(args) > 0:
|
|
formatted = message.format(*args)
|
|
else:
|
|
formatted = message
|
|
packaged = f"{formatted}\r\n"
|
|
return packaged.encode()
|
|
|
|
#def recv(self):
|
|
# data = ""
|
|
# for buf in self._obtain(self._outbox):
|
|
# data = data + buf
|
|
# return data
|
|
|
|
# See rfc2812
|
|
#max_message_length = 512
|
|
#while True:#len(data) <= max_message_length:
|
|
# # Automatically break loop to prevent infinite loop
|
|
# # Allow at least twice the needed iterations to occur exiting loop
|
|
# # Force bufsize to cap out at buffer_size
|
|
# try:
|
|
# packet = self.sock.recv()#self.buffer_size)
|
|
# # The socket can either be broken or no longer open at all
|
|
# except (BrokenPipeError, OSError) as e:
|
|
# #if not isinstance(e, sock_timeout):
|
|
# # self._attempt_reconnect()
|
|
# continue
|
|
# #print(packet.decode())
|
|
# if len(packet) == 0:
|
|
# break
|
|
# data = data + packet
|
|
##print(data.decode())
|
|
#return data.decode() if decode else data
|