From 98178e8c2e11038069242d266ad618506c2cef9d Mon Sep 17 00:00:00 2001 From: Ryan Schmidt Date: Mon, 1 Apr 2024 10:03:41 -0700 Subject: [PATCH] Be more intelligent on updating account data on some networks --- src/transport/irc/__init__.py | 8 ++++++++ src/users.py | 9 +++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/transport/irc/__init__.py b/src/transport/irc/__init__.py index aca26f79..ca180f0c 100644 --- a/src/transport/irc/__init__.py +++ b/src/transport/irc/__init__.py @@ -88,6 +88,11 @@ def supports_release(self): def supports_ghost(self): return bool(self.ghost) + # supports changing account after one is already logged in + # (we assume one is always able to log in if not currently authed) + def supports_account_change(self): + return True + class Services_Anope(Services_Base): name = "anope" nickserv = "NickServ" @@ -118,3 +123,6 @@ class Services_Undernet(Services_Base): name = "undernet" nickserv = "x@channels.undernet.org" command = "LOGIN {account} {password}" + + def supports_account_change(self): + return False diff --git a/src/users.py b/src/users.py index 9bd8c90e..49c7003d 100644 --- a/src/users.py +++ b/src/users.py @@ -10,6 +10,7 @@ from src.events import Event, EventListener from src.debug import CheckedDict, CheckedSet, handle_error from src.match import Match +from src.transport.irc import get_services if TYPE_CHECKING: from src.containers import UserSet, UserDict, UserList @@ -227,6 +228,8 @@ def _update_account(evt, user): if evt.params.old in _pending_account_updates: updates = list(_pending_account_updates[evt.params.old].items()) del _pending_account_updates[evt.params.old] + # update user's account timestamp even if it didn't change + user.account_timestamp = time.time() for command, callback in updates: # handle_error swallows exceptions so that a callback raising an exception # does not prevent other registered callbacks from running @@ -587,8 +590,10 @@ def update_account_data(self, command: str, callback: Callable): callback(self) return - if self.account and self.account_timestamp > time.time() - 900: - # account data is less than 15 minutes old, use existing data instead of refreshing + services = get_services() + if self.account and (not services.supports_account_change() or self.account_timestamp > time.time() - 900): + # account data is less than 15 minutes old or we can't change accounts on this ircd, + # use existing data instead of refreshing callback(self) return