'Reply if attribute of key may reasonably be addressed without an arg.'
return not isinstance(getattr(self, key), (bool, int, str, tuple))
+ @property
+ def chan_names(self) -> tuple[str, ...]:
+ 'Return names of joined channels.'
+ return tuple(self._channels.keys())
+
def del_chan(self, name: str) -> None:
'Remove DB for channel of name.'
del self._channels[name]
self._on_update(name)
- def has_chan(self, name: str) -> bool:
- 'Test if entry of name in channels dictionary.'
- return name in self._channels
-
def chan(self, name: str) -> _ChannelDb:
'Produce DB for channel of name – pre-existing, or newly created.'
if name not in self._channels:
if self.conn:
self.conn.close()
self.conn = None
+ for name in self._db.chan_names:
+ self._db.del_chan(name)
self._db.isupports.clear()
self._db.nickname = ''
self._db.sasl_auth_state = ''
def cmd__privmsg(self, target: str, msg: str) -> None:
'Send chat message msg to target.'
- self._send_msg('PRIVMSG', (target, msg), log_target=target, to_log=msg)
+ self._client_trigger('privmsg', target=target, msg=msg)
def cmd__raw(self, verb: str, params_str: str = '') -> None:
'Send raw command, with direct input of params string.'
self._put(TuiEvent.affector('for_client_do').kw(
client_id=self.client_id, todo=todo, **kwargs))
+ def privmsg(self, target: str, msg: str) -> None:
+ 'Catch /privmsg, only allow for channel if in channel, else complain.'
+ if target[0] == '#' and target not in self._db.chan_names:
+ self._log('not sending, since not in channel',
+ scope=LogScope.SAME, alert=True)
+ return
+ self.send(IrcMessage('PRIVMSG', (target, msg)),
+ log_target=target, to_log=msg)
+
def reconnect(self) -> None:
'Catch /reconnect, only initiate if not connected, else complain back.'
if self.conn:
is_chan = path[0] == '#'
display = ''
if arg:
- if is_chan and self._db.has_chan(path):
- is_chan = True
+ if is_chan and path in self._db.chan_names:
if (chan := self._db.chan(path)) and hasattr(chan, arg):
value = getattr(chan, arg)
else: