Skip to content
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

feat: add protection against missing allowed_updates #422

Merged
merged 4 commits into from
Jun 25, 2023
Merged

Conversation

KnorpelSenf
Copy link
Member

People often forget to specify some updates which they listen for. This PQ fixes that by logging a warning in debug mode in such cases.

Closes #107.

@codecov
Copy link

codecov bot commented May 31, 2023

Codecov Report

Patch coverage: 44.44% and project coverage change: -2.63 ⚠️

Comparison is base (b0fcaa1) 41.35% compared to head (be310f6) 38.72%.

❗ Current head be310f6 differs from pull request most recent head fe8d35e. Consider uploading reports for the commit fe8d35e to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #422      +/-   ##
==========================================
- Coverage   41.35%   38.72%   -2.63%     
==========================================
  Files          16       16              
  Lines        5035     4862     -173     
  Branches      204      194      -10     
==========================================
- Hits         2082     1883     -199     
- Misses       2951     2977      +26     
  Partials        2        2              
Impacted Files Coverage Δ
src/bot.ts 18.27% <42.30%> (+3.69%) ⬆️
src/filter.ts 91.08% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@dcdunkan dcdunkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@KnorpelSenf
Copy link
Member Author

I never ran this code … I'll test it some more before merging

Copy link
Member

@rojvv rojvv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is debug mode mentioned anywhere in the docs?

@KnorpelSenf
Copy link
Member Author

Yes, in the getting started guide.

@rojvv
Copy link
Member

rojvv commented May 31, 2023

I haven’t seen that for years. Is it anchor-able?

@KnorpelSenf
Copy link
Member Author

KnorpelSenf commented May 31, 2023

No, but it is screenshottable:

IMG_20230531_195932_590

@rojvv
Copy link
Member

rojvv commented May 31, 2023

Okay I won’t believe my eyes again

@KnorpelSenf
Copy link
Member Author

Believe Ctrl+F and other hacking skillz

@KnorpelSenf
Copy link
Member Author

Works well actually. Will be much more useful if #424 gets merged.

const debugErr = d("grammy:error");

export const DEFAULT_UPDATE_TYPES = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All update types appear to be available in filter.ts as UPDATE_KEYS already. Should we prefer to do

export const ALL_UPDATE_TYPES = Object.keys(UPDATE_KEYS);
export const DEFAULT_UPDATE_TYPES = ALL_UPDATE_TYPES.filter(u => u !== 'chat_member');

To keep a single source of truth for update types in grammY's source?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this, but they're semantically unrelated because the supported filter queries need not be the same as the Bot API specs. That's why I didn't follow DRY.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it completely semantically unrelated, or perhaps just that it is a superset of Bot API specs? I'd presume you always want to support update types from Bot API specs, but want room to also conjure L1s of your own.

If so, we can probably do TG_UPDATE_KEYS and CUSTOM_UPDATE_KEYS (if and when it is needed); where filter.ts exports the former, and filters on the set union of the above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it completely semantically unrelated

Yes. I don't want to mix those two things. One is a mirror of the specs, and the other is the base for filter query validation. We don't know if we want to have filter queries for all fields in updates, or if we will have excessive queries that are not found in updates (shortcuts that aren't computed perhaps).

@KnorpelSenf KnorpelSenf merged commit 6bde720 into main Jun 25, 2023
@KnorpelSenf KnorpelSenf deleted the check-allowed branch June 25, 2023 22:26
KnorpelSenf added a commit to ssistoza/grammY that referenced this pull request Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

feat: Log warning if starting the bot without specifying all update types that are expected based on bot.on()
5 participants