Skip to content

Commit

Permalink
Be more intelligent on updating account data on some networks
Browse files Browse the repository at this point in the history
  • Loading branch information
skizzerz committed Apr 1, 2024
1 parent b4766c7 commit 98178e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/transport/irc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -118,3 +123,6 @@ class Services_Undernet(Services_Base):
name = "undernet"
nickserv = "[email protected]"
command = "LOGIN {account} {password}"

def supports_account_change(self):
return False
9 changes: 7 additions & 2 deletions src/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 98178e8

Please sign in to comment.