|
1 | | -use rand::{prelude::{IteratorRandom, SliceRandom}, seq::IndexedRandom, Rng}; |
| 1 | +use rand::{ |
| 2 | + prelude::{IteratorRandom, SliceRandom}, |
| 3 | + seq::IndexedRandom, |
| 4 | + Rng, |
| 5 | +}; |
2 | 6 | use serde_rusqlite::from_row; |
3 | 7 | use std::{sync::Arc, time::Instant}; |
4 | 8 | use tokio::sync::{mpsc, MutexGuard}; |
5 | 9 | use twilight_http::Client as HttpClient; |
6 | | -use twilight_model::{gateway::payload::incoming::MessageCreate, id::{marker::{ChannelMarker, MessageMarker}, Id}}; |
| 10 | +use twilight_model::{ |
| 11 | + gateway::payload::incoming::MessageCreate, |
| 12 | + id::{ |
| 13 | + marker::{ChannelMarker, MessageMarker}, |
| 14 | + Id, |
| 15 | + }, |
| 16 | +}; |
7 | 17 | use vesper::twilight_exports::UserMarker; |
8 | 18 |
|
9 | 19 | use crate::{ |
10 | | - ai_message, database::User, memory_creator, quiz_handler, structs::{Command, List, State}, |
11 | | - utils::levels::xp_required_for_level, zalgos::zalgify_text, RESPONDERS, |
| 20 | + ai_message, |
| 21 | + database::User, |
| 22 | + memory_creator, quiz_handler, |
| 23 | + structs::{Command, List, State}, |
| 24 | + utils::levels::xp_required_for_level, |
| 25 | + zalgos::zalgify_text, |
| 26 | + RESPONDERS, |
12 | 27 | }; |
13 | 28 |
|
14 | 29 | /// Handle streaming AI response with periodic updates |
@@ -59,21 +74,19 @@ pub async fn handle_streaming_response( |
59 | 74 | // Send initial message once we have enough words |
60 | 75 | if message_id.is_none() && content.split_whitespace().count() >= MIN_WORDS { |
61 | 76 | match http.create_message(channel_id).content(&content) { |
62 | | - Ok(req) => { |
63 | | - match req.reply(reply_to).exec().await { |
64 | | - Ok(response) => { |
65 | | - if let Ok(msg) = response.model().await { |
66 | | - message_id = Some(msg.id); |
67 | | - last_sent_content = content.clone(); |
68 | | - last_update = Instant::now(); |
69 | | - } |
70 | | - } |
71 | | - Err(e) => { |
72 | | - log::error!("Failed to send initial message: {:?}", e); |
73 | | - return; |
| 77 | + Ok(req) => match req.reply(reply_to).exec().await { |
| 78 | + Ok(response) => { |
| 79 | + if let Ok(msg) = response.model().await { |
| 80 | + message_id = Some(msg.id); |
| 81 | + last_sent_content = content.clone(); |
| 82 | + last_update = Instant::now(); |
74 | 83 | } |
75 | 84 | } |
76 | | - } |
| 85 | + Err(e) => { |
| 86 | + log::error!("Failed to send initial message: {:?}", e); |
| 87 | + return; |
| 88 | + } |
| 89 | + }, |
77 | 90 | Err(e) => { |
78 | 91 | log::error!("Failed to create message: {:?}", e); |
79 | 92 | return; |
@@ -227,7 +240,8 @@ pub async fn handle_message( |
227 | 240 | ) => |
228 | 241 | { |
229 | 242 | // Check if we should create memories based on message count |
230 | | - let should_create_memory = locked_state.channel_message_counts |
| 243 | + let should_create_memory = locked_state |
| 244 | + .channel_message_counts |
231 | 245 | .get(&msg.channel_id.get()) |
232 | 246 | .map(|count| *count >= 30) |
233 | 247 | .unwrap_or(false); |
@@ -374,9 +388,15 @@ pub async fn handle_message( |
374 | 388 | .children |
375 | 389 | .into_iter() |
376 | 390 | .filter(|x| !x.data.over_18) |
377 | | - .filter(|x| x.data.url_overridden_by_dest.contains("i.")) |
| 391 | + .filter(|x| { |
| 392 | + x.data |
| 393 | + .url_overridden_by_dest |
| 394 | + .as_ref() |
| 395 | + .map(|url| url.contains("i.")) |
| 396 | + .unwrap_or(false) |
| 397 | + }) |
378 | 398 | .choose(&mut locked_state.rng) |
379 | | - .map(|x| x.data.url_overridden_by_dest); |
| 399 | + .and_then(|x| x.data.url_overridden_by_dest); |
380 | 400 | if let Some(pic) = res { |
381 | 401 | Ok(Command::text(pic)) |
382 | 402 | } else { |
|
0 commit comments