Skip to content

Commit c69c5f3

Browse files
committed
cooking
1 parent d4c4b4e commit c69c5f3

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/event_handler.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ pub async fn handle_event(
3131
return Ok(());
3232
}
3333

34+
// Increment message count for this channel
35+
let count = locked_state.channel_message_counts.entry(msg.channel_id).or_insert(0);
36+
*count += 1;
37+
3438
if let Some(today_i) = locked_state.config.today_i_channel {
3539
if msg.channel_id == Id::new(today_i) && !msg.content.clone().to_lowercase().starts_with("today i") {
3640
http.delete_message(msg.channel_id, msg.id).exec().await?;

src/message_handler.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ pub async fn handle_message(
222222
|| msg.referenced_message.clone().map(|msg| msg.author.id) == Some(Id::<UserMarker>::new(locked_state.config.id))
223223
) =>
224224
{
225+
// Check if we should create memories based on message count
226+
let should_create_memory = locked_state.channel_message_counts
227+
.get(&msg.channel_id)
228+
.map(|count| *count >= 30)
229+
.unwrap_or(false);
225230
let name = msg.author.name.clone();
226231

227232
let mut context = String::new();
@@ -303,13 +308,18 @@ pub async fn handle_message(
303308
Arc::clone(http),
304309
));
305310

306-
// Spawn background task to create memories
307-
tokio::spawn(memory_creator::create_memories_background(
308-
locked_state.db.clone(),
309-
context.clone(),
310-
user_mentions_clone,
311-
locked_state.config.clone(),
312-
));
311+
// Spawn background task to create memories only if we've reached the threshold
312+
if should_create_memory {
313+
tokio::spawn(memory_creator::create_memories_background(
314+
locked_state.db.clone(),
315+
context.clone(),
316+
user_mentions_clone,
317+
locked_state.config.clone(),
318+
));
319+
320+
// Reset the message counter for this channel
321+
locked_state.channel_message_counts.insert(msg.channel_id, 0);
322+
}
313323

314324
Ok(Command::nothing())
315325
}

src/structs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ pub struct State {
126126
pub pending_math_tests: HashMap<u64, PendingMathTest>,
127127
/// Pending color tests
128128
pub pending_color_tests: HashMap<u64, PendingColorTest>,
129+
/// Message count per channel since last memory creation
130+
pub channel_message_counts: HashMap<Id<ChannelMarker>, i32>,
129131
}
130132
// i hate fixing error
131133
unsafe impl Send for State {}
@@ -151,6 +153,7 @@ impl State {
151153
config,
152154
pending_math_tests: HashMap::new(),
153155
pending_color_tests: HashMap::new(),
156+
channel_message_counts: HashMap::new(),
154157
}
155158
}
156159
}

0 commit comments

Comments
 (0)