Skip to content

Commit

Permalink
Fix channel mode parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmaguire committed Feb 14, 2024
1 parent 38b3446 commit 2be01e7
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions cardinal/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def irc_MODE(self, prefix, params):
self.channels.set_modes(channel, modes, args)

user = self.get_user_tuple(prefix)
mode = modes + ' ' + ' '.join(args)
mode = (modes + ' ' + ' '.join(args)).strip()

# Sent by network, not a real user
if not user:
Expand Down Expand Up @@ -784,17 +784,10 @@ def __init__(self, chanmodes, param_modes):
# param - param changed (always takes a param)
# setParam - param taken when mode is set
# noParam - no param necessary
#
# Convert it to e.g. {mode: addressParam}
self.chanmodes = {}
for k, v in chanmodes.items():
for mode in v:
self.chanmodes[v] = {
'addressModes': 'addressParam',
'param': 'param',
'setParam': 'setParam',
'noParam': 'noParam',
}[k]
self.chanmodes[mode] = k

# Keeping this around so we can make a call to irc.parseModes
self._twisted_param_modes = param_modes
Expand Down Expand Up @@ -826,7 +819,7 @@ def set_modes(self, channel, modes, args):
# parse mode changes out into added and removed
try:
added, removed = irc.parseModes(
modes, args, self._twisted_param_modes)
modes, args.copy(), self._twisted_param_modes)
except KeyError:
self.logger.error("Error parsing modes for {channel}: {modes}"
.format(channel=channel,
Expand All @@ -835,7 +828,7 @@ def set_modes(self, channel, modes, args):

# set modes
for mode, param in added:
if self.chanmodes.get(mode) == "addressParam":
if self.chanmodes.get(mode) == "addressModes":
chan.modes[mode] = chan.modes.get(mode, []).append(param)

elif self.chanmodes.get(mode) in ("param", "setParam"):
Expand All @@ -857,7 +850,7 @@ def set_modes(self, channel, modes, args):
.format(mode=mode))
continue

if self.chanmodes.get(mode) == "addressParam":
if self.chanmodes.get(mode) == "addressModes":
chan.modes[mode] = chan.modes[mode].remove(param)

elif self.chanmodes.get(mode) == "param":
Expand Down

0 comments on commit 2be01e7

Please sign in to comment.