How to create a private bot // limiting by chat_id
?
#442
-
I was wondering if there is an idiomatic way to limit a bot to one or more |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The easiest thing that you could do is to have the allowed id's stored in a ddbb, or even hardcoded in an array.
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) |
Beta Was this translation helpful? Give feedback.
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
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:
or