Skip to content

Commit 273982e

Browse files
authored
Widgets (Astavie#2)
1 parent 9402b63 commit 273982e

File tree

13 files changed

+947
-1077
lines changed

13 files changed

+947
-1077
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ authors = [ "Astavie <astavie@pm.me>" ]
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10+
derive_setters = "0.1.5"
1011
serde = { version = "1.0.126", features = ["derive"] }
1112
serde_json = "1.0.96"
1213
tokio = { version = "1.27.0", features = ["full"] }

discord/src/message.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use derive_setters::Setters;
2-
use monostate::MustBe;
2+
use monostate::{MustBe, MustBeU64};
33
use partial_id::Partial;
44
use serde::{Deserialize, Serialize};
55
use serde_repr::{Deserialize_repr, Serialize_repr};
@@ -76,10 +76,29 @@ pub struct Embed {
7676
#[derive(Debug, Serialize, Deserialize)]
7777
pub struct ActionRow {
7878
#[serde(rename = "type")]
79-
pub typ: MustBe!(1u64),
79+
typ: MustBe!(1u64),
8080
pub components: Vec<ActionRowComponent>,
8181
}
8282

83+
impl ActionRow {
84+
pub fn new(components: Vec<ActionRowComponent>) -> Self {
85+
Self {
86+
typ: MustBeU64,
87+
components,
88+
}
89+
}
90+
pub fn is_full(&self) -> bool {
91+
if self.components.len() >= 5 {
92+
return false;
93+
}
94+
return match self.components.first() {
95+
Some(ActionRowComponent::Button(_)) => false,
96+
None => false,
97+
_ => true,
98+
};
99+
}
100+
}
101+
83102
#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr)]
84103
#[repr(u8)]
85104
pub enum ButtonStyle {

discord/src/request.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl Client for Bot {
286286
.header("Content-Type", "application/json")
287287
.body(body.clone())
288288
.unwrap();
289-
// println!("{}", request.body());
289+
println!("{}", request.body());
290290
isahc::send_async(request)
291291
} else {
292292
let request = http.body(()).unwrap();
@@ -344,7 +344,7 @@ impl Client for Bot {
344344
}
345345

346346
let string = response.text().await.unwrap();
347-
// println!("{}", string);
347+
println!("{}", string);
348348

349349
if response.status().is_client_error() {
350350
return Err(RequestError::ClientError(response.status()));

0 commit comments

Comments
 (0)