Remove durability command and add item and enchantment command
Signed-off-by: trivernis <trivernis@protonmail.com>pull/2/head
parent
56a939a244
commit
6729a61190
@ -0,0 +1,64 @@
|
||||
use serenity::client::Context;
|
||||
use serenity::framework::standard::{macros::command, Args, CommandError, CommandResult};
|
||||
use serenity::model::channel::Message;
|
||||
|
||||
use crate::utils::store::{Store, StoreData};
|
||||
|
||||
#[command]
|
||||
#[description("Provides information for a single enchantment")]
|
||||
#[usage("enchantment <enchantment-name>")]
|
||||
#[example("item unbreaking")]
|
||||
#[min_args(1)]
|
||||
pub(crate) async fn enchantment(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
let data = ctx.data.read().await;
|
||||
let store = data.get::<Store>().expect("Failed to get store");
|
||||
let enchantment_name = args.message().to_lowercase();
|
||||
let enchantments_by_name = store
|
||||
.minecraft_data_api
|
||||
.enchantments
|
||||
.enchantments_by_name()?;
|
||||
let enchantment = enchantments_by_name
|
||||
.get(&enchantment_name)
|
||||
.ok_or(CommandError::from(format!(
|
||||
"Enchantment {} not found",
|
||||
enchantment_name
|
||||
)))?
|
||||
.clone();
|
||||
|
||||
msg.channel_id
|
||||
.send_message(ctx, |m| {
|
||||
m.embed(|mut e| {
|
||||
e = e
|
||||
.title(enchantment.display_name)
|
||||
.field("Name", enchantment.name, false)
|
||||
.field("Category", enchantment.category, false);
|
||||
if !enchantment.exclude.is_empty() {
|
||||
e = e.field("Incompatible With", enchantment.exclude.join(", "), false);
|
||||
}
|
||||
e.field("Max Level", enchantment.max_level, true)
|
||||
.field("Weight", enchantment.weight, true)
|
||||
.field(
|
||||
"Min Cost",
|
||||
format!(
|
||||
"{} * level + {}",
|
||||
enchantment.min_cost.a, enchantment.min_cost.b
|
||||
),
|
||||
false,
|
||||
)
|
||||
.field(
|
||||
"Max Cost",
|
||||
format!(
|
||||
"{} * level + {}",
|
||||
enchantment.max_cost.a, enchantment.max_cost.b
|
||||
),
|
||||
false,
|
||||
)
|
||||
.field("Tradeable", enchantment.tradeable, true)
|
||||
.field("Discoverable", enchantment.discoverable, true)
|
||||
.field("Treasure Only", enchantment.treasure_only, true)
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
use serenity::client::Context;
|
||||
use serenity::framework::standard::{macros::command, Args, CommandError, CommandResult};
|
||||
use serenity::model::channel::Message;
|
||||
|
||||
use crate::utils::store::{Store, StoreData};
|
||||
|
||||
#[command]
|
||||
#[description("Provides information for a single minecraft item")]
|
||||
#[usage("item <item-name>")]
|
||||
#[example("item bread")]
|
||||
#[min_args(1)]
|
||||
pub(crate) async fn item(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
let data = ctx.data.read().await;
|
||||
let store = data.get::<Store>().expect("Failed to get store");
|
||||
|
||||
let item_name = args.message().to_lowercase();
|
||||
let items_by_name = store.minecraft_data_api.items.items_by_name()?;
|
||||
let item = items_by_name
|
||||
.get(&item_name)
|
||||
.ok_or(CommandError::from(format!(
|
||||
"The item `{}` could not be found",
|
||||
item_name
|
||||
)))?;
|
||||
let enchantments_by_category = store
|
||||
.minecraft_data_api
|
||||
.enchantments
|
||||
.enchantments_by_category()?;
|
||||
|
||||
msg.channel_id
|
||||
.send_message(ctx, |m| {
|
||||
m.embed(|mut e| {
|
||||
e = e
|
||||
.title(&*item.display_name)
|
||||
.thumbnail(format!(
|
||||
"https://minecraftitemids.com/item/128/{}.png",
|
||||
item.name
|
||||
))
|
||||
.field("Name", &*item.name, false)
|
||||
.field("Stack Size", item.stack_size, false);
|
||||
if let Some(durability) = item.durability {
|
||||
e = e.field("Durability", durability, true);
|
||||
}
|
||||
if let Some(variations) = &item.variations {
|
||||
e = e.field("Variations", format!("{:?}", variations), false);
|
||||
}
|
||||
if let Some(enchant_categories) = &item.enchant_categories {
|
||||
let item_enchantments = enchant_categories
|
||||
.into_iter()
|
||||
.filter_map(|c| enchantments_by_category.get(c))
|
||||
.flatten()
|
||||
.map(|e| e.display_name.clone())
|
||||
.collect::<Vec<String>>();
|
||||
e = e.field("Enchantments", item_enchantments.join(", "), false);
|
||||
}
|
||||
|
||||
e
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue