2547techno/feature/json format arg (initial commands)#90
2547techno/feature/json format arg (initial commands)#902547techno wants to merge 11 commits intoSupinic:masterfrom
Conversation
Supinic
left a comment
There was a problem hiding this comment.
Two major things to consider:
- If we would go with the parameters route, then every single command would end up having a
formatparameter, which is not ideal. Also, this would conflict with commands that already have a parameter with the same name. Therefore, a different solution needs to be found. - The reply object should just contain all the raw data along with the reply, ideally wrapped in some sort of property (
rawcould work, maybe some other name as well). Then, the command module insupi-corewould be in charge of relaying this data further
How would one indicate which format to return as then? Maybe if a command is able to return a parsed output and is piped into $js, it will choose to use the parsed reply rather than the text reply as the piped value. For example: { "Uptime": "8m, 36s", "Temperature": "N/A", "Free memory": "1 GB/2 GB", "CPU usage": "No stats available", "Commands used": 3, "Redis": "7 keys", "Banphrase API": "Not connected", "Latency to TMI": "56ms" }and then
Is this something that is possible? |
|
The returned object now has the original Maybe an option is to have a new ie. |
|
|
… in pipe operation
|
Solution added: Added Example:No parsed value available: Parsed value available: |
|
Just need feedback on if this is a direction we can go |
Supinic
left a comment
There was a problem hiding this comment.
I like the direction - where each command that supports this kind of functionality has another property returned along with the string response (currently named .reply) in the result object.
I don't think running JSON.stringify is necessary at all in the command context. The command module can manage this just fine. The Command.checkAndExecute could be adjusted so it returns this as part of the result object. Then, the meta commands (I'm mostly thinking of $js, maybe $abb if users request it) can be updated so they can publish this data to the user.
If a command does not support this, it would just be handled via some sort of command flag, so that the meta command doesn't need to run the command and then figure it can't work with the pure data result.
See comment above above about the changes to the pipe command for the reason for using |
Supinic
left a comment
There was a problem hiding this comment.
Discussed on stream with @2547techno
TL;DR - keep object-based data, sb.Command lets it pass anyway; find a good name for the object property, and maybe design preliminary support for meta-commands
For a start, the JSON output format param has been added to the 3 commands $ping, $slots, and $randommeme.
The reason for only 3 is because the other popular commands need either API keys set up or new tables in the DB which are not documented (ie. the init-database does not setup tables for randomline)
The general format for JSON formatted output is:
{ "raw": "raw output that would be returned without format:json", "parsed": { "foo": "bar" } }Until I'm able to set up all the proper tables and API tokens locally, I won't be able to test the JSON format param for most of the other popular commands. Maybe a revision of the init-database script is needed.
Any feedback is welcome :)
Examples
$slots
$slots format:json a b c{ "raw": "[ a c b ] ", "parsed": { "rolledItems": ["a","c","b"], "win":false } }$slots format:json a a a{ "raw": "[ a a a ] FeelsDankMan You won and beat the odds of 100%.", "parsed": { "rolledItems": ["a","a","a"], "chance": 100 "win": true } }$slots format:json a a a a a a a a a a a a ab(cannot test locally because it requires an undocumented table to store winners){ "raw": "[ a a a ] PagChomp A flush! Congratulations, you beat the odds of 78.653% (that is 1 in 1.271)", "parsed": { "rolledItems": ["a","a","a"], "chance": 78.653 "win": true } }$ping
$ping format:json{ "raw": "Pong! Uptime: 8m, 36s; Temperature: N/A; Free memory: 1 GB/2 GB; CPU usage: No stats available; Commands used: 3; Redis: 7 keys; Banphrase API: Not connected; Latency to TMI: 56ms", "parsed": { "Uptime": "8m, 36s", "Temperature": "N/A", "Free memory": "1 GB/2 GB", "CPU usage": "No stats available", "Commands used": 3, "Redis": "7 keys", "Banphrase API": "Not connected", "Latency to TMI": "56ms" } }$randommeme
$randommeme format:json twitch{ "raw": " r/Twitch: Why are my classic twitch emotes monkeys? https://www.reddit.com/gallery/xazmcm (Score: 1, posted 7h, 57m ago) ", "parsed": { "quarantine": false, "fourmName": "Twitch", "post": { "author": "TheOnlyCanadianEver", "created": "2022-09-10T20:47:17.000Z", "id": "xazmcm", "title": "Why are my classic twitch emotes monkeys?", "url": "https://www.reddit.com/gallery/xazmcm", "commentsUrl": "r/Twitch/comments/xazmcm", "flairs": [ "Question" ], "crosspostOrigin": null, "isTextPost": false, "nsfw": false, "stickied": false, "score": 1 } } }