pikadick/commands/
zalgo.rs

1use crate::checks::ENABLED_CHECK;
2use serenity::{
3    client::Context,
4    framework::standard::{
5        macros::command,
6        Args,
7        CommandResult,
8    },
9    model::channel::Message,
10};
11use zalgo::ZalgoBuilder;
12
13#[command]
14#[description("Zalgoify a phrase")]
15#[usage("\"<phrase>\"<Max Length>")]
16#[example("\"Hello World!\" 50")]
17#[min_args(1)]
18#[max_args(2)]
19#[checks(Enabled)]
20#[bucket("default")]
21pub async fn zalgo(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
22    let input: String = args.single_quoted()?;
23    let input_max = args.single().unwrap_or(2_000);
24
25    let input_len = input.chars().count();
26    let total = (input_max as f32 - input_len as f32) / input_len as f32;
27    let max = (total / 3.0) as usize;
28
29    if max == 0 {
30        msg.channel_id
31            .say(
32                &ctx.http,
33                "The phrase cannot be zalgoified within the given limits",
34            )
35            .await?;
36        return Ok(());
37    }
38
39    let output = ZalgoBuilder::new()
40        .set_up(max)
41        .set_down(max)
42        .set_mid(max)
43        .zalgoify(&input);
44
45    msg.channel_id.say(&ctx.http, &output).await?;
46
47    Ok(())
48}