Skip to content

Commit

Permalink
rename interval method for tasks to run_in, store msg content to avoid
Browse files Browse the repository at this point in the history
repeated calls
  • Loading branch information
ivinjabraham committed Oct 17, 2024
1 parent 5172db0 commit c9fd045
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn run_scheduler(ctx: SerenityContext) {

async fn schedule_task(ctx: SerenityContext, task: Box<dyn Task>) {
loop {
let next_run_in = task.interval();
let next_run_in = task.run_in();
tokio::time::sleep(next_run_in).await;

task.run(ctx.clone()).await;
Expand Down
9 changes: 5 additions & 4 deletions src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const STATUS_UPDATE_CHANNEL_ID: u64 = 764575524127244318;
#[async_trait]
pub trait Task: Send + Sync {
fn name(&self) -> &'static str;
fn interval(&self) -> Duration;
fn run_in(&self) -> Duration;
async fn run(&self, ctx: Context);
}

Expand All @@ -48,7 +48,7 @@ impl Task for StatusUpdateCheck {
"StatusUpdateCheck"
}

fn interval(&self) -> Duration {
fn run_in(&self) -> Duration {
time_until(5, 0)
}

Expand All @@ -75,10 +75,11 @@ impl Task for StatusUpdateCheck {
let filtered_messages: Vec<Message> = messages
.into_iter()
.filter(|msg| {
let msg_content = msg.content.to_lowercase();
msg.timestamp >= yesterday_five_am.into()
&& msg.timestamp < today_five_am.into()
&& msg.content.to_lowercase().contains("namah shivaya")
&& msg.content.to_lowercase().contains("regards")
&& msg_content.contains("namah shivaya")
&& msg_content.contains("regards")
})
.collect();

Expand Down

0 comments on commit c9fd045

Please sign in to comment.