Skip to content

Commit

Permalink
Merge pull request #2129 from sopel-irc/remove-bot.privileges
Browse files Browse the repository at this point in the history
bot, coretasks: remove redundant `bot.privileges` data structure
  • Loading branch information
dgw authored Jul 7, 2021
2 parents ab59a36 + f01d622 commit 677cdbf
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 102 deletions.
12 changes: 0 additions & 12 deletions sopel/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,6 @@ def __init__(self, config, daemon=False):
For servers that do not support IRCv3, this will be an empty set.
"""

self.privileges = dict()
"""A dictionary of channels to their users and privilege levels.
The value associated with each channel is a dictionary of
:class:`sopel.tools.Identifier`\\s to a bitwise integer value,
determined by combining the appropriate constants from
:mod:`sopel.plugin`.
.. deprecated:: 6.2.0
Use :attr:`channels` instead. Will be removed in Sopel 8.
"""

self.channels = tools.SopelIdentifierMemory()
"""A map of the channels that Sopel is in.
Expand Down
41 changes: 1 addition & 40 deletions sopel/coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,6 @@ def handle_names(bot, trigger):
if not channels:
return
channel = Identifier(channels.group(1))
if channel not in bot.privileges:
bot.privileges[channel] = {}
if channel not in bot.channels:
bot.channels[channel] = target.Channel(channel)

Expand Down Expand Up @@ -479,7 +477,6 @@ def handle_names(bot, trigger):
priv = priv | value

nick = Identifier(name.lstrip(''.join(mapping.keys())))
bot.privileges[channel][nick] = priv
user = bot.users.get(nick)
if user is None:
# The username/hostname will be included in a NAMES reply only if
Expand Down Expand Up @@ -593,31 +590,12 @@ def _parse_modes(bot, args, clear=False):
# User privs modes, always have a param
nick = Identifier(params[param_idx])
priv = channel.privileges.get(nick, 0)
# Log a warning if the two privilege-tracking data structures
# get out of sync. That should never happen.
# This is a good place to verify that bot.channels is doing
# what it's supposed to do before ultimately removing the old,
# deprecated bot.privileges structure completely.
ppriv = bot.privileges[channel_name].get(nick, 0)
if priv != ppriv:
LOGGER.warning(
(
"Privilege data error! Please share Sopel's "
"raw log with the developers, if enabled. "
"(Expected %s == %s for %r in %r)"
),
priv,
ppriv,
nick,
channel,
)
value = mapping.get(char)
if value is not None:
if sign == "+":
priv = priv | value
else:
priv = priv & ~value
bot.privileges[channel_name][nick] = priv
channel.privileges[nick] = priv
param_idx += 1
else:
Expand Down Expand Up @@ -652,7 +630,7 @@ def track_nicks(bot, trigger):
old = trigger.nick
new = Identifier(trigger)

# Give debug mssage, and PM the owner, if the bot's own nick changes.
# Give debug message, and PM the owner, if the bot's own nick changes.
if old == bot.nick and new != bot.nick:
privmsg = (
"Hi, I'm your bot, %s. Something has made my nick change. This "
Expand All @@ -669,12 +647,6 @@ def track_nicks(bot, trigger):
bot.say(privmsg, bot.config.core.owner)
return

for channel in bot.privileges:
channel = Identifier(channel)
if old in bot.privileges[channel]:
value = bot.privileges[channel].pop(old)
bot.privileges[channel][new] = value

for channel in bot.channels.values():
channel.rename_user(old, new)
if old in bot.users:
Expand Down Expand Up @@ -715,7 +687,6 @@ def track_kick(bot, trigger):

def _remove_from_channel(bot, nick, channel):
if nick == bot.nick:
bot.privileges.pop(channel, None)
bot.channels.pop(channel, None)

lost_users = []
Expand All @@ -726,8 +697,6 @@ def _remove_from_channel(bot, nick, channel):
for nick_ in lost_users:
bot.users.pop(nick_, None)
else:
bot.privileges[channel].pop(nick, None)

user = bot.users.get(nick)
if user and channel in user.channels:
bot.channels[channel].clear_user(nick)
Expand Down Expand Up @@ -793,7 +762,6 @@ def track_join(bot, trigger):

# is it a new channel?
if channel not in bot.channels:
bot.privileges[channel] = {}
bot.channels[channel] = target.Channel(channel)

# did *we* just join?
Expand All @@ -812,8 +780,6 @@ def track_join(bot, trigger):
str(channel), trigger.nick)

# set initial values
bot.privileges[channel][trigger.nick] = 0

user = bot.users.get(trigger.nick)
if user is None:
user = target.User(trigger.nick, trigger.user, trigger.host)
Expand All @@ -832,8 +798,6 @@ def track_join(bot, trigger):
@plugin.priority('medium')
def track_quit(bot, trigger):
"""Track when users quit channels."""
for chanprivs in bot.privileges.values():
chanprivs.pop(trigger.nick, None)
for channel in bot.channels.values():
channel.clear_user(trigger.nick)
bot.users.pop(trigger.nick, None)
Expand Down Expand Up @@ -1384,9 +1348,6 @@ def _record_who(bot, channel, user, host, nick, account=None, away=None, modes=N
if channel not in bot.channels:
bot.channels[channel] = target.Channel(channel)
bot.channels[channel].add_user(usr, privs=priv)
if channel not in bot.privileges:
bot.privileges[channel] = {}
bot.privileges[channel][nick] = priv


@plugin.event(events.RPL_WHOREPLY)
Expand Down
50 changes: 0 additions & 50 deletions test/test_regression.py

This file was deleted.

0 comments on commit 677cdbf

Please sign in to comment.