From a52b44966627396a39d217e7372ae2f28025a42e Mon Sep 17 00:00:00 2001 From: xy Date: Tue, 27 Aug 2024 18:45:30 +0900 Subject: [PATCH] Use inline to improve performance --- src/discord/error.rs | 11 +++++++++++ src/discord/mod.rs | 17 ++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 src/discord/error.rs diff --git a/src/discord/error.rs b/src/discord/error.rs new file mode 100644 index 0000000..bfcde9e --- /dev/null +++ b/src/discord/error.rs @@ -0,0 +1,11 @@ +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum Error { + #[error(transparent)] + ModelConfigurationBuilder(#[from] chatgpt::config::ModelConfigurationBuilderError), + #[error(transparent)] + ChatGPT(#[from] chatgpt::err::Error), + #[error(transparent)] + Client(#[from] serenity::Error), +} diff --git a/src/discord/mod.rs b/src/discord/mod.rs index f905c00..7277771 100644 --- a/src/discord/mod.rs +++ b/src/discord/mod.rs @@ -1,3 +1,7 @@ +mod error; + +pub use error::Error; + use chatgpt::client::ChatGPT; use chatgpt::config::{ChatGPTEngine, ModelConfigurationBuilder}; use chatgpt::types::ResponseChunk; @@ -10,21 +14,10 @@ use serenity::model::gateway::GatewayIntents; use serenity::Client; use std::sync::Arc; use std::time::Duration; -use thiserror::Error; use tokio::sync::Mutex; use tokio::time::{interval, Interval}; use tracing::{debug, error}; -#[derive(Debug, Error)] -pub enum Error { - #[error(transparent)] - ModelConfigurationBuilder(#[from] chatgpt::config::ModelConfigurationBuilderError), - #[error(transparent)] - ChatGPT(#[from] chatgpt::err::Error), - #[error(transparent)] - Client(#[from] serenity::Error), -} - type Result = std::result::Result; fn init_gpt_client(api_key: &str) -> Result { @@ -114,10 +107,12 @@ impl EventHandler for Handler { } } +#[inline] fn should_process_message(msg: &Message) -> bool { !msg.author.bot && msg.content.starts_with('.') } +#[inline] async fn update_message_interval( http: Arc, processing_message: Message,