Cursed bad apple change
+ Clippy + fmt
This commit is contained in:
parent
357c1f069a
commit
10b471f25a
@ -56,6 +56,7 @@ pub struct BotState {
|
||||
pub accepted_nsfw: Option<UserId>,
|
||||
pub fortune_templates: Tera,
|
||||
pub albums: HashMap<String, Vec<Image>>,
|
||||
pub bad_apple_running: bool,
|
||||
}
|
||||
|
||||
impl BotState {
|
||||
@ -80,6 +81,7 @@ impl BotState {
|
||||
accepted_nsfw: None,
|
||||
fortune_templates,
|
||||
albums,
|
||||
bad_apple_running: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -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(())
|
||||
}
|
||||
|
||||
@ -10,6 +10,8 @@ use serenity::framework::standard::StandardFramework;
|
||||
use serenity::prelude::*;
|
||||
use structopt::StructOpt;
|
||||
|
||||
const BAD_APPLE: &str = include_str!("assets/bad_apple.txt");
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let args: Args = Args::from_args();
|
||||
@ -38,6 +40,8 @@ async fn main() {
|
||||
.group(&discord::joke::JOKE_GROUP)
|
||||
.group(&discord::admin::ADMIN_GROUP)
|
||||
.unrecognised_command(unrecognised_command_hook)
|
||||
.bucket("bad_apple", |b| b.delay(60*10))
|
||||
.await
|
||||
.help(&discord::MY_HELP)
|
||||
.after(discord::after);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user