UA6AQUK37FVMQHXLMRAEEKV4JF6CHJI5Y72G2HSJX4HGY42AVAVAC
E3JNTFL4KR4647E2ONDQJ3SZJQG7ZXR2KZD634D5JYXRPT7IIKWAC
7X3AZRA7PHV3TYMSR6YSE3XZTZDYRF7UMH7UELYMTXRBYCVE6R4QC
L4T474CNJCONMNPILIUW3ZWBKBTW5QPGRLUFPO2QWAHPFECT6ZSAC
5YD5TE7BVUUMNIT2WQPFPLZ75Z4GK74B2NPCZO33U2JWCEOSN4HAC
35EVA5MHEJMVJWQUXIJWAX43LJZ7YLE5Y4YN5T2SOSTBTQB6HTTQC
HU54Y66265W2VOTVERPHEFFKM3FDNZHL5FDTWBE4OX5YIELFNRLAC
use std::env;
fn get_image_url(text: &str) -> Result<String, Box<dyn std::error::Error>> {
let logs = env::var("IMGFLIP")?;
let logs: Vec<&str> = logs.splitn(2, ':').collect();
let username = logs[0];
let password = logs[1];
let url = format!(
"username={}&password={}&template_id=102156234&boxes[0][text]=&boxes[1][text]={}",
username, password, text
);
let resp = ureq::post("https://api.imgflip.com/caption_image")
.set("Content-Type", "application/x-www-form-urlencoded")
.send_string(&url);
let url = &resp.into_json()?["data"]["url"];
if let Some(url) = url.as_str() {
Ok(url.to_string())
} else {
Err("Could not as str".into())
}
}
use serenity::framework::standard::{macros::command, Args, CommandResult};
use serenity::{model::channel::Message, prelude::Context};
#[command]
pub fn roasted(ctx: &mut Context, msg: &Message, _args: Args) -> CommandResult {
let message: String = msg
.content
.chars()
.skip("!roasted ".chars().count())
.collect();
if let Ok(url) = crate::imgflip::generate_image_url(Some(&message), None, "122616222") {
let _ = msg
.channel_id
.send_files(&ctx, vec![url.as_str()], |m| m.content(&msg.author));
}
let _ = msg.delete(&ctx);
Ok(())
}
use std::env;
/// Generate a meme with the imageflip API
/// h1 -> the text to the top of the image
/// h2 -> the text to the bottom of the image
/// id -> the id of the meme
pub fn generate_image_url(
h1: Option<&str>,
h2: Option<&str>,
id: &str,
) -> Result<String, Box<dyn std::error::Error>> {
let logs = env::var("IMGFLIP")?;
let logs: Vec<&str> = logs.splitn(2, ':').collect();
let username = logs[0];
let password = logs[1];
let url = format!(
"username={}&password={}&template_id={}&boxes[0][text]={}&boxes[1][text]={}",
username,
password,
id,
h1.unwrap_or(""),
h2.unwrap_or("")
);
let resp = ureq::post("https://api.imgflip.com/caption_image")
.set("Content-Type", "application/x-www-form-urlencoded")
.send_string(&url);
let url = &resp.into_json()?["data"]["url"];
if let Some(url) = url.as_str() {
Ok(url.to_string())
} else {
Err("Could not as str".into())
}
}