Skip to content

Commit

Permalink
Merge Main
Browse files Browse the repository at this point in the history
  • Loading branch information
Tokarak committed Jul 22, 2024
2 parents 026e2c0 + 881f30b commit a786249
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = ["bot", "protocol", "worker"]
default-members = ["bot"]
members = ["crates/bot", "crates/protocol", "crates/worker"]
default-members = ["crates/bot"]
resolver = "2"

[profile.dev]
Expand Down
8 changes: 2 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ FROM chef AS planner

# Compilation requires only the source code.
COPY Cargo.toml Cargo.lock ./
COPY protocol protocol
COPY worker worker
COPY bot bot
COPY crates crates
RUN cargo chef prepare --recipe-path recipe.json

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

# ============ Run Stage ============
Expand Down
4 changes: 2 additions & 2 deletions bot/Cargo.toml → crates/bot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ version = "0.1.0"
anyhow = "1"
bincode = "1"
flate2 = "1"
poise = { version = "0.6", git = "https://github.com/serenity-rs/poise", default_features = false, features = [
poise = { version = "0.6", git = "https://github.com/serenity-rs/poise", default-features = false, features = [
"cache",
] }
protocol = { path = "../protocol" }
rusqlite = { version = "0.31", features = ["bundled"] }
serde = { version = "1", features = ["derive"] }
serenity = { version = "0.12", default_features = false, features = [
serenity = { version = "0.12", default-features = false, features = [
"rustls_backend",
] }
strip-ansi-escapes = "0.2.0"
Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 22 additions & 1 deletion bot/src/bot.rs → crates/bot/src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,28 @@ async fn tag_autocomplete(ctx: Context<'_>, partial_tag: &str) -> Vec<TagName> {
.unwrap_or_else(|_| Vec::new())
}

fn interpolate<'a>(template: &str, mut params: impl Iterator<Item = &'a str>) -> String {
let mut buf = String::with_capacity(template.len() / 2);
for chunk in template.split("%%") {
let mut chunks = chunk.split("%s");
buf += chunks.next().unwrap();
for chunk in chunks {
buf += params.next().unwrap_or("%s");
buf += chunk;
}
buf += "%";
}
// Remove last `%`.
buf.pop();
buf
}

/// Print the content of a tag by name.
///
/// Syntax: `?tag <tag name>`
/// Syntax: `?tag <tag name> <parameters...>`
///
/// If the tag has placeholders (set with `%s`),
/// then you can fill them with the subsequent arguments.
///
/// Note that tags are local to the guild.
#[poise::command(prefix_command, slash_command, track_edits)]
Expand All @@ -559,6 +578,7 @@ async fn tag(
#[description = "The tag to print"]
#[autocomplete = "tag_autocomplete"]
TagName(tag_name): TagName,
#[description = "Any parameters for the tag"] parameters: Vec<String>,
) -> Result<(), PoiseError> {
let database = &ctx.data().database;
let guild_id = ctx.guild_id().ok_or("no guild id, so no tags")?.get();
Expand All @@ -571,6 +591,7 @@ async fn tag(
.map(|row| row.get::<_, String>("text"))
.transpose()?;
let text = text.unwrap_or_else(|| "That tag is not defined.".into());
let text = interpolate(&text, parameters.iter().map(String::as_str));
ctx.say(text).await?;
Ok(())
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions worker/Cargo.toml → crates/worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ name = "worker"
version = "0.1.0"

[dependencies]
ariadne = { version = "0.4", default_features = false }
ariadne = { version = "0.4", default-features = false }
bincode = "1"
bytemuck = "1"
comemo = "0.4"
image = { version = "0.25", default_features = false, features = ["png"] }
image = { version = "0.25", default-features = false, features = ["png"] }
protocol = { path = "../protocol" }
thiserror = "1"
time = "0.3"
Expand All @@ -17,7 +17,7 @@ typst = "0.11"
typst-render = "0.11"

# downloading packages
zune-inflate = { version = "0.2", default_features = false, features = [
zune-inflate = { version = "0.2", default-features = false, features = [
"gzip",
"std",
] }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit a786249

Please sign in to comment.