ClientsDb = dict[str, 'Client']
_NAMES_DESIRED_SERVER_CAPS = ('server-time', 'account-tag', 'sasl')
-_NUMERICS_TO_IGNORE = ( # tuples define (inclusive) ranges
- (2, 4), # nothing in this login info we're interested in
+
+# NB: in below numerics accounting, tuples define inclusive ranges
+_NUMERICS_TO_CONFIRM_NICKNAME = (
+ (1, 5),
+ (251, 255),
+ (265, 266),
+ 372,
+ (375, 376),
+)
+_NUMERICS_TO_IGNORE = (
+ (1, 4), # nothing in this login info we're interested in
(251, 255), # same
(265, 266), # same
375, # RPL_MOTDSTART already implied to us by first appearance of 372
SAME = auto()
+class _Numerics:
+ 'To easen dealing with numeric replies.'
+
+ def __init__(self, numerics: tuple[int | tuple[int, int], ...]) -> None:
+ as_ints = []
+ for item in numerics:
+ as_ints += ([item] if isinstance(item, int)
+ else list(range(item[0], item[1] + 1)))
+ self._numerics = tuple(as_ints)
+
+ def contain(self, msg_verb: str) -> bool:
+ 'Is int(msg_verb) within the listed numbers?'
+ return msg_verb.isdigit() and int(msg_verb) in self._numerics
+
+
+_NumericsToIgnore = _Numerics(_NUMERICS_TO_IGNORE)
+_NumericsToConfirmNickname = _Numerics(_NUMERICS_TO_CONFIRM_NICKNAME)
+
+
@dataclass
class ClientIdMixin:
'Collects a Client\'s ID at .client_id.'
if msg.verb != self._prev_verb and self._prev_verb == '005':
self._update_db('isupports', None, True)
self._prev_verb = msg.verb
- numerics_to_ignore = []
- for item in _NUMERICS_TO_IGNORE:
- if isinstance(item, tuple):
- numerics_to_ignore += list(range(item[0], item[1] + 1))
- else:
- numerics_to_ignore += [item]
- if msg.verb.isdigit() and int(msg.verb) in numerics_to_ignore:
+ if _NumericsToConfirmNickname.contain(msg.verb):
+ self._update_db('nickname', value=msg.params[0], confirm=True)
+ if _NumericsToIgnore.contain(msg.verb):
return
match msg.verb:
- case '001' | 'NICK':
+ case 'NICK':
self._update_db('nickname', value=msg.params[0], confirm=True)
case '005':
for param in msg.params[1:-1]: