-
-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plugin: new require_bot_privilege
decorator
#1982
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems useful. Lgtm besides nitpicks.
Re-requesting reviews because I added a new commit with some tests on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did the editing thing again, with a bit of bonus commenting on actual code.
d876960
to
d501a10
Compare
More generally, I'm not sold on the need for
This started as a tangential thought, but... Ideally we would track +y/+Y separately, so a bot could avoid harassing an oper joining on official business... Maybe we should track the actual user priv modes, and add only a |
As far as Ignoring the specific cases that could be confusing, though: I see @half-duplex's point about enshrining the privilege modes Sopel "supports". My question is then, how could we rework Sopel's channel privilege tracking and requirement enforcement to be more dynamic? If Sopel assigns bitwise values to modes from the server's Example: On Network A with only RFC-defined modes, I'm not saying that it's impossible, but it would require a thoughtful rewrite of all decorators etc. dealing with privileges. That's obviously out of scope for this PR, though it should inform our decision about whether to introduce the And to stop ignoring the potentially confusing cases: I say we explicitly should not have IRC networks' advertised PREFIX modesI (well, my Python console) downloaded all 477 network pages currently linked from netsplit.de's network list and analyzed the PREFIX tokens, where available. Of the 317 network pages that matched my PREFIX regex, here are how many advertised each mode letter: v: 317 o: 317 h: 272 a: 206 q: 205 Y: 47 V: 10 u: 2 Z: 2 y: 2 d: 1 f: 1 Outside of the six buckets Sopel hard-codes (v, h, o, a, q, y/Y), the most common is advertised on only 10 networks out of over 300 surveyed. Maybe we should just keep doing what we're doing. |
I honestly didn't know about OPER privilege level: it was here, in the code, as a constant, so I used it, but that's pretty much the full extent of my knowledge about it. It sound sane to remove Now, Sopel has all these constants for years now, and they assume a system where each level is a different power of 2. It's already the assumption made by the code, both when registering user's privileges in channel and when checking for a user's privilege (with decorators such as I've made, in this PR, 2 decisions:
To support these decisions, I've documented how to protect a callable for the bot's privilege level, but there is no specific documentation about how to deal with the Now I've a question: do we really care about exotic mode/privilege levels? I mean, IRC is quite old, the only 2 privileges that really matters are VOICE and OP, everything else is mostly luck based, and it's not like Sopel offer some kind of enterprise level support. I think this topic suffer a bit from overthinking the problems. |
d501a10
to
73d0aab
Compare
I modified the Is there a final statement about that? Should I just remove the methods around non-OP/VOICED privilege levels? Should I keep them? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By way of answering @Exirel's question about whether to keep the OPER-related stuff around, I've gone through most of this again and annotated a few typos I missed, plus put forward an idea for warnings in the documentation so plugin developers unfamiliar with how fragmented IRC mode support can be are aware.
Thanks for the review, I added the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready for history cleanup at your leisure 🚀
Co-authored-by: dgw <dgw@technobabbl.es>
Co-authored-by: dgw <dgw@technobabbl.es>
Co-authored-by: dgw <dgw@technobabbl.es>
d9465c4
to
d31721c
Compare
Description
This wasn't requested, and probably not needed that much. However, when reading the code for #1981 I realized that we repeat a lot of code, so I figured out I could add these:
bot.has_channel_privilege(channel, level)
will tell you if the bot itself has the right privilege level,plugin.require_bot_privilege
is a new decorator that uses this new method,which is probably useful only for channel administration. Probably.
Anyway, it has tests, and it gave me some ideas for the future (in particular, how we could manage more complex privilege check). So it's good!
Second round description
OK, after second thought, I realized I could improve the
sopel.tools.target.Channel
class, by adding privilege related methods, and use one of these methods into the bot.However, I found out that there is no test for
Channel
(orUser
), and that's not good, so I kind of hijacked this PR to add these tests, while trying to stay on topic.Checklist
make qa
(runsmake quality
andmake test
)