Cursed bad apple change

+ Clippy + fmt
This commit is contained in:
2022-12-14 22:43:39 -07:00
parent 357c1f069a
commit 10b471f25a
3 changed files with 52 additions and 2 deletions
+46 -2
View File
@@ -1,5 +1,5 @@
use crate::error::Error;
use crate::{command, group, GlobalData};
use crate::{command, group, GlobalData, BAD_APPLE};
use rand::prelude::IteratorRandom;
use rand::thread_rng;
use reqwest::Client;
@@ -7,10 +7,12 @@ use serde::{Deserialize, Serialize};
use serenity::client::Context;
use serenity::framework::standard::{Args, CommandResult};
use serenity::model::channel::Message;
use serenity::utils::MessageBuilder;
use std::collections::HashMap;
use std::time::Duration;
#[group]
#[commands(dad_joke, fortune, roll)]
#[commands(dad_joke, fortune, roll, bad_apple)]
pub struct Joke;
#[derive(Clone, Serialize, Deserialize)]
@@ -120,3 +122,45 @@ async fn roll(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
Ok(())
}
#[command]
#[only_in(guilds)]
#[bucket = "bad_apple"]
async fn bad_apple(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
let mut frames = BAD_APPLE.split('|');
let first_frame = frames.next().unwrap();
if first_frame.len() > 2000 {
msg.reply(&ctx.http, format!("Frame too big: {}", first_frame.len()))
.await?;
return Ok(());
}
let mut bad_apple_msg = msg
.reply(
&ctx.http,
MessageBuilder::default()
.push_codeblock_safe(first_frame, None)
.build(),
)
.await?;
for (idx, frame) in frames.enumerate() {
tokio::time::sleep(Duration::from_millis(100)).await;
if (idx % 10) == 0 {
bad_apple_msg
.edit(&ctx.http, |m| {
m.content(
MessageBuilder::default()
.push_codeblock_safe(frame, None)
.build(),
)
})
.await?;
}
}
Ok(())
}