Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use aformat! #41

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 100 additions & 20 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ reqwest = "0.11.22"
hex = "0.4.3"
to-arraystring = "0.1.3"
arrayvec = "0.7.4"
aformat = "0.1.2"
10 changes: 3 additions & 7 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub(crate) const ACCENT_COLOUR: Colour = Colour(0x8957e5);
pub(crate) const OK_COLOUR: Colour = Colour(0x2ecc71);
pub(crate) const ERROR_COLOUR: Colour = Colour(0xe74c3c);

use arrayvec::ArrayString;
use aformat::aformat;
use to_arraystring::ToArrayString;

use crate::{Context, Error};
Expand Down Expand Up @@ -91,13 +91,9 @@ pub async fn paginate_lists(
) -> Result<(), Error> {
let ctx_id = ctx.id().to_arraystring();

let mut prev_button_id = ArrayString::<24>::new();
prev_button_id.push_str(&ctx_id);
prev_button_id.push_str("prev");

let mut next_button_id = ArrayString::<24>::new();
next_button_id.push_str(&ctx_id);
next_button_id.push_str("next");
let prev_button_id = aformat!("{ctx_id}prev");
let next_button_id = aformat!("{ctx_id}next");

let colour = Colour::TEAL;

Expand Down
14 changes: 3 additions & 11 deletions src/events/issues/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::time::Duration;

use crate::{commands::interaction_err, structures::Embeddable, Data};

use arrayvec::ArrayString;
use aformat::aformat;
use poise::serenity_prelude::{
self as serenity, ButtonStyle, Context, CreateActionRow, CreateButton, CreateEmbed,
CreateInteractionResponse, Message, Permissions,
Expand Down Expand Up @@ -44,16 +44,8 @@ pub async fn message(data: &Data, ctx: &Context, message: &Message) {
// we can avoid even a stack allocation! (thanks gnome)
let ctx_id = message.id.get().to_arraystring();

// we know the max size so we don't need to allocate.
// 20 + 6
let mut remove_id = ArrayString::<26>::new();
remove_id.push_str(&ctx_id);
remove_id.push_str("delete");

// 20 + 9
let mut hide_body_id = ArrayString::<29>::new();
hide_body_id.push_str(&ctx_id);
hide_body_id.push_str("hide_body");
let remove_id = aformat!("{ctx_id}delete");
let hide_body_id = aformat!("{ctx_id}hide_body");

let remove = CreateActionRow::Buttons(vec![CreateButton::new(&*remove_id)
.label("delete")
Expand Down
Loading