Skip to content

Commit 8cb5ac3

Browse files
committed
feat(playmatch): rate-limit every playmatch request via a global wrapper client
1 parent 36ccdf2 commit 8cb5ac3

15 files changed

Lines changed: 555 additions & 178 deletions

Cargo.lock

Lines changed: 115 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ poise = { git = "https://github.com/serenity-rs/poise", branch = "serenity-next"
2929

3030
# playmatch
3131
playmatch_client = { path = "playmatch_client" }
32+
governor = "^0.10"
3233

3334
# commands
3435
unicode-width = "^0.2"

src/abstraction/command.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub type CheckResult = Result<bool, CommandError>;
1717

1818
pub struct CommandData {
1919
pub client: reqwest::Client,
20-
pub playmatch_client: Arc<playmatch_client::Client>,
20+
pub playmatch_client: Arc<crate::abstraction::playmatch_client::PlaymatchClient>,
2121
}
2222

2323
impl Default for CommandData {
@@ -44,12 +44,16 @@ impl Default for CommandData {
4444
.build()
4545
.unwrap();
4646

47+
let inner = playmatch_client::Client::new_with_client(
48+
&env::var("PLAYMATCH_API_URL")
49+
.unwrap_or("https://playmatch.retrorealm.dev".to_string()),
50+
client.clone(),
51+
);
52+
4753
Self {
48-
client: client.clone(),
49-
playmatch_client: Arc::new(playmatch_client::Client::new_with_client(
50-
&env::var("PLAYMATCH_API_URL")
51-
.unwrap_or("https://playmatch.retrorealm.dev".to_string()),
52-
client,
54+
client,
55+
playmatch_client: Arc::new(crate::abstraction::playmatch_client::PlaymatchClient::new(
56+
inner,
5357
)),
5458
}
5559
}

src/abstraction/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ pub mod activity_data;
22
pub mod command;
33
pub mod components_v2;
44
pub mod playmatch;
5+
pub mod playmatch_client;
56
pub mod providers;

0 commit comments

Comments
 (0)