Skip to content

Commit

Permalink
Use aformat!
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbt365 committed Jun 15, 2024
1 parent e218a01 commit f8a7819
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 38 deletions.
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

0 comments on commit f8a7819

Please sign in to comment.