use async_trait::async_trait; use reqwest::Method; use serenity::model::interactions::application_command::{ ApplicationCommandInteraction, ApplicationCommandOptionType, }; use geoffrey_models::models::locations::Location; use crate::bot::arg_parse::option_to_string; use crate::bot::commands::{BotCommand, CommandError}; use crate::bot::lang::PLAYER_DOES_NOT_HAVE_MATCHING_SHOP; use geoffrey_models::models::parameters::item_command_params::ItemCommandParams; use geoffrey_models::models::response::api_error::GeoffreyAPIError; use serenity::builder::CreateApplicationCommand; pub struct RestockCommand; #[async_trait] impl BotCommand for RestockCommand { type ApiParams = ItemCommandParams; type ApiResp = Location; fn command_name() -> String { "restock".to_string() } fn request_type() -> Method { Method::POST } fn custom_err_resp(e: &CommandError) -> Option { match e { CommandError::GeoffreyApi(GeoffreyAPIError::EntryNotFound) => { Some(PLAYER_DOES_NOT_HAVE_MATCHING_SHOP.to_string()) } _ => None, } } fn create_app_command(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { command .name(Self::command_name()) .description("Restock an item from a shop") .create_option(|option| { option .name("shop_name") .description("Shop to restock the item at") .kind(ApplicationCommandOptionType::String) .required(true) }) .create_option(|option| { option .name("item_name") .description("Name of the item to restock") .kind(ApplicationCommandOptionType::String) .required(true) }) } async fn process_arguments( command_interaction: ApplicationCommandInteraction, ) -> Result { let options = command_interaction.data.options; Ok(Self::ApiParams::new( option_to_string(options.get(0), "shop_name")?, option_to_string(options.get(1), "item_name")?, )) } fn build_response(resp: Self::ApiResp, args: Self::ApiParams) -> String { format!( "**{}** has been restocked at **{}**", args.item_name, resp.name ) } }