Skip to content

Commit a786249

Browse files
committed
Merge Main
2 parents 026e2c0 + 881f30b commit a786249

File tree

17 files changed

+33
-16
lines changed

17 files changed

+33
-16
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
2-
members = ["bot", "protocol", "worker"]
3-
default-members = ["bot"]
2+
members = ["crates/bot", "crates/protocol", "crates/worker"]
3+
default-members = ["crates/bot"]
44
resolver = "2"
55

66
[profile.dev]

Dockerfile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ FROM chef AS planner
66

77
# Compilation requires only the source code.
88
COPY Cargo.toml Cargo.lock ./
9-
COPY protocol protocol
10-
COPY worker worker
11-
COPY bot bot
9+
COPY crates crates
1210
RUN cargo chef prepare --recipe-path recipe.json
1311

1412
FROM chef AS builder
@@ -18,9 +16,7 @@ COPY --from=planner /typst-bot/recipe.json recipe.json
1816
RUN cargo chef cook --release --workspace --recipe-path recipe.json
1917
# Compilation requires only the source code.
2018
COPY Cargo.toml Cargo.lock ./
21-
COPY protocol protocol
22-
COPY worker worker
23-
COPY bot bot
19+
COPY crates crates
2420
RUN cargo build --release --workspace --config git-fetch-with-cli=true
2521

2622
# ============ Run Stage ============

bot/Cargo.toml renamed to crates/bot/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ version = "0.1.0"
77
anyhow = "1"
88
bincode = "1"
99
flate2 = "1"
10-
poise = { version = "0.6", git = "https://github.com/serenity-rs/poise", default_features = false, features = [
10+
poise = { version = "0.6", git = "https://github.com/serenity-rs/poise", default-features = false, features = [
1111
"cache",
1212
] }
1313
protocol = { path = "../protocol" }
1414
rusqlite = { version = "0.31", features = ["bundled"] }
1515
serde = { version = "1", features = ["derive"] }
16-
serenity = { version = "0.12", default_features = false, features = [
16+
serenity = { version = "0.12", default-features = false, features = [
1717
"rustls_backend",
1818
] }
1919
strip-ansi-escapes = "0.2.0"
File renamed without changes.
File renamed without changes.

bot/src/bot.rs renamed to crates/bot/src/bot.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,28 @@ async fn tag_autocomplete(ctx: Context<'_>, partial_tag: &str) -> Vec<TagName> {
547547
.unwrap_or_else(|_| Vec::new())
548548
}
549549

550+
fn interpolate<'a>(template: &str, mut params: impl Iterator<Item = &'a str>) -> String {
551+
let mut buf = String::with_capacity(template.len() / 2);
552+
for chunk in template.split("%%") {
553+
let mut chunks = chunk.split("%s");
554+
buf += chunks.next().unwrap();
555+
for chunk in chunks {
556+
buf += params.next().unwrap_or("%s");
557+
buf += chunk;
558+
}
559+
buf += "%";
560+
}
561+
// Remove last `%`.
562+
buf.pop();
563+
buf
564+
}
565+
550566
/// Print the content of a tag by name.
551567
///
552-
/// Syntax: `?tag <tag name>`
568+
/// Syntax: `?tag <tag name> <parameters...>`
569+
///
570+
/// If the tag has placeholders (set with `%s`),
571+
/// then you can fill them with the subsequent arguments.
553572
///
554573
/// Note that tags are local to the guild.
555574
#[poise::command(prefix_command, slash_command, track_edits)]
@@ -559,6 +578,7 @@ async fn tag(
559578
#[description = "The tag to print"]
560579
#[autocomplete = "tag_autocomplete"]
561580
TagName(tag_name): TagName,
581+
#[description = "Any parameters for the tag"] parameters: Vec<String>,
562582
) -> Result<(), PoiseError> {
563583
let database = &ctx.data().database;
564584
let guild_id = ctx.guild_id().ok_or("no guild id, so no tags")?.get();
@@ -571,6 +591,7 @@ async fn tag(
571591
.map(|row| row.get::<_, String>("text"))
572592
.transpose()?;
573593
let text = text.unwrap_or_else(|| "That tag is not defined.".into());
594+
let text = interpolate(&text, parameters.iter().map(String::as_str));
574595
ctx.say(text).await?;
575596
Ok(())
576597
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

worker/Cargo.toml renamed to crates/worker/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ name = "worker"
44
version = "0.1.0"
55

66
[dependencies]
7-
ariadne = { version = "0.4", default_features = false }
7+
ariadne = { version = "0.4", default-features = false }
88
bincode = "1"
99
bytemuck = "1"
1010
comemo = "0.4"
11-
image = { version = "0.25", default_features = false, features = ["png"] }
11+
image = { version = "0.25", default-features = false, features = ["png"] }
1212
protocol = { path = "../protocol" }
1313
thiserror = "1"
1414
time = "0.3"
@@ -17,7 +17,7 @@ typst = "0.11"
1717
typst-render = "0.11"
1818

1919
# downloading packages
20-
zune-inflate = { version = "0.2", default_features = false, features = [
20+
zune-inflate = { version = "0.2", default-features = false, features = [
2121
"gzip",
2222
"std",
2323
] }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)