Skip to content

Commit

Permalink
use floodgate (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
circuitsacul authored Dec 4, 2022
1 parent d2b3a0d commit 52e27ce
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 131 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ humantime = "2.1.0"
reqwest = "0.11.12"
thiserror = "1.0.37"
sentry = "0.29.0"
floodgate = "0.4.0"
20 changes: 12 additions & 8 deletions src/client/cooldowns.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
use std::sync::Arc;

use floodgate::FixedMapping;
use twilight_model::id::{marker::ChannelMarker, Id};

use crate::{constants, utils::cooldowns::FixedMapping};
use crate::constants;

pub struct Cooldowns {
// restricts per-channel
pub autostar_send: FixedMapping<Id<ChannelMarker>>,
pub autostar_send: Arc<FixedMapping<Id<ChannelMarker>>>,
}

impl Cooldowns {
pub fn new() -> Self {
Self {
autostar_send: FixedMapping::new(
constants::AUTOSTAR_COOLDOWN.0,
constants::AUTOSTAR_COOLDOWN.1,
),
}
let autostar_send = Arc::new(FixedMapping::new(
constants::AUTOSTAR_COOLDOWN.0,
constants::AUTOSTAR_COOLDOWN.1,
));
FixedMapping::start(autostar_send.clone(), None);

Self { autostar_send }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub const MAX_MESSAGES: u32 = 10_000;
pub const MAX_NAMES: u32 = 100;

// Cooldowns
pub const AUTOSTAR_COOLDOWN: (u32, Duration) = (5, Duration::from_secs(20));
pub const AUTOSTAR_COOLDOWN: (u64, Duration) = (5, Duration::from_secs(20));

// Common Validation
pub const MAX_NAME_LENGTH: u32 = 32;
Expand Down
5 changes: 2 additions & 3 deletions src/core/autostar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ pub async fn handle(bot: &StarboardBot, event: &MessageCreate) -> StarboardResul
if bot
.cooldowns
.autostar_send
.trigger(event.channel_id)
.await
.is_none()
.trigger(&event.channel_id)
.is_some()
{
return Ok(());
}
Expand Down
118 changes: 0 additions & 118 deletions src/utils/cooldowns.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod async_dash;
pub mod cooldowns;
pub mod dashset_lock;
pub mod dm;
pub mod embed;
Expand Down

0 comments on commit 52e27ce

Please sign in to comment.