mirror of
https://github.com/encounter/zookeeper.git
synced 2026-07-11 06:19:06 -07:00
Add Mechanic cooldown, /find & formatting rework
This commit is contained in:
Generated
+12
@@ -2016,6 +2016,16 @@ version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uwl"
|
||||
version = "0.6.0"
|
||||
@@ -2407,11 +2417,13 @@ dependencies = [
|
||||
"regex",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serenity",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"toml",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"uuid",
|
||||
"vergen",
|
||||
]
|
||||
|
||||
@@ -16,12 +16,14 @@ poise = "0.6"
|
||||
rand = "0.8"
|
||||
regex = "1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
serenity = "0.12"
|
||||
tokio = { version = "1", features = ["rt-multi-thread", "signal"] }
|
||||
tokio-util = { version = "0.7", features = ["rt"] }
|
||||
toml = "0.8"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = "0.3"
|
||||
uuid = { version = "1.8", features = ["fast-rng", "v4"] }
|
||||
|
||||
[dependencies.reqwest]
|
||||
version = "*"
|
||||
@@ -31,3 +33,7 @@ features = ["rustls", "json", "brotli", "gzip", "deflate"]
|
||||
[build-dependencies]
|
||||
anyhow = "1.0"
|
||||
vergen = { version = "8.3", features = ["build", "rustc"] }
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 2
|
||||
debug = false
|
||||
|
||||
+301
-116
File diff suppressed because it is too large
Load Diff
@@ -26,6 +26,11 @@ static CARD_TODO_RE: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(concatcp!(r"Next Card Pull: \*\*", DURATION_PATTERN, r"\*\* \(<t:(\d+)>\)")).unwrap()
|
||||
});
|
||||
|
||||
static MECHANIC_TODO_RE: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(concatcp!(r"Mechanic Finishes: \*\*", DURATION_PATTERN, r"\*\* \(<t:(\d+)>\)"))
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
static PROFILE_RE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(concatcp!(r"change profiles in ", DURATION_PATTERN)).unwrap());
|
||||
|
||||
@@ -149,6 +154,32 @@ pub fn extract_card_cooldown(message: &Message) -> Option<Timestamp> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn extract_mechanic_cooldown(message: &Message) -> Option<Timestamp> {
|
||||
if let Some(embed) = message.embeds.first() {
|
||||
// info command
|
||||
if let Some(description) = &embed.description {
|
||||
if let Some(ts) = MECHANIC_TODO_RE
|
||||
.captures(description)
|
||||
.and_then(|captures| captures[5].parse().ok())
|
||||
.and_then(|secs| Timestamp::from_unix_timestamp(secs).ok())
|
||||
{
|
||||
return Some(ts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Terminal `to-do` command
|
||||
if let Some(ts) = MECHANIC_TODO_RE
|
||||
.captures(&message.content)
|
||||
.and_then(|captures| captures[5].parse().ok())
|
||||
.and_then(|secs| Timestamp::from_unix_timestamp(secs).ok())
|
||||
{
|
||||
return Some(ts);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn extract_profile_cooldown(message: &Message) -> Option<Timestamp> {
|
||||
if let Some(embed) = message.embeds.first() {
|
||||
// profile command
|
||||
@@ -359,4 +390,27 @@ __**Upcoming Events**__
|
||||
Some(Timestamp::from_unix_timestamp(1711437242).unwrap())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_extract_mechanic_cooldown_info() {
|
||||
let mut message = Message::default();
|
||||
message.author.id = ZOO_USER_ID;
|
||||
let mut embed = Embed::default();
|
||||
embed.description = Some(
|
||||
"`$ td`\n\
|
||||
__**Upcoming Events**__\n\
|
||||
> 🎴 Next Card Pull: **2:22:54** (<t:1711560217>)\n\
|
||||
> 🐾 Next Rescue: **4:18:33** (<t:1711567155>)\n\
|
||||
> 🎒 Mechanic Finishes: **8:44:18** (<t:1711583100>)\n\
|
||||
> 💻 Relic Cooldown: **11:58:52** (<t:1711594774>)\n\
|
||||
> 🏕️ Quest Finishes: **4d + 05:51:06** (<t:1711918308>)\n\
|
||||
> 💀 Curse Expires: **13d + 15:10:10** (<t:1712729452>)"
|
||||
.to_string(),
|
||||
);
|
||||
message.embeds.push(embed);
|
||||
assert_eq!(
|
||||
extract_mechanic_cooldown(&message),
|
||||
Some(Timestamp::from_unix_timestamp(1711583100).unwrap())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-2
@@ -1,3 +1,5 @@
|
||||
use anyhow::{Error, Result};
|
||||
|
||||
#[derive(Debug, Clone, serde::Deserialize)]
|
||||
pub struct ZooProfileUser {
|
||||
pub avatar: Option<String>,
|
||||
@@ -288,7 +290,12 @@ pub async fn fetch_zoo_profile(
|
||||
client: &reqwest::Client,
|
||||
user_id: u64,
|
||||
profile: Option<&str>,
|
||||
) -> Result<ZooProfileResponse, reqwest::Error> {
|
||||
) -> Result<ZooProfileResponse> {
|
||||
let api_url = profile_api_url(user_id, profile);
|
||||
client.get(&api_url).send().await?.json().await
|
||||
let response = client.get(&api_url).send().await?;
|
||||
let text = response.text().await?;
|
||||
match serde_json::from_str(&text) {
|
||||
Ok(profile) => Ok(profile),
|
||||
Err(e) => Err(Error::new(e).context(format!("Response body: {}", text))),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user