add bovine
This commit is contained in:
parent
788dca687f
commit
d348b548c1
29
src/main.rs
29
src/main.rs
|
@ -19,9 +19,7 @@
|
||||||
use teloxide::{prelude::*, utils::command::BotCommand, requests::ResponseResult};
|
use teloxide::{prelude::*, utils::command::BotCommand, requests::ResponseResult};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::error::Error;
|
use std::{error::Error, fs::File, io::prelude::*};
|
||||||
use std::fs::File;
|
|
||||||
use std::io::prelude::*;
|
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
|
|
||||||
type AsyncResult<T> = Result<T, Box<dyn Error + Send + Sync>>;
|
type AsyncResult<T> = Result<T, Box<dyn Error + Send + Sync>>;
|
||||||
|
@ -115,10 +113,10 @@ async fn quaff(id: i64) -> AsyncResult<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn harvest_corn() -> AsyncResult<String> {
|
async fn grab_photo(query: &'static str) -> AsyncResult<String> {
|
||||||
if let Some(access) = std::env::var_os("UNSPLASH_ACCESS") {
|
if let Some(access) = std::env::var_os("UNSPLASH_ACCESS") {
|
||||||
// call API to get a random picture of corn
|
// call API to get a random picture of corn
|
||||||
let auth_uri = format!("https://api.unsplash.com/photos/random/?client_id={}&query={}", access.into_string().unwrap(), "corn");
|
let auth_uri = format!("https://api.unsplash.com/photos/random/?client_id={}&query={}", access.into_string().unwrap(), query);
|
||||||
let response = reqwest::get(&auth_uri)
|
let response = reqwest::get(&auth_uri)
|
||||||
.await.unwrap().text().await.unwrap();
|
.await.unwrap().text().await.unwrap();
|
||||||
// response format is some pretty nested json
|
// response format is some pretty nested json
|
||||||
|
@ -134,6 +132,14 @@ async fn harvest_corn() -> AsyncResult<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn harvest_corn() -> AsyncResult<String> {
|
||||||
|
grab_photo("corn").await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn bovine() -> AsyncResult<String> {
|
||||||
|
grab_photo("cow").await
|
||||||
|
}
|
||||||
|
|
||||||
//// TO IMPLEMENT A NEW COMMAND
|
//// TO IMPLEMENT A NEW COMMAND
|
||||||
// Add the command name to the Command enum with a description
|
// Add the command name to the Command enum with a description
|
||||||
// Implement the logic of the command in the match statement in answer()
|
// Implement the logic of the command in the match statement in answer()
|
||||||
|
@ -156,7 +162,9 @@ enum Command {
|
||||||
#[command(description = "Get the number of beers on tap")]
|
#[command(description = "Get the number of beers on tap")]
|
||||||
Count,
|
Count,
|
||||||
#[command(description = "Die stupidly")]
|
#[command(description = "Die stupidly")]
|
||||||
Yasd
|
Yasd,
|
||||||
|
#[command(description = "Take a tripe to the pasture")]
|
||||||
|
Bovine
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn answer(cx: UpdateWithCx<AutoSend<Bot>, Message>, command: Command) -> ResponseResult<()> {
|
async fn answer(cx: UpdateWithCx<AutoSend<Bot>, Message>, command: Command) -> ResponseResult<()> {
|
||||||
|
@ -228,6 +236,15 @@ async fn answer(cx: UpdateWithCx<AutoSend<Bot>, Message>, command: Command) -> R
|
||||||
cx.reply_to("You don't have a farm.").await?
|
cx.reply_to("You don't have a farm.").await?
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Command::Bovine => {
|
||||||
|
log::info!("cow time");
|
||||||
|
if let Ok(bovine) = bovine().await {
|
||||||
|
cx.answer_photo(teloxide::types::InputFile::url(bovine)).await?
|
||||||
|
} else {
|
||||||
|
log::error!("An error occurred within bovine()");
|
||||||
|
cx.reply_to("No bovine").await?
|
||||||
|
}
|
||||||
|
},
|
||||||
Command::Post => {
|
Command::Post => {
|
||||||
log::info!("Generating new message");
|
log::info!("Generating new message");
|
||||||
let new_msg = telegram_markov_chain::chain();
|
let new_msg = telegram_markov_chain::chain();
|
||||||
|
|
Loading…
Reference in New Issue