Title regex gaming
This commit is contained in:
parent
bd750c2ca4
commit
1f4f7698dc
|
@ -14,7 +14,7 @@ impl Title {
|
||||||
pub fn new() -> anyhow::Result<Self> {
|
pub fn new() -> anyhow::Result<Self> {
|
||||||
Ok(Title {
|
Ok(Title {
|
||||||
http: Client::new(),
|
http: Client::new(),
|
||||||
title_regex: Regex::new(r"(?<=<title>)(.*)(?=</title>)")?,
|
title_regex: Regex::new(r"<title[^>]*>(.*?)</title>")?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ impl Trigger for Title {
|
||||||
.unwrap_or("text/html");
|
.unwrap_or("text/html");
|
||||||
if mime.contains("text/html") {
|
if mime.contains("text/html") {
|
||||||
let body = response.text().await?;
|
let body = response.text().await?;
|
||||||
if let Some(tm) = self.title_regex.find(&body)? {
|
if let Some(tm) = self.title_regex.captures(&body)?.and_then(|c| c.get(1)) {
|
||||||
let title_match = tm.as_str();
|
let title_match = tm.as_str();
|
||||||
let result = decode_html(title_match).unwrap_or_else(|_| title_match.to_string());
|
let result = decode_html(title_match).unwrap_or_else(|_| title_match.to_string());
|
||||||
Ok(format!("\x039[Title]\x0311 {}", result))
|
Ok(format!("\x039[Title]\x0311 {}", result))
|
||||||
|
|
Loading…
Reference in a new issue