Skip to content

Commit

Permalink
fixed finding prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckyBlender committed Oct 16, 2024
1 parent a237b9b commit 8c682a0
Showing 1 changed file with 23 additions and 34 deletions.
57 changes: 23 additions & 34 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,47 +65,36 @@ pub fn remove_command(text: &str) -> String {
}

pub async fn find_prompt(message: &Message) -> Option<String> {
// First, check the text in the current message
let msg_text = message.text();
// Check if the message itself has text
if let Some(msg_text) = message.text() {
let cleaned_text = remove_command(msg_text);
if !cleaned_text.is_empty() {
return Some(cleaned_text);
}
}

let msg_text = if let Some(text) = msg_text {
// If there's text in the message, remove the command and return the prompt
remove_command(text)
} else {
// If no text in the current message, check for a reply message
if let Some(reply) = message.reply_to_message() {
// First, check if the reply message has text
if let Some(text) = reply.text() {
let msg_text = remove_command(text);
if !msg_text.is_empty() {
return Some(msg_text); // Return the cleaned reply message text
}
// Check if the message is a reply to another message
if let Some(reply) = message.reply_to_message() {
// First, check if the reply message has text
if let Some(reply_text) = reply.text() {
let cleaned_text = remove_command(reply_text);
if !cleaned_text.is_empty() {
return Some(cleaned_text);
}
}

// If no text, check for a caption in the reply photo or sticker
if let Some(caption) = reply.caption() {
let msg_text = remove_command(caption);
if !msg_text.is_empty() {
return Some(msg_text); // Return the cleaned caption
}
// If no text, check for a caption in the reply
if let Some(reply_caption) = reply.caption() {
let cleaned_caption = remove_command(reply_caption);
if !cleaned_caption.is_empty() {
return Some(cleaned_caption);
}

// No valid text or caption found
warn!("No text or caption found in the reply message");
return None;
}
// No reply message found either
warn!("No text found in the message & no reply message");
return None;
};

if msg_text.is_empty() {
warn!("No valid text or caption found");
return None;
}

debug!("Message text: {}", msg_text);
Some(msg_text.to_string())
// If no valid text or caption found, log the warning and return None
warn!("No valid text or caption found in the message or reply");
None
}

pub fn parse_webhook(
Expand Down

0 comments on commit 8c682a0

Please sign in to comment.