Skip to content

Commit

Permalink
Use inline to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
kasugamirai committed Aug 27, 2024
1 parent 843bccf commit a52b449
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/discord/error.rs
Original file line number Diff line number Diff line change
@@ -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),
}
17 changes: 6 additions & 11 deletions src/discord/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
mod error;

pub use error::Error;

use chatgpt::client::ChatGPT;
use chatgpt::config::{ChatGPTEngine, ModelConfigurationBuilder};
use chatgpt::types::ResponseChunk;
Expand All @@ -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<T> = std::result::Result<T, Error>;

fn init_gpt_client(api_key: &str) -> Result<ChatGPT> {
Expand Down Expand Up @@ -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<serenity::http::Http>,
processing_message: Message,
Expand Down

0 comments on commit a52b449

Please sign in to comment.