Update and improve util.py CLI script#14364
Open
talflon wants to merge 14 commits intoCharcoal-SE:masterfrom
Open
Update and improve util.py CLI script#14364talflon wants to merge 14 commits intoCharcoal-SE:masterfrom
talflon wants to merge 14 commits intoCharcoal-SE:masterfrom
Conversation
added 10 commits
June 9, 2025 17:16
- if it can be single line, run it as single line - detect multi-line input with starting quotes, and handle similar to before - no longer exit on a blank interactive input line
- still allows command line arguments, but now allows them to be treated individually or as a single line with -S - force interactive mode with -i after running other commands - specfify command more explicitly with -c - load commands from a file/pipe with -C - load arguments to the specified command from a file/pipe with -A
- allows null-terminating input files for files without any null bytes, that means treating the file as a single argument or command
2f2efa5 to
5d52b94
Compare
added 4 commits
June 9, 2025 17:38
- loads a post from SE API and then tests it
- loads a post from a Metasmoke URL and re-runs current detection on it - add Post._parse_ms_api_post, Post(ms_api_response=) - add Metasmoke.get_post_from_ms()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. What does your pull request change or introduce to the project?
It updates the
util.pyCLI so that it:bisect-i)-S)-A,-C), single line or multiline (-0)To accomplish this, the following changes were made outside of
util.py:normalize_number()anddeobfuscate_number()inchatcommands: instead of assumingmsgis notNone, these methods now treatmsg=Nonesimilar to howbisect()andbisect_number()already do, by falling back to the passed-inpatternargumentPostinitializable withms_api_response, adding corresponding method_parse_ms_api_post()Metasmoke.get_post_from_ms()which loads a Metasmoke post given its id or URL, and turns it into aPostThe following new commands call into the same internal code as their namesake chat commands:
bisect-numberdeobfuscate-numbernormalize-numbertest-question/test-qtest-answer/test-atest-user/test-utest-title/test-ttesttest-json/test-jThe following new commands load posts and test them:
scan: takes an SE URLtest-ms: takes an MS URLThe following new commands create temporary copies of the relevant blacklists, then manually add or remove items from these temporary copies, so that subsequent calls to
bisect-*ortest-*commands will test these modifications. They don't run the full logic of their namesake chat commands:blacklist-keywordblacklist-websiteblacklist-usernameblacklist-numberunblacklist2. What is the justification for the inclusion of your Pull Request (or, what problem does it solve?)
It lets someone test the blacklists and most of the other spam rules outside of public chat, by cloning the SmokeDetector repository and installing the dependencies. If they want to test a lot of different things, it avoids spamming a chatroom. Furthermore, they could use this to test new regexes using the actual SmokeDetector code, before creating a commit on the public repository, or use this to test new spam detection code without starting up a full SmokeDetector instance.
util.pyused to be able to do this forbisect, but that was broken due to the removal ofinspect.getargspec()in Python 3.11. I fixed that, and extended the functionality of this script.3. Write meaningful commit messages ...
I was pretty brief in my commit messages. In the later ones I tried to explain a little more.
4. Include comments in your code ...
I did some of that, where I didn't think it was self-explanatory.
5. Use meaningful variable names ...
I've tried to do that.
6. What testing have you done?
I have only tested it by running
util.pymyself and playing around with it.util.pywasn't working for me before I started, so I'm hoping I can't have broken it too badly.I believe the only way it could introduce errors in other parts of SmokeDetector is if there was code relying on
deobfuscate_number()ornormalize_number()raising an error onmsg=None. I don't see any error handling code related to that, so I'm hoping there's no requirement for that to raise.