Skip to content

Commit 6de5a08

Browse files
committed
feat: split compact message
1 parent eda71e6 commit 6de5a08

File tree

13 files changed

+131
-63
lines changed

13 files changed

+131
-63
lines changed

.cargo/config.toml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
[build]
2-
rustflags = ["-C", "target-cpu=haswell"]
3-
rustdocflags = ["-C", "target-cpu=native"]
4-
5-
[target.x86_64-unknown-linux-gnu]
6-
7-
[target.wasm32-unknown-unknown]
8-
rustflags = ["-C", "target-feature=+simd128"]
9-
10-
[target.wasm32-wasi]
11-
rustflags = ["-C", "target-feature=+simd128"]
2+
rustflags = ["-C", "target-cpu=native"]
123

134
[net]
145
git-fetch-with-cli = true

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/api/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![allow(clippy::wildcard_imports)]
55
#![allow(clippy::get_first)]
66
#![feature(let_chains)]
7-
#![feature(exclusive_range_pattern)]
87
#![feature(assert_matches)]
98
#![feature(associated_type_defaults)]
109

crates/extra/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(exclusive_range_pattern)]
2-
31
pub mod inverse_bool;
42
pub mod meters;
53
pub mod percent;

crates/minecraft/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![warn(clippy::pedantic)]
2-
#![feature(exclusive_range_pattern)]
32
#![feature(assert_matches)]
43
#![feature(const_precise_live_drops)]
54
#![feature(const_mut_refs)]

crates/statpixel/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "statpixel"
3-
version = "0.40.0"
3+
version = "0.41.0"
44
edition = "2021"
55
license = "GPL-3.0"
66
authors = ["Matthew Polak <contact@matteopolak.com>"]

crates/statpixel/src/commands/at/run.rs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use minecraft::{
1313
text::{parse, Text},
1414
Colour,
1515
};
16-
use poise::serenity_prelude::CreateAttachment;
16+
use poise::serenity_prelude::{CacheHttp, CreateAttachment, CreateMessage};
1717
use skia_safe::textlayout::TextAlign;
1818
use translate::{context, tr, tr_fmt, Error};
1919
use uuid::Uuid;
@@ -119,15 +119,16 @@ pub async fn command<G: api::canvas::prelude::Game>(
119119
at: format!("<t:{}:f>", created_at.timestamp()),
120120
);
121121

122-
let attachments = G::condensed(ctx, family, data_lhs, suffix.as_deref(), background)
123-
.into_iter()
124-
.map(|mut surface| {
125-
CreateAttachment::bytes(
126-
Cow::Owned(canvas::to_png(&mut surface)),
127-
crate::IMAGE_NAME,
128-
)
129-
})
130-
.collect::<Vec<_>>();
122+
let mut attachments =
123+
G::condensed(ctx, family, data_lhs, suffix.as_deref(), background)
124+
.into_iter()
125+
.map(|mut surface| {
126+
CreateAttachment::bytes(
127+
Cow::Owned(canvas::to_png(&mut surface)),
128+
crate::IMAGE_NAME,
129+
)
130+
})
131+
.collect::<Vec<_>>();
131132

132133
let (_, id) = G::Mode::as_at(
133134
ctx,
@@ -136,14 +137,28 @@ pub async fn command<G: api::canvas::prelude::Game>(
136137
None,
137138
);
138139

139-
let mut reply = poise::CreateReply::new().content(format!(
140-
"{}\n{content}",
141-
tr_fmt!(ctx, "identifier", identifier: api::id::encode(&id)),
142-
));
143-
144-
reply.attachments = attachments;
140+
let reply = poise::CreateReply::new()
141+
.content(format!(
142+
"{}\n{content}",
143+
tr_fmt!(ctx, "identifier", identifier: api::id::encode(&id)),
144+
))
145+
.attachment(attachments.remove(0));
145146

146147
ctx.send(reply).await?;
148+
149+
let Some(channel_id) = ctx.channel_id() else {
150+
return Ok(());
151+
};
152+
153+
for attachment in attachments {
154+
channel_id
155+
.send_files(
156+
ctx.discord().http(),
157+
Some(attachment),
158+
CreateMessage::default(),
159+
)
160+
.await?;
161+
}
147162
}
148163
format::Display::Text => {
149164
let (player, data_rhs) = commands::get_player_data(ctx, uuid, username).await?;

crates/statpixel/src/commands/compare/run.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::borrow::Cow;
22

33
use api::canvas::{self, prelude::Mode};
4-
use poise::serenity_prelude::CreateAttachment;
4+
use poise::serenity_prelude::{CacheHttp, CreateAttachment, CreateMessage};
55
use translate::{context, tr_fmt, Error};
66
use uuid::Uuid;
77

@@ -100,7 +100,7 @@ pub async fn command<G: api::canvas::prelude::Game>(
100100
to: data_lhs.username.as_str(),
101101
);
102102

103-
let attachments = G::condensed_diff(
103+
let mut attachments = G::condensed_diff(
104104
ctx,
105105
family,
106106
&data_lhs,
@@ -116,14 +116,28 @@ pub async fn command<G: api::canvas::prelude::Game>(
116116

117117
let (_, id) = G::Mode::as_compare(ctx, player_lhs.uuid, player_rhs.uuid, None);
118118

119-
let mut reply = poise::CreateReply::new().content(format!(
120-
"{}\n{content}",
121-
tr_fmt!(ctx, "identifier", identifier: api::id::encode(&id)),
122-
));
123-
124-
reply.attachments = attachments;
119+
let reply = poise::CreateReply::new()
120+
.content(format!(
121+
"{}\n{content}",
122+
tr_fmt!(ctx, "identifier", identifier: api::id::encode(&id)),
123+
))
124+
.attachment(attachments.remove(0));
125125

126126
ctx.send(reply).await?;
127+
128+
let Some(channel_id) = ctx.channel_id() else {
129+
return Ok(());
130+
};
131+
132+
for attachment in attachments {
133+
channel_id
134+
.send_files(
135+
ctx.discord().http(),
136+
Some(attachment),
137+
CreateMessage::default(),
138+
)
139+
.await?;
140+
}
127141
}
128142
format::Display::Text => {
129143
let (player_rhs, data_rhs) = commands::get_player_data(

crates/statpixel/src/commands/games/run.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::borrow::Cow;
22

33
use api::canvas::{self, prelude::Mode};
4-
use poise::serenity_prelude::CreateAttachment;
4+
use poise::serenity_prelude::{CacheHttp, CreateAttachment, CreateMessage};
55
use translate::{context, tr_fmt};
66
use uuid::Uuid;
77

@@ -22,7 +22,8 @@ pub async fn command<G: api::canvas::prelude::Game>(
2222

2323
player.increase_searches(ctx).await?;
2424

25-
let attachments = G::condensed(ctx, family, &data, suffix.as_deref(), background)
25+
// guaranteed to have >= 1 element
26+
let mut attachments = G::condensed(ctx, family, &data, suffix.as_deref(), background)
2627
.into_iter()
2728
.map(|mut surface| {
2829
CreateAttachment::bytes(
@@ -33,15 +34,29 @@ pub async fn command<G: api::canvas::prelude::Game>(
3334
.collect::<Vec<_>>();
3435

3536
let (_, id) = G::Mode::as_root(ctx, player.uuid, None);
36-
let mut reply = poise::CreateReply::new().content(format!(
37-
"{}\n{}",
38-
tr_fmt!(ctx, "identifier", identifier: api::id::encode(&id)),
39-
crate::tip::random(ctx),
40-
));
41-
42-
reply.attachments = attachments;
37+
let reply = poise::CreateReply::new()
38+
.content(format!(
39+
"{}\n{}",
40+
tr_fmt!(ctx, "identifier", identifier: api::id::encode(&id)),
41+
crate::tip::random(ctx),
42+
))
43+
.attachment(attachments.remove(0));
4344

4445
ctx.send(reply).await?;
46+
47+
let Some(channel_id) = ctx.channel_id() else {
48+
return Ok(());
49+
};
50+
51+
for attachment in attachments {
52+
channel_id
53+
.send_files(
54+
ctx.discord().http(),
55+
Some(attachment),
56+
CreateMessage::default(),
57+
)
58+
.await?;
59+
}
4560
}
4661
format::Display::Image | format::Display::Compact => {
4762
let (player, data, session, skin, suffix) =

crates/statpixel/src/commands/snapshot/run.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use minecraft::{
1313
text::{parse, Text},
1414
Colour,
1515
};
16-
use poise::serenity_prelude::CreateAttachment;
16+
use poise::serenity_prelude::{CacheHttp, CreateAttachment, CreateMessage};
1717
use skia_safe::textlayout::TextAlign;
1818
use translate::{context, tr, tr_fmt, Error};
1919
use uuid::Uuid;
@@ -116,7 +116,7 @@ pub async fn command<G: api::canvas::prelude::Game>(
116116
to: format!("<t:{}:f>", Utc::now().timestamp()),
117117
);
118118

119-
let attachments = G::condensed_diff(
119+
let mut attachments = G::condensed_diff(
120120
ctx,
121121
family,
122122
data_lhs,
@@ -137,14 +137,28 @@ pub async fn command<G: api::canvas::prelude::Game>(
137137
None,
138138
);
139139

140-
let mut reply = poise::CreateReply::new().content(format!(
141-
"{}\n{content}",
142-
tr_fmt!(ctx, "identifier", identifier: api::id::encode(&id)),
143-
));
144-
145-
reply.attachments = attachments;
140+
let reply = poise::CreateReply::new()
141+
.content(format!(
142+
"{}\n{content}",
143+
tr_fmt!(ctx, "identifier", identifier: api::id::encode(&id)),
144+
))
145+
.attachment(attachments.remove(0));
146146

147147
ctx.send(reply).await?;
148+
149+
let Some(channel_id) = ctx.channel_id() else {
150+
return Ok(());
151+
};
152+
153+
for attachment in attachments {
154+
channel_id
155+
.send_files(
156+
ctx.discord().http(),
157+
Some(attachment),
158+
CreateMessage::default(),
159+
)
160+
.await?;
161+
}
148162
}
149163
format::Display::Text => {
150164
let (player, data_rhs) = commands::get_player_data(ctx, uuid, username).await?;

crates/statpixel/src/commands/snapshot/session.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::borrow::Cow;
22

33
use api::canvas;
44
use chrono::Utc;
5-
use poise::serenity_prelude::CreateAttachment;
5+
use poise::serenity_prelude::{CacheHttp, CreateAttachment, CreateMessage};
66
use translate::{context, tr_fmt, Error};
77
use uuid::Uuid;
88

@@ -77,7 +77,7 @@ pub async fn command<G: api::canvas::prelude::Game>(
7777
to: format!("<t:{}:f>", Utc::now().timestamp()),
7878
);
7979

80-
let attachments = G::condensed_diff(
80+
let mut attachments = G::condensed_diff(
8181
ctx,
8282
family,
8383
data_lhs,
@@ -91,11 +91,25 @@ pub async fn command<G: api::canvas::prelude::Game>(
9191
})
9292
.collect::<Vec<_>>();
9393

94-
let mut reply = poise::CreateReply::new().content(content);
95-
96-
reply.attachments = attachments;
94+
let reply = poise::CreateReply::new()
95+
.content(content)
96+
.attachment(attachments.remove(0));
9797

9898
ctx.send(reply).await?;
99+
100+
let Some(channel_id) = ctx.channel_id() else {
101+
return Ok(());
102+
};
103+
104+
for attachment in attachments {
105+
channel_id
106+
.send_files(
107+
ctx.discord().http(),
108+
Some(attachment),
109+
CreateMessage::default(),
110+
)
111+
.await?;
112+
}
99113
}
100114
format::Display::Text => {
101115
let (player, data_rhs) = commands::get_player_data(ctx, Some(uuid_rhs), None).await?;

crates/statpixel/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// and overflows the requirement evaluator
66
#![allow(clippy::get_first)]
77
#![feature(let_chains)]
8-
#![feature(exclusive_range_pattern)]
98
#![feature(iter_intersperse)]
109
#![feature(iter_array_chunks)]
1110

crates/translate/src/context.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,16 @@ impl<'c> Context<'c> {
355355
}
356356
}
357357

358+
pub fn channel_id(&self) -> Option<serenity::ChannelId> {
359+
match &self.interaction {
360+
#[cfg(feature = "error")]
361+
ContextInteraction::Command(ctx) => Some(ctx.channel_id()),
362+
ContextInteraction::Component { interaction, .. } => Some(interaction.channel_id),
363+
ContextInteraction::Modal { interaction, .. } => Some(interaction.channel_id),
364+
ContextInteraction::External(..) | ContextInteraction::Empty => None,
365+
}
366+
}
367+
358368
async fn send_modal(
359369
&self,
360370
ctx: &serenity::Context,

0 commit comments

Comments
 (0)