From 8463f34e0e0065d1c8df945f19b108ac0ac3d074 Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 22 Mar 2019 22:23:04 -0300 Subject: [PATCH] docs/structure.md: add storage and error sections - docs: add docs/extra_fields.md --- docs/extra_fields.md | 23 +++++++++++++++++++++++ docs/structure.md | 26 +++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 docs/extra_fields.md diff --git a/docs/extra_fields.md b/docs/extra_fields.md new file mode 100644 index 0000000..377f2ad --- /dev/null +++ b/docs/extra_fields.md @@ -0,0 +1,23 @@ +# Extra / undocumented fields + +Litecord provides extra fields for some objects due to the implicit requirement +on them by Discord clients. However, they're not documented. + +Objects that aren't documented in the Discord API, such as relationships +aren't documented here. Take a look at the +[discord-unofficial-docs page][d-unofficial-docs] instead. + +[d-unofficial-docs]: https://luna.gitlab.io/discord-unofficial-docs + +## User object + +| field | type | description | +| --: | :-- | :-- | +| premium | boolean | if the user has nitro | +| mobile | boolean? | if the user has a phone number registered | +| phone | string? | the user's phone number, hardcoded to `null` for litecord. | + +## Author user object for messages from webhooks + +It contains an extra `discriminator`, set to `'0000'`. This is Discord +undocumented behavior. diff --git a/docs/structure.md b/docs/structure.md index f5e0fea..78f2bf5 100644 --- a/docs/structure.md +++ b/docs/structure.md @@ -1,4 +1,4 @@ -# Project structure +# Project structure + Project-specific questions ## `attachments` and `images` @@ -40,3 +40,27 @@ Tests are run with `pytest` and the asyncio plugin for proper testing. A point of interest is `tests/conftest.py` as it contains test-specific configuration for the app object. Adding a test is trivial, as pytest will match against any file containing `test_` as a prefix. + +## Litecord-specifics + +### How do I fetch a User/Guild/Channel/DM/Group DM/...? + +You can find the common code to fetch those in `litecord/storage.py` on the +`Storage` class, acessible via `app.storage`. A good example is +`Storage.get_user`. There are no custom classes to hold common things used in +the Discord API. + +They're all dictionaries and follow *at least* the same fields you would expect +on the Discord API. + +### How are API errors handled? + +Quart provides custom handling of errors via `errorhandler()`. You can look +at the declared error handlers on `run.py`. The `500` error handler +converts any 500 into a JSON error object for client ease-of-use. + +All litecord errors inherit from the `LitecordError` class, defining things +on top such as its specific Discord error code and what HTTP status code +to use. + +Error messages are documented [here](https://discordapp.com/developers/docs/topics/opcodes-and-status-codes#http).