added ai chat
This commit is contained in:
@@ -123,12 +123,6 @@ pub async fn delete_auto_response(
|
||||
.ok_or_else(|| Error::msg("Guild only command"))?;
|
||||
let db = &ctx.data().db;
|
||||
|
||||
// To delete a key from a map in SurrealDB using merge, we might need to fetch, modify, and update,
|
||||
// or use a specific unset operation if supported via JSON merge patch or similar.
|
||||
// SurrealDB merge with `null` value for a key usually removes it? No, that sets it to null.
|
||||
// We should probably fetch the current map, remove the key, and update.
|
||||
|
||||
// Actually, let's try to fetch, modify locally, and update.
|
||||
let record: Option<GuildRecord> = db.select(("guilds", guild_id.to_string())).await?;
|
||||
|
||||
if let Some(record) = record {
|
||||
@@ -216,6 +210,60 @@ pub async fn edit_auto_response(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[poise::command(slash_command, prefix_command, guild_only)]
|
||||
pub async fn summary(
|
||||
ctx: Context<'_>,
|
||||
#[description = "Message to summarize (reply to one or provide message link)"]
|
||||
message: Option<serenity::Message>,
|
||||
) -> Result<(), Error> {
|
||||
if let poise::Context::Application(app_ctx) = ctx {
|
||||
app_ctx.defer().await?;
|
||||
}
|
||||
|
||||
let msg = if let Some(m) = message {
|
||||
m
|
||||
} else if let poise::Context::Prefix(prefix_ctx) = ctx {
|
||||
// For prefix, check if replying to a message
|
||||
if let Some(reply) = prefix_ctx.msg.referenced_message.as_ref() {
|
||||
(**reply).clone()
|
||||
} else {
|
||||
ctx.say("You must reply to a message or provide a message to summarize.")
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
} else {
|
||||
ctx.say("You must reply to a message or provide a message to summarize.")
|
||||
.await?;
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let ai_chat_manager = ctx.data().ai_chat.clone();
|
||||
let content = msg.content.trim();
|
||||
|
||||
if content.is_empty() {
|
||||
ctx.say("The message is empty, nothing to summarize.").await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let prompt = format!("Summarize this message in 1-2 sentences: {}", content);
|
||||
match ai_chat_manager.query_ollama_direct(&prompt).await {
|
||||
Ok(summary) => {
|
||||
ctx.say(format!(
|
||||
"**Summary of message by {}:**\n{}",
|
||||
msg.author.name, summary
|
||||
))
|
||||
.await?;
|
||||
}
|
||||
Err(err) => {
|
||||
tracing::error!(error = %err, "Failed to summarize message");
|
||||
ctx.say("Failed to generate summary. Try again later.")
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn process_auto_response(
|
||||
ctx: &serenity::Context,
|
||||
msg: &serenity::Message,
|
||||
|
||||
Reference in New Issue
Block a user