mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-10 20:12:25 +01:00
Add User::{tme_url, preferably_tme_url}
functions
This commit is contained in:
parent
705083c2d9
commit
55f753a201
2 changed files with 17 additions and 0 deletions
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Added
|
||||
|
||||
- `UserId::{url, is_anonymous, is_channel, is_telegram}` convenience functions ([#197][pr197])
|
||||
- `User::{tme_url, preferably_tme_url}` convenience functions ([#197][pr197])
|
||||
|
||||
[pr197]: https://github.com/teloxide/teloxide-core/pull/197
|
||||
|
||||
|
|
|
@ -51,6 +51,22 @@ impl User {
|
|||
self.id.url()
|
||||
}
|
||||
|
||||
/// Returns an URL that links to this user in the form of `t.me/<...>`.
|
||||
/// Returns `None` if `self.username.is_none()`.
|
||||
pub fn tme_url(&self) -> Option<reqwest::Url> {
|
||||
Some(
|
||||
format!("https://t.me/{}", self.username.as_ref()?)
|
||||
.parse()
|
||||
.unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns an URL that links to this user in the form of `t.me/<...>` or
|
||||
/// `tg://user/?id=<...>`, preferring `t.me` one when possible.
|
||||
pub fn preferably_tme_url(&self) -> reqwest::Url {
|
||||
self.tme_url().unwrap_or_else(|| self.url())
|
||||
}
|
||||
|
||||
/// Returns `true` if this is the special user used by telegram bot API to
|
||||
/// denote an anonymous user that sends messages on behalf of a group.
|
||||
pub fn is_anonymous(&self) -> bool {
|
||||
|
|
Loading…
Reference in a new issue