Skip to content

How to create a private bot // limiting by chat_id? #442

Answered by JasterV
hendrikmaus asked this question in Q&A
Discussion options

You must be logged in to vote

The easiest thing that you could do is to have the allowed id's stored in a ddbb, or even hardcoded in an array.
For the second option you could just have a file named allowed_ids:

allowed_ids.rs

pub const allowed_ids: [i64; 2] = [1826330247, 2340573957];

You could even read the allowed_ids from an env variable with the ids separated by commas, then on the allowed_ids.rs file I would export a function that reads from that variable and returns a Vec.

Then just assert the sender chat_id against the array:

allowed_ids.contains(&chat_id);

or

allowed_ids.iter().any(|id| id == chat_id)

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@hendrikmaus
Comment options

@hendrikmaus
Comment options

@JasterV
Comment options

Answer selected by hendrikmaus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants