Skip to content

Commit ca07ecf

Browse files
committed
ZBR v1.4.1
1 parent da3b0de commit ca07ecf

11 files changed

Lines changed: 90 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
All notable changes to the ZBR project are documented here and in the [changelog](https://zbr-website.vercel.app/docs/changelog) website.
44

5+
## v1.4.1 - Parser fix and Zupdate interaction
6+
7+
This release addresses a critical parser bug and introduces a new interaction feature for better message management in Discord.
8+
9+
### Core
10+
- **Fixed Parser Data Loss** — Resolved a bug in `parse_arg` where arguments containing multiple function calls (e.g., inside `Zif`) were being truncated.
11+
12+
### New Functions
13+
- `Zupdate{}` — Signals that an interaction (button/select menu) should update the original message instead of sending a new reply.
14+
515
---
616

717
## v1.4.0 - Centralized error handling across all functions

docs/categories.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ Zunmute - moderation
434434
ZunpinMessage - message
435435
ZuntimeOut - moderation
436436
Zuppercase - string
437+
Zupdate - components
437438
Zuptime - bot
438439
Zurl - string
439440
ZuseChannel - message

docs/functions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7636,6 +7636,14 @@
76367636
],
76377637
"example": "Zuppercase{Hello World}"
76387638
},
7639+
{
7640+
"name": "Zupdate",
7641+
"description": "Signals that the interaction response should update the original message instead of sending a new reply. Only valid inside interaction handlers (buttons, select menus).",
7642+
"syntax": "Zupdate{}",
7643+
"variadic": false,
7644+
"arguments": [],
7645+
"example": "Zupdate{}"
7646+
},
76397647
{
76407648
"name": "Zuptime",
76417649
"description": "Returns the bot's uptime since startup, formatted as a human-readable string of days, hours, minutes, and seconds.",

docs/functions_tag.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@
435435
"ZunpinMessage",
436436
"ZuntimeOut",
437437
"Zuppercase",
438+
"Zupdate",
438439
"Zuptime",
439440
"Zurl",
440441
"ZuseChannel",

src/bot.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,21 +1125,35 @@ impl EventHandler for Bot {
11251125
return;
11261126
}
11271127

1128-
let mut msg = CreateInteractionResponseMessage::new();
1129-
if let Some(text) = text_content {
1130-
msg = msg.content(text);
1131-
}
1132-
for e in built_embeds {
1133-
msg = msg.add_embed(e);
1134-
}
1135-
if data.ephemeral {
1136-
msg = msg.ephemeral(true);
1137-
}
1138-
for row in build_components(&data.components) {
1139-
msg = msg.components(vec![row]);
1140-
}
1128+
let response = if data.components.update_message {
1129+
let mut msg = CreateInteractionResponseMessage::new();
1130+
if let Some(text) = text_content {
1131+
msg = msg.content(text);
1132+
}
1133+
for e in built_embeds {
1134+
msg = msg.add_embed(e);
1135+
}
1136+
for row in build_components(&data.components) {
1137+
msg = msg.components(vec![row]);
1138+
}
1139+
CreateInteractionResponse::UpdateMessage(msg)
1140+
} else {
1141+
let mut msg = CreateInteractionResponseMessage::new();
1142+
if let Some(text) = text_content {
1143+
msg = msg.content(text);
1144+
}
1145+
for e in built_embeds {
1146+
msg = msg.add_embed(e);
1147+
}
1148+
if data.ephemeral {
1149+
msg = msg.ephemeral(true);
1150+
}
1151+
for row in build_components(&data.components) {
1152+
msg = msg.components(vec![row]);
1153+
}
1154+
CreateInteractionResponse::Message(msg)
1155+
};
11411156

1142-
let response = CreateInteractionResponse::Message(msg);
11431157
if let Err(e) = component.create_response(&ctx.http, response).await {
11441158
eprintln!("Failed to respond to component interaction: {}", e);
11451159
}

src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ pub struct ComponentState {
6565
pub modal: Option<ModalData>,
6666
/// Whether Zdefer{} was called.
6767
pub deferred: bool,
68+
/// Whether Zupdate{} was called (to edit the original message in an interaction).
69+
pub update_message: bool,
6870
}
6971

7072
#[derive(Clone, Default, Debug)]

src/executor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pub struct ComponentData {
7676
pub select_menu: Option<SelectMenuData>,
7777
pub modal: Option<ModalData>,
7878
pub deferred: bool,
79+
pub update_message: bool,
7980
}
8081

8182
pub struct RunResponse {
@@ -206,6 +207,7 @@ fn build_response(result: crate::context::EvalResult, rt: &mut runtime::Runtime)
206207
select_menu: None,
207208
modal: None,
208209
deferred: false,
210+
update_message: false,
209211
},
210212
};
211213
}
@@ -285,6 +287,7 @@ fn build_response(result: crate::context::EvalResult, rt: &mut runtime::Runtime)
285287
.collect(),
286288
}),
287289
deferred: result.components.deferred,
290+
update_message: result.components.update_message,
288291
};
289292

290293
RunResponse {

src/functions/components/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub mod removeAllComponents;
1515
pub mod removeButtons;
1616
pub mod removeComponent;
1717
pub mod defer;
18+
pub mod update;
1819
pub mod inputValue;
1920
pub mod customID;
2021
pub mod getUserSelectUserID;

src/functions/components/update.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use crate::context::{DiscordContext, FnOutput};
2+
3+
/// Zupdate{} — signals that this interaction response should update the original message.
4+
pub fn run(_args: Vec<String>, ctx: &DiscordContext) -> FnOutput {
5+
tokio::task::block_in_place(|| {
6+
tokio::runtime::Handle::current().block_on(async {
7+
ctx.components.lock().await.update_message = true;
8+
})
9+
});
10+
FnOutput::Empty
11+
}

src/functions/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,6 +2964,14 @@ pub fn register(registry: &mut HashMap<String, FnMeta>) {
29642964
max_args: 0,
29652965
},
29662966
);
2967+
registry.insert(
2968+
"update".to_string(),
2969+
FnMeta {
2970+
func: components::update::run,
2971+
min_args: 0,
2972+
max_args: 0,
2973+
},
2974+
);
29672975
registry.insert(
29682976
"inputValue".to_string(),
29692977
FnMeta {

0 commit comments

Comments
 (0)