mirror of https://github.com/MedzikUser/imgurs
feat(webhook): add discord webhook
example https://i.imgur.com/fgSyFZP.png
This commit is contained in:
parent
6ec952b60f
commit
572899509f
|
@ -830,6 +830,19 @@ dependencies = [
|
|||
"tokio-rustls",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-tls"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"hyper",
|
||||
"native-tls",
|
||||
"tokio",
|
||||
"tokio-native-tls",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.2.3"
|
||||
|
@ -881,6 +894,7 @@ dependencies = [
|
|||
"tokio",
|
||||
"toml",
|
||||
"validator",
|
||||
"webhook",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1054,6 +1068,24 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "native-tls"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"log",
|
||||
"openssl",
|
||||
"openssl-probe",
|
||||
"openssl-sys",
|
||||
"schannel",
|
||||
"security-framework",
|
||||
"security-framework-sys",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.20.2"
|
||||
|
@ -1198,6 +1230,39 @@ version = "1.9.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
|
||||
|
||||
[[package]]
|
||||
name = "openssl"
|
||||
version = "0.10.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"openssl-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-probe"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
|
||||
|
||||
[[package]]
|
||||
name = "openssl-sys"
|
||||
version = "0.9.72"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ordered-stream"
|
||||
version = "0.0.1"
|
||||
|
@ -1266,6 +1331,12 @@ version = "0.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
|
||||
|
||||
[[package]]
|
||||
name = "png"
|
||||
version = "0.16.8"
|
||||
|
@ -1432,6 +1503,15 @@ version = "0.6.25"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
||||
|
||||
[[package]]
|
||||
name = "remove_dir_all"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.11.9"
|
||||
|
@ -1536,6 +1616,16 @@ version = "1.0.9"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
|
||||
|
||||
[[package]]
|
||||
name = "schannel"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
|
@ -1552,6 +1642,29 @@ dependencies = [
|
|||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "security-framework"
|
||||
version = "2.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23a2ac85147a3a11d77ecf1bc7166ec0b92febfa4461c37944e180f319ece467"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"core-foundation",
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
"security-framework-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "security-framework-sys"
|
||||
version = "2.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556"
|
||||
dependencies = [
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.136"
|
||||
|
@ -1711,6 +1824,20 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"fastrand",
|
||||
"libc",
|
||||
"redox_syscall 0.2.10",
|
||||
"remove_dir_all",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.2"
|
||||
|
@ -1821,6 +1948,16 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-native-tls"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b"
|
||||
dependencies = [
|
||||
"native-tls",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-rustls"
|
||||
version = "0.23.2"
|
||||
|
@ -1958,6 +2095,12 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
|
@ -2068,6 +2211,18 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webhook"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3482f4a3d66b31b4be952ba25255a51cc4ae73f4abc0f0907450644db766e3b"
|
||||
dependencies = [
|
||||
"hyper",
|
||||
"hyper-tls",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki"
|
||||
version = "0.22.0"
|
||||
|
|
|
@ -33,6 +33,7 @@ better-panic = "0.3.0"
|
|||
validator = "0.14.0"
|
||||
colored = "2.0.0"
|
||||
clap_mangen = "0.1.2"
|
||||
webhook = "2.0.0"
|
||||
|
||||
[target.'cfg(not(all(unix, not(any(target_os="macos", target_os="android", target_os="emscripten")))))'.dependencies]
|
||||
arboard = "2.0.1"
|
||||
|
|
|
@ -6,3 +6,7 @@ enabled = true
|
|||
|
||||
[clipboard]
|
||||
enabled = true
|
||||
|
||||
[discord_webhook]
|
||||
enabled = false
|
||||
uri = ''
|
||||
|
|
|
@ -4,6 +4,7 @@ pub mod delete_image;
|
|||
pub mod info_image;
|
||||
pub mod parse;
|
||||
pub mod upload_image;
|
||||
pub mod webhook;
|
||||
|
||||
use chrono::{prelude::DateTime, Utc};
|
||||
use colored::Colorize;
|
||||
|
|
|
@ -2,7 +2,7 @@ use super::clipboard::set_clipboard;
|
|||
use imgurs::api::{upload_image::upload_image as upload_img, ImgurClient};
|
||||
use notify_rust::Notification;
|
||||
|
||||
use crate::config::toml::parse as parse_config;
|
||||
use crate::{config::toml, cli::webhook::send_discord_webhook};
|
||||
|
||||
use super::print_image_info;
|
||||
|
||||
|
@ -11,7 +11,7 @@ use std::{fs::read as fs_read, path::Path};
|
|||
|
||||
macro_rules! notify (
|
||||
($notification: expr) => (
|
||||
if parse_config().notification.enabled {
|
||||
if toml::parse().notification.enabled {
|
||||
$notification.show().expect("send notification");
|
||||
}
|
||||
);
|
||||
|
@ -34,6 +34,7 @@ pub async fn upload_image(client: ImgurClient, path: &str) {
|
|||
.summary("Error!")
|
||||
.body(&format!("Error: {}", &err.to_string()))
|
||||
.appname("Imgurs")); // I don't think you can set it to error
|
||||
|
||||
panic!("{}", err)
|
||||
});
|
||||
print_image_info(i.clone());
|
||||
|
@ -42,7 +43,13 @@ pub async fn upload_image(client: ImgurClient, path: &str) {
|
|||
|
||||
notify!(Notification::new().summary("Imgurs").body(&body));
|
||||
|
||||
if parse_config().clipboard.enabled {
|
||||
set_clipboard(i.data.link)
|
||||
let config = toml::parse();
|
||||
|
||||
if config.clipboard.enabled {
|
||||
set_clipboard(i.data.link.clone())
|
||||
}
|
||||
|
||||
if config.discord_webhook.enabled {
|
||||
send_discord_webhook(i.data.link, i.data.deletehash.unwrap()).await.expect("send discord webhook");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ pub struct Config {
|
|||
pub imgur: ConfigImgur,
|
||||
pub notification: ConfigNotification,
|
||||
pub clipboard: ConfigClipboard,
|
||||
pub discord_webhook: ConfigDiscordWebhook,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
@ -23,3 +24,9 @@ pub struct ConfigNotification {
|
|||
pub struct ConfigClipboard {
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ConfigDiscordWebhook {
|
||||
pub enabled: bool,
|
||||
pub uri: String,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue