Made checking nft value easier
This commit is contained in:
parent
93975f463c
commit
747aa81d62
@ -65,7 +65,7 @@ pub async fn create_motivation_image(motivation: Motivation) -> Result<Vec<u8>,
|
||||
text_wand.set_font_size(0.07 * (wand.get_image_width() as f64));
|
||||
text_wand.set_text_alignment(magick_rust::bindings::AlignType_CenterAlign);
|
||||
wand.annotate_image(&text_wand, text_pos_x, text_pos_y, 0.0, &text)?;
|
||||
Ok(wand.write_image_blob("png")?)
|
||||
Ok(wand.write_image_blob("jpg")?)
|
||||
}
|
||||
|
||||
#[command]
|
||||
@ -97,7 +97,7 @@ async fn motivation(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
.content("Today's motivation")
|
||||
.add_file(CreateAttachment::bytes(
|
||||
Cow::from(image),
|
||||
"motivate.png".to_string(),
|
||||
"motivate.jpg".to_string(),
|
||||
)),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use crate::discord::get_role;
|
||||
use crate::discord::motivate::create_motivation_image;
|
||||
use crate::error::Error;
|
||||
use crate::inventory::{InventoryError, ItemData, ItemType, Operation};
|
||||
use crate::inventory::{nft_value, InventoryError, ItemData, ItemType, Operation};
|
||||
use crate::models::motivation::MotivationConfig;
|
||||
use crate::models::task::{Task, TaskType};
|
||||
use crate::user::{User, UserError};
|
||||
@ -251,7 +251,7 @@ async fn use_item(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
}
|
||||
ItemType::Nft => {
|
||||
if let Some(ItemData::Nft(path)) = item_data {
|
||||
let file: tokio::fs::File = match tokio::fs::File::open(path).await {
|
||||
let file: tokio::fs::File = match tokio::fs::File::open(&path).await {
|
||||
Ok(f) => f,
|
||||
Err(_) => {
|
||||
msg.reply(&ctx.http, "Sorry this was a pump and dump")
|
||||
@ -259,13 +259,18 @@ async fn use_item(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
let value = nft_value(&path);
|
||||
msg.channel_id
|
||||
.send_message(
|
||||
&ctx.http,
|
||||
CreateMessage::new()
|
||||
.content("Your NFT my good friend:")
|
||||
.content(format!(
|
||||
"Your NFT my good friend. It's worth **{} FC**!",
|
||||
value
|
||||
))
|
||||
.add_file(
|
||||
CreateAttachment::file(&file, "nft.png".to_string())
|
||||
CreateAttachment::file(&file, "nft.jpg".to_string())
|
||||
.await
|
||||
.unwrap(),
|
||||
),
|
||||
@ -477,7 +482,7 @@ pub async fn restock_shop(ctx: &Context, global_data: &GlobalData) -> Result<(),
|
||||
hasher.write(&nft);
|
||||
let nft_hash = hasher.finish();
|
||||
|
||||
let path = global_data.cfg.nft_path.join(format!("{}.png", nft_hash));
|
||||
let path = global_data.cfg.nft_path.join(format!("{}.jpg", nft_hash));
|
||||
|
||||
if path.exists() {
|
||||
continue;
|
||||
|
||||
@ -108,6 +108,17 @@ impl Display for ItemType {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn nft_value(s: &String) -> i64 {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
s.hash(&mut hasher);
|
||||
|
||||
let hash = hasher.finish();
|
||||
|
||||
let per_value = (hash as f64) / (u64::MAX as f64);
|
||||
|
||||
((2000.0 * per_value) as i64) - 500
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct InventorySlot {
|
||||
pub quantity: i64,
|
||||
@ -132,14 +143,7 @@ impl InventorySlot {
|
||||
match self.item_type {
|
||||
ItemType::Nft => {
|
||||
if let Some(ItemData::Nft(s)) = &self.item_data {
|
||||
let mut hasher = DefaultHasher::new();
|
||||
s.hash(&mut hasher);
|
||||
|
||||
let hash = hasher.finish();
|
||||
|
||||
let per_value = (hash as f64) / (u64::MAX as f64);
|
||||
|
||||
((2000.0 * per_value) as i64) - 500
|
||||
nft_value(s)
|
||||
} else {
|
||||
0
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user