update and code refactoring focused on: 1. Adding new documentation pages to the table of contents 2. Restructuring the bot templates documentation 3. Changing keyword syntax from underscore format to space format (e.g., `SET_BOT_MEMORY` → `SET BOT MEMORY`) 4. Updating compiler and keyword registration to support the new space-based syntax 5. Adding new keyword modules (social media, lead scoring, templates, etc.) Refactor BASIC keywords to use spaces instead of underscores Change keyword syntax from underscore format (SET_BOT_MEMORY) to more natural space-separated format (SET BOT MEMORY) throughout the codebase. Key changes: - Update Rhai custom syntax registration to use space tokens - Simplify compiler preprocessing (fewer replacements needed) - Update all template .bas files to use new syntax - Expand documentation with consolidated examples and new sections - Add new keyword modules: social_media, lead_scoring, send_template, core_functions, qrcode, sms, procedures, import_export, llm_macros, on_form_submit
55 lines
1.7 KiB
Rust
55 lines
1.7 KiB
Rust
use crate::shared::models::UserSession;
|
|
use crate::shared::state::AppState;
|
|
use diesel::prelude::*;
|
|
use log::{debug, trace};
|
|
use rhai::{Dynamic, Engine};
|
|
use std::sync::Arc;
|
|
|
|
pub fn delete_post_keyword(state: Arc<AppState>, user: UserSession, engine: &mut Engine) {
|
|
let state_clone = Arc::clone(&state);
|
|
let user_clone = user;
|
|
|
|
engine
|
|
.register_custom_syntax(
|
|
&["DELETE", "POST", "$expr$"],
|
|
false,
|
|
move |context, inputs| {
|
|
let post_id = context.eval_expression_tree(&inputs[0])?.to_string();
|
|
let post_id = post_id.trim_matches('"');
|
|
|
|
trace!("DELETE POST: {}", post_id);
|
|
|
|
let mut conn = state_clone
|
|
.conn
|
|
.get()
|
|
.map_err(|e| format!("DB error: {}", e))?;
|
|
|
|
let result =
|
|
delete_social_post(&mut *conn, user_clone.bot_id, post_id).map_err(|e| {
|
|
Box::new(rhai::EvalAltResult::ErrorRuntime(
|
|
format!("DELETE POST failed: {}", e).into(),
|
|
rhai::Position::NONE,
|
|
))
|
|
})?;
|
|
|
|
Ok(Dynamic::from(result))
|
|
},
|
|
)
|
|
.unwrap();
|
|
|
|
debug!("Registered DELETE POST keyword");
|
|
}
|
|
|
|
fn delete_social_post(
|
|
conn: &mut diesel::PgConnection,
|
|
bot_id: uuid::Uuid,
|
|
post_id: &str,
|
|
) -> Result<bool, String> {
|
|
let result = diesel::sql_query("DELETE FROM social_posts WHERE bot_id = $1 AND id = $2")
|
|
.bind::<diesel::sql_types::Uuid, _>(bot_id)
|
|
.bind::<diesel::sql_types::Text, _>(post_id)
|
|
.execute(conn)
|
|
.map_err(|e| format!("Failed to delete post: {}", e))?;
|
|
|
|
Ok(result > 0)
|
|
}
|