From e3b7a1b13e881e6b8b4c640578410a2b9190941f Mon Sep 17 00:00:00 2001 From: Sakuhl <2012collector@gmail.com> Date: Fri, 12 Jan 2018 15:34:12 +0100 Subject: [PATCH] Add auto-crop command --- Cargo.lock | 2 +- src/main.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e1d39c..b4effdc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1100,7 +1100,7 @@ dependencies = [ [[package]] name = "wynnrobot" -version = "0.1.0" +version = "0.9.1" dependencies = [ "diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/main.rs b/src/main.rs index 3d8414e..b356bf5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,8 +46,10 @@ impl EventHandler for Handler { wc_livefeed(msg); } else if msg.content.starts_with("wc!unlivefeed") { wc_unlivefeed(msg); - } else if msg.content == "wc!info" { + } else if msg.content == "wc!info" || msg.content == "wc!help" || msg.content == "wc!" { wc_info(msg); + } else if msg.content.starts_with("wc!crop ") { + wc_crop(msg); } } @@ -232,7 +234,7 @@ fn wc_unlivefeed(msg: Message) { let connection = establish_connection(); let channel_id = msg.channel_id.0 as i64; - let num_deleted = diesel::delete(livefeedlisteners.filter(id.eq(channel_id))) + diesel::delete(livefeedlisteners.filter(id.eq(channel_id))) .execute(&connection) .expect("Error deleting posts"); @@ -242,10 +244,17 @@ fn wc_unlivefeed(msg: Message) { fn wc_info(msg: Message) { let guilds = serenity::http::get_current_user().unwrap().guilds().unwrap().len(); msg.channel_id.say(format!("Developer: Wurst#1783 +Forum thread: https://forums.wynncraft.com/threads/discord-bot.212142/ Version: {} Servers: {}", env!("CARGO_PKG_VERSION"), guilds)).unwrap(); } +fn wc_crop(msg: Message) { + let url = &msg.content[8..]; + let new_url = reqwest::get(&format!("https://wynncraft-autocrop.herokuapp.com/?url={}", url)).unwrap().text().unwrap(); + msg.channel_id.say(&new_url).unwrap(); +} + fn territory_livefeed() { use models::LivefeedListener; use schema::livefeedlisteners::dsl::*;