made it post stats to dbl
This commit is contained in:
parent
79732d1710
commit
4fa8313c7b
7
.idea/dictionaries/jude.xml
Normal file
7
.idea/dictionaries/jude.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="jude">
|
||||
<words>
|
||||
<w>reqwest</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
72
Cargo.lock
generated
72
Cargo.lock
generated
@ -280,15 +280,6 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ct-logs"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d3686f5fa27dbc1d76c751300376e167c5a43387f44bb451fd1c24776e49113"
|
||||
dependencies = [
|
||||
"sct",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.8.1"
|
||||
@ -598,17 +589,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac965ea399ec3a25ac7d13b8affd4b8f39325cca00858ddf5eb29b79e6b14b08"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"ct-logs",
|
||||
"futures-util",
|
||||
"hyper",
|
||||
"log",
|
||||
"rustls 0.17.0",
|
||||
"rustls-native-certs",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-tls"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3adcd308402b9553630734e9c36b77a7e48b3821251ca2493e8cd596763aafaa"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"hyper",
|
||||
"native-tls",
|
||||
"tokio",
|
||||
"tokio-tls",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "0.2.0"
|
||||
@ -1090,11 +1092,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.10.4"
|
||||
version = "0.10.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02b81e49ddec5109a9dcfc5f2a317ff53377c915e9ae9d4f2fb50914b85614e2"
|
||||
checksum = "3b82c9238b305f26f53443e3a4bc8528d64b8d0bee408ec949eb7bf5635ec680"
|
||||
dependencies = [
|
||||
"base64 0.11.0",
|
||||
"base64 0.12.0",
|
||||
"bytes",
|
||||
"encoding_rs",
|
||||
"futures-core",
|
||||
@ -1103,25 +1105,27 @@ dependencies = [
|
||||
"http-body",
|
||||
"hyper",
|
||||
"hyper-rustls",
|
||||
"hyper-tls",
|
||||
"js-sys",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"mime",
|
||||
"mime_guess",
|
||||
"native-tls",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rustls 0.17.0",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"time",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-tls",
|
||||
"url",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"webpki-roots 0.18.0",
|
||||
"webpki-roots 0.19.0",
|
||||
"winreg",
|
||||
]
|
||||
|
||||
@ -1172,18 +1176,6 @@ dependencies = [
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-native-certs"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a75ffeb84a6bd9d014713119542ce415db3a3e4748f0bfce1e1416cd224a23a5"
|
||||
dependencies = [
|
||||
"openssl-probe",
|
||||
"rustls 0.17.0",
|
||||
"schannel",
|
||||
"security-framework",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.3"
|
||||
@ -1381,6 +1373,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"dotenv",
|
||||
"lazy_static",
|
||||
"reqwest",
|
||||
"serenity",
|
||||
"sqlx",
|
||||
"tokio",
|
||||
@ -1600,6 +1593,16 @@ dependencies = [
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-tls"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343"
|
||||
dependencies = [
|
||||
"native-tls",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-util"
|
||||
version = "0.3.1"
|
||||
@ -1844,15 +1847,6 @@ dependencies = [
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91cd5736df7f12a964a5067a12c62fa38e1bd8080aff1f80bc29be7c80d19ab4"
|
||||
dependencies = [
|
||||
"webpki",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.19.0"
|
||||
@ -1898,9 +1892,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
version = "0.6.2"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9"
|
||||
checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69"
|
||||
dependencies = [
|
||||
"winapi 0.3.8",
|
||||
]
|
||||
|
@ -10,3 +10,4 @@ sqlx = {version = "0.3.5", default-features = false, features = ["runtime-tokio"
|
||||
dotenv = "0.15"
|
||||
tokio = {version = "0.2.19", features = ["fs", "sync", "process", "io-util"]}
|
||||
lazy_static = "1.4.0"
|
||||
reqwest = "0.10.6"
|
||||
|
35
src/main.rs
35
src/main.rs
@ -1,6 +1,8 @@
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
extern crate reqwest;
|
||||
|
||||
mod guilddata;
|
||||
mod sound;
|
||||
mod error;
|
||||
@ -24,6 +26,7 @@ use serenity::{
|
||||
},
|
||||
model::{
|
||||
channel::Message,
|
||||
guild::Guild,
|
||||
id::{
|
||||
GuildId,
|
||||
RoleId,
|
||||
@ -85,6 +88,12 @@ impl TypeMapKey for VoiceGuilds {
|
||||
type Value = Arc<Mutex<HashMap<GuildId, u8>>>;
|
||||
}
|
||||
|
||||
struct ReqwestClient;
|
||||
|
||||
impl TypeMapKey for ReqwestClient {
|
||||
type Value = Arc<reqwest::Client>;
|
||||
}
|
||||
|
||||
static THEME_COLOR: u32 = 0x00e0f3;
|
||||
|
||||
lazy_static! {
|
||||
@ -220,6 +229,30 @@ struct Handler;
|
||||
|
||||
#[serenity::async_trait]
|
||||
impl EventHandler for Handler {
|
||||
async fn guild_create(&self, ctx: Context, _guild: Guild, is_new: bool) {
|
||||
if is_new {
|
||||
if let Ok(token) = env::var("DISCORDBOTS_TOKEN") {
|
||||
let guild_count = ctx.cache.guild_count().await;
|
||||
|
||||
let mut hm = HashMap::new();
|
||||
hm.insert("server_count", guild_count);
|
||||
|
||||
let client = ctx.data.read().await
|
||||
.get::<ReqwestClient>().cloned().expect("Could not get ReqwestClient from data");
|
||||
|
||||
let response = client.post(format!("https://top.gg/api/bots/{}/stats", ctx.cache.current_user_id().await.as_u64()).as_str())
|
||||
.header("Authorization", token)
|
||||
.json(&hm)
|
||||
.send()
|
||||
.await;
|
||||
|
||||
if let Ok(res) = response {
|
||||
println!("DiscordBots Response: {:?}", res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn voice_state_update(&self, ctx: Context, guild_id_opt: Option<GuildId>, old: Option<VoiceState>, new: VoiceState) {
|
||||
if let (Some(guild_id), Some(user_channel)) = (guild_id_opt, new.channel_id) {
|
||||
|
||||
@ -388,6 +421,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
data.insert::<VoiceManager>(Arc::clone(&client.voice_manager));
|
||||
|
||||
data.insert::<VoiceGuilds>(voice_guilds.clone());
|
||||
|
||||
data.insert::<ReqwestClient>(Arc::new(reqwest::Client::new()));
|
||||
}
|
||||
|
||||
let cvm = Arc::clone(&client.voice_manager);
|
||||
|
Loading…
Reference in New Issue
Block a user