Remove durability command and add item and enchantment command

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/2/head
trivernis 4 years ago
parent 56a939a244
commit 6729a61190
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -3,6 +3,13 @@
<component name="CsvFileAttributes"> <component name="CsvFileAttributes">
<option name="attributeMap"> <option name="attributeMap">
<map> <map>
<entry key="/src/commands/minecraft/mod.rs">
<value>
<Attribute>
<option name="separator" value=":" />
</Attribute>
</value>
</entry>
<entry key="/src/database/scripts/update_tables.sql"> <entry key="/src/database/scripts/update_tables.sql">
<value> <value>
<Attribute> <Attribute>

21
Cargo.lock generated

@ -169,6 +169,12 @@ version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.28" version = "0.8.28"
@ -513,6 +519,15 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135"
[[package]]
name = "itertools"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319"
dependencies = [
"either",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "0.4.7" version = "0.4.7"
@ -598,11 +613,13 @@ dependencies = [
[[package]] [[package]]
name = "minecraft-data-rs" name = "minecraft-data-rs"
version = "0.1.0" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd60c77ef4902ad297b11bc7f8ad8857177d856e763ab92eb717f33c83e0e254" checksum = "6878c011df73cf61f64b8c55022a2b9b713233d234a8083d2e8a01057921856e"
dependencies = [ dependencies = [
"include_dir", "include_dir",
"itertools",
"lazy_static",
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",

@ -16,4 +16,4 @@ serde_derive = "1.0.125"
serde = "1.0.125" serde = "1.0.125"
thiserror = "1.0.24" thiserror = "1.0.24"
parking_lot = "0.11.1" parking_lot = "0.11.1"
minecraft-data-rs = "0.1.0" minecraft-data-rs = "0.2.0"

@ -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(())
}

@ -1,42 +1,11 @@
use serenity::model::channel::Message; mod enchantment;
mod item;
use crate::utils::store::{Store, StoreData}; use enchantment::ENCHANTMENT_COMMAND;
use serenity::client::Context; use item::ITEM_COMMAND;
use serenity::framework::standard::{ use serenity::framework::standard::macros::group;
macros::{command, group},
Args, CommandError, CommandResult,
};
#[group] #[group]
#[commands(durability)] #[commands(item, enchantment)]
#[prefix("mc")]
pub(crate) struct Minecraft; pub(crate) struct Minecraft;
#[command]
pub(crate) async fn durability(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
if args.is_empty() {
return Err(CommandError::from("You need to provide an item name"));
}
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
)))?;
msg.channel_id
.say(
ctx,
format!(
"The durability for `{}` is `{:?}`",
item.display_name, item.durability
),
)
.await?;
Ok(())
}

Loading…
Cancel
Save