From 2ff6754bd1c53a801929152624c8d9acf108aa60 Mon Sep 17 00:00:00 2001 From: seth Date: Tue, 11 Apr 2023 22:17:00 -0400 Subject: fix sending very long copypastas --- src/commands/copypasta.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/commands') diff --git a/src/commands/copypasta.rs b/src/commands/copypasta.rs index 9424665..0e1a8e6 100644 --- a/src/commands/copypasta.rs +++ b/src/commands/copypasta.rs @@ -1,13 +1,11 @@ use crate::utils; use serenity::builder::CreateApplicationCommand; use serenity::http::client::Http; -use serenity::model::channel::Message; use serenity::model::id::ChannelId; use serenity::model::prelude::command::CommandOptionType; use serenity::model::prelude::interaction::application_command::{ CommandDataOption, CommandDataOptionValue, }; -use serenity::prelude::SerenityError; use std::sync::Arc; pub async fn run(options: &[CommandDataOption], channel_id: ChannelId, http: &Arc) -> String { @@ -20,26 +18,25 @@ pub async fn run(options: &[CommandDataOption], channel_id: ChannelId, http: &Ar .expect(err_msg); if let CommandDataOptionValue::String(copypasta) = option { - let replies = &utils::get_copypasta(copypasta).await; - let len = replies.len() - 1; + let replies = utils::get_copypasta(copypasta).await; - // send messages separately if we have > 1 - for (i, reply) in replies.iter().enumerate() { - let resp: Result; - - if i < len { - resp = channel_id.send_message(&http, |m| m.content(reply)).await; + if replies.len() > 1 { + for reply in replies { + let resp = channel_id.send_message(&http, |m| m.content(reply)).await; match resp { Ok(_) => continue, Err(why) => { println!("couldn't send message: {:?}", why); + "something went wrong!"; } } } + return "here's your copypasta:".to_string(); // yes this causes the + // application to not respond. + // no i don't care. } - - return replies[len].to_string(); + return replies[0].to_string(); } "couldn't find a copypasta".to_string() @@ -55,7 +52,7 @@ pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicatio .description("the copypasta you want to send") .kind(CommandOptionType::String) .required(true) - // .add_string_choice("ismah", "ismah") // renable this later + .add_string_choice("ismah", "ismah") // renable this later .add_string_choice("happymeal", "happymeal") .add_string_choice("sus", "sus") .add_string_choice("ticktock", "ticktock") -- cgit v1.2.3