From b0eff0ad7c26b74c79bb6fb8f393aaaa271fc5e4 Mon Sep 17 00:00:00 2001 From: Teo Date: Tue, 27 Dec 2022 21:17:35 +0100 Subject: [PATCH] forgot to actually use message.content lol --- src/handle_events.rs | 11 +++++++++-- src/handler.rs | 11 +++++++---- src/main.rs | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/handle_events.rs b/src/handle_events.rs index 08358f1..cac161c 100644 --- a/src/handle_events.rs +++ b/src/handle_events.rs @@ -4,12 +4,12 @@ use serenity::{ Interaction, }, gateway::Ready, - guild::Guild, + guild::Guild, prelude::Message, }, async_trait, prelude::* }; -use log::info; +use log::{info, trace}; use crate::handler_util::{response, is_writable}; use crate::handler::Handler; @@ -46,4 +46,11 @@ impl EventHandler for Handler { async fn guild_create(&self, ctx: Context, guild: Guild, _is_new: bool) { self.register_guild(ctx.http, guild).await; } + + async fn message(&self, _ctx: Context, message: Message) { + if let Some(guild_id) = message.guild_id { + trace!(target: "Wordy", "Read a new message from {}", message.author.name); + self.message(guild_id, message.channel_id, message.author.id, message.content); + } + } } diff --git a/src/handler.rs b/src/handler.rs index 3c5670b..db4b93f 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -1,5 +1,5 @@ use itertools::Itertools; -use log::{warn, info}; +use log::{warn, info, trace}; use image::{write_buffer_with_format, ColorType, ImageOutputFormat}; use std::{io::{Cursor, Seek, SeekFrom}, sync::Arc}; use palette::rgb::Rgb; @@ -17,6 +17,7 @@ use serenity::{ }; use wordcloud_rs::{Token, WordCloud, Colors}; use crate::idiom::Idioms; +const READ_PAST: u64 = 10000; fn convert_color(color: Color) -> Rgb { Rgb::new( @@ -38,7 +39,7 @@ impl Handler { } pub fn message(&self, guild_id: GuildId, channel_id: ChannelId, member_id: UserId, message: String) { - self.idioms.get_mut(&guild_id).unwrap().update(channel_id, member_id, message) + self.idioms.get_mut(&guild_id).unwrap().update(channel_id, member_id, message); } fn to_wc_tokens(&self, tokens: Vec<(String, f32)>) -> Vec<(Token, f32)> { @@ -52,6 +53,7 @@ impl Handler { if let Some(guild_id) = command.guild_id { let member_id = member.user.id; let tokens = self.idioms.get(&guild_id).unwrap().idiom(member_id); + trace!(target: "Wordy", "/cloud: retrieved {} tokens for {}", tokens.len(), member.user.name); let wc_tokens = self.to_wc_tokens(tokens); let image = WordCloud::new() .colors(Colors::DoubleSplitCompl(convert_color(color))).generate(wc_tokens); @@ -109,13 +111,14 @@ impl Handler { tokio::spawn(async move { for (channel_id, channel) in channels { if let Ok(messages) = channel.messages( - &http, |retriever| retriever.limit(1000) + &http, |retriever| retriever.limit(READ_PAST) ).await { for message in messages { idioms.get_mut(&guild.id).unwrap().update( - channel_id, message.author.id, String::new() + channel_id, message.author.id, message.content ); } + info!(target: "Wordy", "Read {} past messages in {}/{}", READ_PAST, guild.name, channel.name()) } } }); diff --git a/src/main.rs b/src/main.rs index 5b93d56..7a3df39 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ fn get_token(name: &str) -> Option { #[tokio::main] async fn main() { - env_logger::builder().filter_module("Wordy", LevelFilter::Info).init(); + env_logger::builder().filter_module("Wordy", LevelFilter::Trace).init(); // Configure the client with your Discord bot token in the environment. let token = get_token("WORDY_TOKEN").unwrap(); let http = Http::new(&token);