From 077a63e59f9a2bed33dd6e1fe4fbe8d0f8acc17a Mon Sep 17 00:00:00 2001 From: nolik Date: Sun, 2 Apr 2023 23:05:25 +0200 Subject: [PATCH 1/2] ignore-rust-mention - add ignore rust-mention reply for rust-chat. --- src/chat_gpt_handler.rs | 2 +- src/main.rs | 2 +- src/rust_mention_handler.rs | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/chat_gpt_handler.rs b/src/chat_gpt_handler.rs index 12fc155..42f296a 100644 --- a/src/chat_gpt_handler.rs +++ b/src/chat_gpt_handler.rs @@ -35,7 +35,7 @@ lazy_static! { static ref BOT_PROFILES: Vec> = vec![ BotConfiguration { profile: Fedor, - mention_regex: Regex::new(r"(?i)(fedor|ф[её]дор)").expect("Can't compile regex"), + mention_regex: Regex::new(r"(?i)(fedor|ф[её]дор|федя)").expect("Can't compile regex"), gpt_system_context: FEDOR_CHAT_GPT_SYSTEM_CONTEXT, }, BotConfiguration { diff --git a/src/main.rs b/src/main.rs index 7fdd645..26516b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ mod rust_mention_handler; const RUST_REGEX: &str = r"(?i)(rust|раст)"; const BLAZING_FAST_REGEX: &str = r"\w*[BbБб][LlЛл]\w*\W[FfФф][AaАа]\w*\b"; -const CHAT_GPT_REGEX: &str = r"(?i)(fedor|ф[её]дор|felix|феликс|feris|ferris|ферис|феррис)"; +const CHAT_GPT_REGEX: &str = r"(?i)(fedor|ф[её]дор|федя|felix|феликс|feris|ferris|ферис|феррис)"; const MIN_TIME_DIFF: i64 = 15; #[tokio::main] diff --git a/src/rust_mention_handler.rs b/src/rust_mention_handler.rs index 21a77fc..7715af7 100644 --- a/src/rust_mention_handler.rs +++ b/src/rust_mention_handler.rs @@ -7,6 +7,7 @@ use teloxide::types::{InputFile, MessageCommon, MessageId, User}; use crate::mention_repository; +const RUST_CHAT: i64 = -1001228598755; const STICKERS: &[&str; 5] = &[ "CAACAgEAAx0CTdy33AAD3mQO6sc3rzklybqG4MMI4MLXpXJIAAKCAQACaXoxBT0NGBN6KJNELwQ", "CAACAgEAAx0CTdy33AACAQFkF6KoodtDg4KfcPHlUk_7SRFN7QACkQEAAml6MQW86C1JCZcTkS8E", @@ -42,14 +43,15 @@ pub async fn handle_rust_matched_mention( }) = message.kind { // pool the latest mention time from db + let chat_id = message.chat.id; let last_mention_time = - mention_repository::lead_earliest_mention_time(&db_pool, message.chat.id.0).await; + mention_repository::lead_earliest_mention_time(&db_pool, chat_id.0).await; let last_update_time = Utc.from_utc_datetime(&last_mention_time); info!("latest update time: {}", last_update_time); let time_diff = curr_date.signed_duration_since(last_update_time); - if time_diff > req_time_diff { - let message_ids = (message.id, message.chat.id, message.thread_id.unwrap_or(0)); + if chat_id.0 != RUST_CHAT && time_diff > req_time_diff { + let message_ids = (message.id, chat_id, message.thread_id.unwrap_or(0)); send_rust_mention_response(bot, message_ids, time_diff, &username).await; } @@ -59,7 +61,7 @@ pub async fn handle_rust_matched_mention( &username, message .thread_id - .map_or_else(|| message.chat.id.0, |id| id as i64), + .map_or_else(|| chat_id.0, |id| id as i64), ) .await; } From a82486d8c23247affd9ce643f1826f5514b87c26 Mon Sep 17 00:00:00 2001 From: nolik Date: Mon, 3 Apr 2023 00:24:01 +0200 Subject: [PATCH 2/2] main - increase context size. --- src/chat_gpt_repository.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chat_gpt_repository.rs b/src/chat_gpt_repository.rs index 810ff75..1f4f9da 100644 --- a/src/chat_gpt_repository.rs +++ b/src/chat_gpt_repository.rs @@ -9,7 +9,7 @@ pub async fn get_context( redis::cmd("LRANGE") .arg(key) .arg(0) - .arg(10) + .arg(15) .query_async(&mut con) .await }