diff options
Diffstat (limited to '')
| -rw-r--r-- | src/events/mod.rs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/events/mod.rs b/src/events/mod.rs index 22fe976..ae0e1e4 100644 --- a/src/events/mod.rs +++ b/src/events/mod.rs | |||
| @@ -172,6 +172,22 @@ pub async fn handle_voice_state_update( | |||
| 172 | let active_str = format_duration(va.total_active); | 172 | let active_str = format_duration(va.total_active); |
| 173 | let afk_str = format_duration(va.total_afk); | 173 | let afk_str = format_duration(va.total_afk); |
| 174 | 174 | ||
| 175 | // Accumulate to user_stats if in tracked guild | ||
| 176 | if let Some(status_channel_id) = data.config.status_channel_id | ||
| 177 | && let Some(gid) = guild_id { | ||
| 178 | let is_tracked = ctx.cache.guild(gid) | ||
| 179 | .map(|g| g.channels.contains_key(&serenity::ChannelId::new(status_channel_id))) | ||
| 180 | .unwrap_or(false); | ||
| 181 | if is_tracked { | ||
| 182 | database::add_voice_time( | ||
| 183 | &data.db_pool, | ||
| 184 | &user_id_str, | ||
| 185 | va.total_active, | ||
| 186 | va.total_afk, | ||
| 187 | ).await?; | ||
| 188 | } | ||
| 189 | } | ||
| 190 | |||
| 175 | if let Some(lc) = log_channel { | 191 | if let Some(lc) = log_channel { |
| 176 | let msg = format!( | 192 | let msg = format!( |
| 177 | "[{current_time}] {member_name} rozłączył się z {} <t:{current_ts}:R>\n\ | 193 | "[{current_time}] {member_name} rozłączył się z {} <t:{current_ts}:R>\n\ |
| @@ -324,10 +340,24 @@ pub async fn handle_message( | |||
| 324 | data: &Data, | 340 | data: &Data, |
| 325 | new_message: &serenity::Message, | 341 | new_message: &serenity::Message, |
| 326 | ) -> Result<()> { | 342 | ) -> Result<()> { |
| 327 | if new_message.author.id == ctx.cache.current_user().id { | 343 | // Ignore own messages and other bots |
| 344 | if new_message.author.id == ctx.cache.current_user().id || new_message.author.bot { | ||
| 328 | return Ok(()); | 345 | return Ok(()); |
| 329 | } | 346 | } |
| 330 | 347 | ||
| 348 | // Track message count in the tracked guild | ||
| 349 | if let Some(status_channel_id) = data.config.status_channel_id | ||
| 350 | && let Some(guild_id) = new_message.guild_id { | ||
| 351 | // Check if the status channel is in the same guild as the message | ||
| 352 | let is_tracked_guild = ctx.cache.guild(guild_id) | ||
| 353 | .map(|g| g.channels.contains_key(&serenity::ChannelId::new(status_channel_id))) | ||
| 354 | .unwrap_or(false); | ||
| 355 | if is_tracked_guild { | ||
| 356 | database::increment_message_count(&data.db_pool, &new_message.author.id.to_string()) | ||
| 357 | .await?; | ||
| 358 | } | ||
| 359 | } | ||
| 360 | |||
| 331 | let content_lower = new_message.content.to_lowercase(); | 361 | let content_lower = new_message.content.to_lowercase(); |
| 332 | let response_to_send = { | 362 | let response_to_send = { |
| 333 | let triggers = data.triggers.lock().await; | 363 | let triggers = data.triggers.lock().await; |
