forked from serenity-rs/poise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
attachment_parameter.rs
35 lines (31 loc) · 1016 Bytes
/
attachment_parameter.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::{Context, Error};
use poise::serenity_prelude as serenity;
/// View the difference between two file sizes
#[poise::command(prefix_command, slash_command)]
pub async fn file_details(
ctx: Context<'_>,
#[description = "File to examine"] file: serenity::Attachment,
#[description = "Second file to examine"] file_2: Option<serenity::Attachment>,
) -> Result<(), Error> {
ctx.say(format!(
"First file name: **{}**. File size difference: **{}** bytes",
file.filename,
file.size - file_2.map_or(0, |f| f.size)
))
.await?;
Ok(())
}
#[poise::command(prefix_command)]
pub async fn totalsize(
ctx: Context<'_>,
#[description = "File to rename"] files: Vec<serenity::Attachment>,
) -> Result<(), Error> {
let total = files.iter().map(|f| f.size as u64).sum::<u64>();
ctx.say(format!(
"Total file size: `{}B`. Average size: `{}B`",
total,
total.checked_div(files.len() as _).unwrap_or(0)
))
.await?;
Ok(())
}