_NAMES_DESIRED_SERVER_CAPS = ('sasl',)
-class Alert(BaseException):
+class SendFail(BaseException):
pass
'Where log messages should go.'
ALL = auto()
SERVER = auto()
- #
RAW = auto()
- #
CHAT = auto()
USER = auto()
USER_NO_CHANNELS = auto()
- #
SAME = auto()
def send(self, verb: str, *args) -> None:
'Send msg over socket, on success log .raw.'
- if self.conn:
- msg = IrcMessage(verb, args)
- self.conn.send(msg)
- self._log(msg.raw, scope=LogScope.RAW, out=True)
- else:
- self._log('cannot send, connection seems closed', alert=True,
- scope=LogScope.SAME)
+ if not self.conn:
+ raise SendFail('cannot send, connection seems closed')
+ msg = IrcMessage(verb, args)
+ self.conn.send(msg)
+ self._log(msg.raw, scope=LogScope.RAW, out=True)
def handle_msg(self, msg: IrcMessage) -> None:
'Log msg.raw, then process incoming msg into appropriate client steps.'
CMD_SHORTCUTS)
from ircplom.client import (
AutoAttrMixin, Channel, Client, ClientQueueMixin, Dict, DictItem,
- IrcConnSetup, LogScope, NewClientEvent, NickUserHost, ServerCapability,
- SharedClientDbFields, User)
+ IrcConnSetup, LogScope, NewClientEvent, NickUserHost, SendFail,
+ ServerCapability, SharedClientDbFields, User)
CMD_SHORTCUTS['disconnect'] = 'window.disconnect'
CMD_SHORTCUTS['join'] = 'window.join'
def privmsg(self, target: str, msg: str) -> None:
'Catch /privmsg, only allow for channel if in channel, else complain.'
- if self.db.is_chan_name(target)\
- and target not in self.db.channels.keys():
- self._log('not sending, since not in channel',
- scope=LogScope.SAME, alert=True)
- return
- self.send('PRIVMSG', target, msg)
- self._log(msg, scope=LogScope.CHAT, target=target, out=True)
+ try:
+ if self.db.is_chan_name(target)\
+ and target not in self.db.channels.keys():
+ raise SendFail('not sending, since not in channel')
+ self.send('PRIVMSG', target, msg)
+ except SendFail as e:
+ self._log(f'{e}', scope=LogScope.SAME, alert=True)
+ else:
+ self._log(msg, scope=LogScope.CHAT, target=target, out=True)
def reconnect(self) -> None:
'Catch /reconnect, only initiate if not connected, else complain back.'
1,2 $ channels cleared
1,2 $ users cleared
+# fail to send in disconnect, check alert window is command prompt window
+> /window 7
+> /privmsg barbar test
+7 !$ cannot send, connection seems closed
+> /window 1
+> /privmsg barbar test
+1 !$ cannot send, connection seems closed
+> /privmsg #test test
+1 !$ not sending, since not in channel
+
# test setting up second client, but 432 irrecoverably
> /connect baz.bar.foo ?foo foo:foo
8,9 $ isupport cleared