def connect(self) -> None:
self._socket = socket()
- self._broadcast(EventType.CONN_ALERT,
+ self._broadcast(EventType.LOG_CONN,
f'Connecting to {self._hostname} …')
self._socket.settimeout(_TIMEOUT_CONNECT)
try:
self._socket.connect((self._hostname, _PORT))
except (TimeoutError, socket_gaierror) as e:
- self._broadcast(EventType.CONN_ALERT, str(e))
+ self._broadcast(EventType.LOG_CONN, f'ALERT: {e}')
return
self._socket.settimeout(TIMEOUT_LOOP)
self._assumed_open = True
def _write_line(self, line: str) -> None:
'Send line-separator-delimited message over socket.'
if not (self._socket and self._assumed_open):
- self._broadcast(EventType.CONN_ALERT,
- 'cannot send, assuming connection closed')
+ self._broadcast(EventType.LOG_CONN,
+ 'ALERT: cannot send, assuming connection closed')
return
self._socket.sendall(line.encode('utf-8') + _IRCSPEC_LINE_SEPARATOR)
'Process connection-directed Event into further steps.'
if event.type_ == EventType.INIT_RECONNECT:
if self._assumed_open:
- self._broadcast(EventType.CONN_ALERT,
- 'Reconnect called, but still seem connected, '
- 'so nothing to do.')
+ self._broadcast(EventType.LOG_CONN,
+ 'ALERT: Reconnect called, but still seem '
+ 'connected, so nothing to do.')
else:
self._start_connecting()
elif event.type_ == EventType.CONNECTED:
self.broadcast(type_, (self._conn_idx, *args))
def _send(self, verb: str, parameters: tuple[str, ...]) -> None:
- self._broadcast_conn(EventType.SEND, IrcMessage(verb, parameters))
+ msg = IrcMessage(verb, parameters)
+ self._broadcast_conn(EventType.LOG_CONN, f'->: {msg.raw}')
+ self._broadcast_conn(EventType.SEND, msg)
def process_main(self, event: Event) -> bool:
if not super().process_main(event):
return False
if event.type_ == EventType.CONNECTED:
login = event.payload[1]
+ # self._send('CAP', ('LS', '302'))
self._send('USER', (login.user, '0', '*', login.real))
self._send('NICK', (login.nick,))
+ # self._send('CAP', ('LIST',))
+ # self._send('CAP', ('END',))
return True
def process_bonus(self, yielded: str) -> None:
msg = IrcMessage.from_raw(yielded)
- self._broadcast_conn(EventType.RECV, msg)
+ self._broadcast_conn(EventType.LOG_CONN, f'<-: {msg}')
if msg.verb == 'PING':
self._send('PONG', (msg.parameters[0],))
elif msg.verb == 'ERROR'\
elif len(yielded) == 1:
self.broadcast(EventType.PROMPT_ADD, yielded)
else:
- self.broadcast(EventType.ALERT,
- f'unknown keyboard input: {yielded}')
+ self.broadcast(EventType.LOG,
+ f'ALERT: unknown keyboard input: {yielded}')
class _TuiLoop(Loop):
self._windows += [conn_win]
self._conn_windows += [conn_win]
self._switch_window(conn_win.idx)
- elif event.type_ == EventType.ALERT:
- self.window.log.append(f'ALERT {event.payload}')
+ elif event.type_ == EventType.LOG:
+ self.window.log.append(event.payload)
self.window.log.draw()
- elif event.type_ in {EventType.RECV, EventType.SEND,
- EventType.CONN_ALERT}:
+ elif event.type_ == EventType.LOG_CONN:
conn_win = self._conn_windows[event.payload[0]]
- if event.type_ == EventType.CONN_ALERT:
- msg = f'ALERT {event.payload[1]}'
- else:
- msg = (('<-' if event.type_ == EventType.RECV else '->')
- + event.payload[1].raw)
- conn_win.log.append(msg)
+ conn_win.log.append(event.payload[1])
if conn_win == self.window:
self.window.log.draw()
elif event.type_ == EventType.NICK_SET:
else:
alert = 'not prefixed by /'
if alert:
- self.broadcast(EventType.ALERT, f'invalid prompt command: {alert}')
+ self.broadcast(EventType.LOG, f'invalid prompt command: {alert}')
def cmd__quit(self) -> None:
'Send QUIT to all threads.'