Last active
February 12, 2023 10:00
-
-
Save Enigo/e74bd23fc9a7e226a25f01333220c8e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BOT_TOKEN: &str = <>; // insert value | |
const CHAT_ID: i64 = <>; // insert value | |
pub async fn send(metadata: Metadata, buy: Buy) { | |
let message = build_message(&metadata, buy); | |
let bot = Bot::new(BOT_TOKEN); | |
info!("Sending message to telegram"); | |
match bot.send_message(ChatId(CHAT_ID), message).await | |
{ | |
Ok(message) => info!("Text message sent successfully {:?}", message.id), | |
Err(e) => warn!("Text message wasn't sent because of: {}", e) | |
}; | |
} | |
fn build_message(metadata: &Metadata, buy: Buy) -> String { | |
let price = get_price(buy.data); | |
let token_type = HashMap::from([ | |
(String::from("ERC20"), String::from("USDC")) | |
]); | |
let token = token_type.get(&buy.the_type).map_or("ETH", String::as_str); | |
let (tier, name, landmark, | |
hydrogen, carbon, silicon, | |
solon, crypton, hyperion | |
) = (&metadata.tier, &metadata.name, &metadata.landmark, | |
&metadata.hydrogen, &metadata.carbon, &metadata.silicon, | |
&metadata.solon, &metadata.crypton, &metadata.hyperion | |
); | |
format!("T{tier} {name}\nprice: {price}{token}\nlandmark: {landmark}\ | |
\nhydrogen: {hydrogen} carbon: {carbon} silicon: {silicon}\ | |
\nsolon: {solon} crypton: {crypton} hyperion: {hyperion})") | |
} | |
fn get_price(data: BuyData) -> f32 { | |
let index_of_comma = data.quantity.chars().count() as i32 - data.decimals; | |
return match index_of_comma { | |
-1 => ("0.0".to_owned() + &data.quantity).parse().unwrap(), | |
0 => ("0.".to_owned() + &data.quantity).parse().unwrap(), | |
_ => { | |
let mut quantity_clone = data.quantity.clone(); | |
quantity_clone.insert(index_of_comma as usize, '.'); | |
quantity_clone.parse().unwrap() | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment