mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-23 06:51:01 +01:00
replace return type in url() function to Url from String
This commit is contained in:
parent
7488f96d02
commit
d490ed9bc0
5 changed files with 9 additions and 9 deletions
|
@ -796,7 +796,7 @@ mod getters {
|
|||
}
|
||||
|
||||
impl Message {
|
||||
pub fn url(&self) -> Option<String> {
|
||||
pub fn url(&self) -> Option<reqwest::Url> {
|
||||
match &self.chat.kind {
|
||||
ChatKind::NonPrivate {
|
||||
kind:
|
||||
|
@ -812,7 +812,7 @@ impl Message {
|
|||
..
|
||||
},
|
||||
..
|
||||
} => Some(format!("https://t.me/{0}/{1}/", username, self.id)),
|
||||
} => Some(reqwest::Url::parse(format!("https://t.me/{0}/{1}/", username, self.id).as_str()).unwrap()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ impl User {
|
|||
Some(format!("@{}", self.username.as_ref()?))
|
||||
}
|
||||
|
||||
pub fn url(&self) -> String {
|
||||
format!("tg://user?id={}", self.id)
|
||||
pub fn url(&self) -> reqwest::Url {
|
||||
reqwest::Url::parse(format!("tg://user/?id={}", self.id).as_str()).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ pub fn escape(s: &str) -> String {
|
|||
pub fn user_mention_or_link(user: &User) -> String {
|
||||
match user.mention() {
|
||||
Some(mention) => mention,
|
||||
None => link(&user.url(), &user.full_name()),
|
||||
None => link(user.url().as_str(), &user.full_name()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ mod tests {
|
|||
};
|
||||
assert_eq!(
|
||||
user_mention_or_link(&user_without_username),
|
||||
r#"<a href="tg://user?id=123456789">Name</a>"#
|
||||
r#"<a href="tg://user/?id=123456789">Name</a>"#
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ pub fn escape_code(s: &str) -> String {
|
|||
pub fn user_mention_or_link(user: &User) -> String {
|
||||
match user.mention() {
|
||||
Some(mention) => mention,
|
||||
None => link(&user.url(), &user.full_name()),
|
||||
None => link(user.url().as_str(), &user.full_name()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,7 @@ mod tests {
|
|||
};
|
||||
assert_eq!(
|
||||
user_mention_or_link(&user_without_username),
|
||||
r#"[Name](tg://user?id=123456789)"#
|
||||
r#"[Name](tg://user/?id=123456789)"#
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ where
|
|||
/// use teloxide::utils::parse_command;
|
||||
/// let text = "/ban 5 hours";
|
||||
/// let (command, args) = parse_command(text).unwrap();
|
||||
/// assert_eq!(command, "ban");
|
||||
/// assert_eq!(command, "/ban");
|
||||
/// assert_eq!(args, vec!["5", "hours"]);
|
||||
/// ```
|
||||
pub fn parse_command(text: &str) -> Option<(&str, Vec<&str>)> {
|
||||
|
|
Loading…
Reference in a new issue