Skip to content

Commit

Permalink
fix(idlemove): Restore user to their previous channel (#36)
Browse files Browse the repository at this point in the history
Replaces PR #14, Fixes #13
  • Loading branch information
Kissaki committed Mar 15, 2024
2 parents 26f9c68 + 1eab6cc commit 87e82bb
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions modules/idlemove.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def UpdateUserAutoAway(self, server, user):
try:
index = self.affectedusers[sid]
except KeyError:
self.affectedusers[sid] = set()
self.affectedusers[sid] = {}
index = self.affectedusers[sid]

# Check if the user is whitelisted
Expand Down Expand Up @@ -165,7 +165,7 @@ def UpdateUserAutoAway(self, server, user):
update = True

if update:
index.add(user.session)
index[user.session] = user.channel
log.info(
'%ds > %ds: State transition for user %s (%d/%d) from mute %s -> %s / deaf %s -> %s | channel %d -> %d on server %d',
user.idlesecs, threshold, user.name, user.session, user.userid, user.mute, mute, user.deaf,
Expand All @@ -176,8 +176,10 @@ def UpdateUserAutoAway(self, server, user):
if not over_threshold and user.session in self.affectedusers[sid]:
deafen = False
mute = False
channel = user.channel
index.remove(user.session)
try:
channel = index.pop(user.session)
except KeyError:
log.warning("Missing previous channel information on restore")
log.info("Restore user %s (%d/%d) on server %d", user.name, user.session, user.userid, server.id())
update = True

Expand Down Expand Up @@ -222,10 +224,10 @@ def channelStateChanged(self, server, state, context=None):

def started(self, server, context=None):
sid = server.id()
self.affectedusers[sid] = set()
self.affectedusers[sid] = {}
self.log().debug('Handling server %d', sid)

def stopped(self, server, context=None):
sid = server.id()
self.affectedusers[sid] = set()
self.affectedusers[sid] = {}
self.log().debug('Server %d gone', sid)

0 comments on commit 87e82bb

Please sign in to comment.