mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-23 15:01:45 +01:00
Add User::is_telegram
This commit is contained in:
parent
3f2906df62
commit
fbbb5c842b
1 changed files with 20 additions and 0 deletions
|
@ -84,6 +84,26 @@ impl User {
|
|||
|
||||
self.id == ANON_CHANNEL_ID
|
||||
}
|
||||
|
||||
/// Returns `true` if this is special user used by telegram itself.
|
||||
///
|
||||
/// It is sometimes also used as a fallback, for example when a channel post
|
||||
/// is automatically forwarded to a group, bots in a group will get a
|
||||
/// message where `from` is the Telegram user.
|
||||
pub fn is_telegram(&self) -> bool {
|
||||
const TELEGRAM_USER_ID: i64 = 777000;
|
||||
|
||||
// Sanity check
|
||||
debug_assert!(
|
||||
(self.id != TELEGRAM_USER_ID)
|
||||
|| (!self.is_bot
|
||||
&& self.first_name == "Telegram"
|
||||
&& self.last_name.is_none()
|
||||
&& self.username.is_none())
|
||||
);
|
||||
|
||||
self.id == TELEGRAM_USER_ID
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Reference in a new issue