sopel-irc / sopel

:robot::speech_balloon: An easy-to-use and highly extensible IRC Bot framework. Formerly Willie.
https://sopel.chat
Other
948 stars 403 forks source link

[Proposal] Better ignore system #1355

Open dgw opened 6 years ago

dgw commented 6 years ago

I noticed this weekend that .blocks add hostmask <regex> actually adds a host block, and doesn't work as expected if given an actual hostmask, e.g. *!*@bad-domain.tld. Ignoring the fact that I gave an invalid regular expression (starts with a quantifier), .*!.*@bad-domain\.tld won't work as expected either.

What .blocks add hostmask actually does is add to the host_blocks, which does exactly what it says on the tin: It blocks based on the line originator's host. It's a bit confusing, due to the command naming.

The simple solution would be to rename the .blocks ___ hostmask commands to .blocks ___ host, but I'd like to do more than that:

The first three items definitely can be done in Sopel 6.x 7.x, as the only users who can actually use the ignore-system commands are bot owners/admins who read the changelogs before upgrading. (You do read changelogs before upgrading, riiight? :stuck_out_tongue:). Validation would be a nice non-breaking enhancement, too.

I'm less inclined to change how config file entries are interpreted in a point update, so making regex syntax optional might be a Sopel 7 8 thing. But if there's a clean way to just quietly tweak existing configs on first start and make all existing ignore entries into the regex variety (however that's represented in the file), it doesn't have to wait. The biggest barrier to that is that Sopel's config file isn't versioned—but determining the config format version is easy if it doesn't contain a version! :grin:

Self-assigned this because I already started thinking about the implementation, but no code has been committed Yet™. Therefore, it's also Patches Welcome until I actually prototype (some of) the changes.

alanhuang122 commented 6 years ago

I rewrote the blocks module in alanhuang122/sopel@0d0b73a to take IRC hostmasks only. (ignore the change on line 303; it's hardcoded specific minor behavior). Perhaps that could be useful as a reference?

dgw commented 6 years ago

Could be a good start, yeah. Thanks for the pointer!

I'm just shaking my head a bit that you didn't even have to change the docstring for core.hostmask_blocks in that commit, because core.host_blocks already says "hostmasks". :roll_eyes: Lies!

dgw commented 5 years ago

Pushing off to Sopel 7. Version 6.6.0 has gotten too bloated, and this can wait until the next major release.

dgw commented 4 years ago

Just a few weeks left before target release date for 7.0 and this isn't even started. It can wait.

half-duplex commented 4 years ago

Is there a reason not to turn both host_blocks and nick_blocks into hostmask_blocks? E.g. adding a "nick" block could turn into a hostmask "{nick}!.@." block, unless we're worried about regex matching overhead. My only other thought is that some things (clients, services packages) have default ban types, where /ban baduser would automatically ban them with a configurable specificity, like baduser*!*@*.res.blah. That may be useful enough to implement, or confusion between bot block syntax and irc block syntax may be enough to make it worth implementing (at least if we can support eg. naked *).

dgw commented 4 years ago

From an internals perspective, I think yes: matching "host_blocks" on host and "nick_blocks" on nick gives us less overhead, because we're already parsing those components out of the incoming line to populate the trigger object. It's done for free, and it reduces the amount of text each block type needs to process.

That said, one could also say that having three different lists to process gives us higher overhead anyway, just of a different type.

The idea of having default ban types that wildcard out part of the hostmask when given a nickname is great, but I think not for .blocks. It sounds like a good fit for adminchannel, in the .ban/.kickban commands. (There's already a ton of "guess how to normalize this" regex logic in that plugin's configureHostMask() function.)

deathbybandaid commented 4 years ago

Some more thoughts regarding the ignore/blocks system, from things I do with my own bot.

dgw commented 4 years ago

Blocking by command is sort of possible for channels via config. It's clunky though. I'm hoping most of that could be implemented by a plugin once we get hooks (#1546) in, though, rather than forcing core to handle it all.

Exirel commented 4 years ago

So, just a quick note: we can use the fnmatch built-in module for that. In particular, we can use the translate function to take a file-like pattern (using * and ? wildcard), to get a regex, then use that regex to match on full nick/hostname.

dgw commented 3 years ago

I was going back through really old issues I opened and came across dgw/sopel-BombBot#12 and dgw/sopel-BombBot#13. These still remain unimplemented after almost 5 years mostly because there's no way I, as a plugin developer, want to deal with using Sopel's various block lists to check whether a potential target's attempts to win the game would be ignored.

Seems like a possible new API feature, loosely related to this overhaul of the ignore system. Whether it's part of the ignore system, I don't know/care. It could be a new field on tools.target.User objects, or a new method somewhere that takes a nickname (Identifier) or User and checks.

Any immediate "PLS NO" thoughts from the crew on this issue before I write up that proposal for 8.0?

Exirel commented 3 years ago

Something like bot.is_ignored(Identifier) -> bool? It would make sense, yes.

dgw commented 3 years ago

Added bot.is_ignored(Identifier) idea and @cottongin's semi-request for @plugin.unblockable functions to see if they should have been blocked (via IRC) to the OP task list.