-
-
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
config, bot: Configurable message rate #1518
Conversation
@kwaaak This needs to go into It would also be great to include the original commit message (feel free to correct the spelling—there are a few typos in there), and a |
8ec333c
to
64e71c8
Compare
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.
Between the two of us, we got the branch rebased and the commit message updated.
Time for a real look at the code.
@kwaaak If you want, you can address these yourself, in a new commit (don't amend/rebase). You can also wait for @Exirel to weigh in, since I'll ask his opinion too. One of us can also make the name changes if you don't want to. 😸
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.
Looking good so far, the main logic is here. We can nitpick at naming things, but I feel like it's a valuable improvement.
With the work I'm doing on multi-recipients and reaching the 512byte limit of a message, I'm not sure exactly how this is going to affect that. #1525 |
@deathbybandaid Affect that in what way? Or do you just mean that they both step on the same part of the code? (In which case, by convention, this will get merged first because it's older.) |
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'm happy after the renaming of things. Now to see if @Exirel wants more renames or not. 😛
Code-style and naming-thing wise, I'm happy about your changes! LGTM. |
The configfile part of this PR is going to be super helpful for what I'm working on. The actual implementation of how the flood protection works with multiple recipients and my new bytecounting logic is likely to be a bit different than this. Not a conflict, just pointing out that I'm not fully sure how I'm working out my stuff yet, and this add a little extra layer to that. :) |
Plan to build on top of this, @deathbybandaid, and see where it takes you. Remember that I think it's been said before, but adding "official" support for multiple recipients isn't extremely high on the priority list compared to this since it's already possible to do "manually" (with commas). |
I decided to give your branch a test, and have come across an issue:
It looks like you may be overwriting the variable |
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.
using recipient
for the dict overrides the actual recipient that gets sent to self.write
causing:
AttributeError: 'dict' object has no attribute 'replace' (file "/usr/local/lib/python3.6/dist-packages/sopel/irc.py", line 121, in safe)
532a516
to
1eabf4f
Compare
@kwaaak Seeing as we keep getting issues asking how to turn off the flood protection delay, I think it's time this was rebased and squashed a bit so we can merge it. I'll leave sorting out the merge conflict to you. As far as squashing, you can meld the last two or even three commits into the first commit, merging the co-author trailers together. With co-author tags and detailed PR history, we don't have to worry too much about losing attribution in squashes. 😸 |
@kwaaak Alternatively, you can squash just the last commit ("Update bot.py") into the first, and tweak the third commit's message: "Fix variable name" -> "bot: fix variable name in flood prevention logic" That last commit makes a change to the penalty logic that was already made in #1552 between when this PR was opened and now, so it makes sense to include it in the first commit after rebasing. |
b1d8664
to
7dc09fc
Compare
Original change description by @larsks (from sopel-irc#908, slightly edited): This adds several knobs that control how fast the bot sends multiple messages to the same recipient: - bucket_burst_tokens -- this controls how many messages may be sent in "burst mode", i.e., without any inter-message delay. - bucket_refill_rate -- once exhausted, burst tokens are refilled at a rate of bucket_refill_rate tokens/second. - bucket_empty_wait -- how long to wait between sending messages when not in burst mode. This permits the bot to return a few lines of information quickly and not trigger flood protection. How it works: When sending to a new recipient, we initialize a token counter to bucket_burst_tokens. Every time we send a message, we decrement this by 1. If the token counter reaches 0, we engage the rate limiting behavior (which is identical to the existing code, except that the minimum wait of 0.7 seconds is now configurable). When sending a new message to an existing recipient, we check if the token counter is exhausted. If it is, we refill it based on the elapsed time since the last message and the value of bucket_refill_rate, and then proceed as described above. ---- Adapted to current Sopel code and rebased by these users, respectively: Co-authored-by: kwaaak <kwaaak@users.noreply.github.com> Co-authored-by: dgw <dgw@technobabbl.es>
Co-authored-by: deathbybandaid <sam@deathbybandaid.net>
I think this is successfully rescued from the brink of being thrown out and started over. Always make a backup branch when you rebase, people—and don't delete your local repo if it breaks, because you'll want to keep that reflog! (@kwaaak learned a valuable lesson today.) @Exirel do you stand by your approval of this now that the dust has settled post-squash? |
couldn't figure out how to make github let me review these lines:
May need to update these comments with the new configurable logic. Especially since the default for 'flood_empty_wait' = 0.7 |
I have taken the time to test different combinations of configured numbers, and I'm very happy with this. My primary bots sit behind ZNC, and this allows me to essentially disable the flood protection from the bot and rely on ZNCs flood protection, if I want. |
Thank you very much for your field testing. This is not a feature that is easy to test, so this type of feedback is very valuable. It's good to know it works as intended! So I guess 🚢 ? 😄 |
Loop detection was only running if the bot was out of flood lines. It should ALWAYS try to detect message loops. Also removed an outdated comment and added updated ones for the new flood-protection logic.
I was looking over this one last time, partly because of @deathbybandaid's comment, and I was having the damnedest time figuring out how to fix the code comments. Then I realized part of the issue was the loop-detection code being indented too far (so it became part of an Re-requesting review so someone else can double-check me 😁 |
I touched it, so I can't approve my own work.
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.
LGTM
OK, I'm finally ready to ship this. Anything I missed can get fixed up when @Exirel inevitably moves a big chunk of the new logic over into |
Code originally by @larsks in #908
I just made it compatible with the current state.