From 3a1b35967a0dbe38685813cf3daf3f8970703324 Mon Sep 17 00:00:00 2001 From: "DavidCrompton1192@gmail.com" Date: Sat, 11 Mar 2023 20:19:38 -0500 Subject: [PATCH] Initialize client, not on ready --- src/events.rs | 3 --- src/main.rs | 4 ++++ src/utils/guild_popin.rs | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/events.rs b/src/events.rs index 9773a8f..c904a76 100644 --- a/src/events.rs +++ b/src/events.rs @@ -18,9 +18,6 @@ impl EventHandler for Handler { // In this case, just print what the current user's username is. async fn ready(&self, ctx: Context, ready: Ready) { println!("{} is connected!", ready.user.name); - println!("Initialize guild voice popin state"); - - guild_popin::init(ctx).await; } async fn guild_create(&self, ctx: Context, guild: Guild, _new: bool) { diff --git a/src/main.rs b/src/main.rs index cffde60..fe43dcd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,6 +43,10 @@ async fn main() { .await .expect("Err creating client"); + // TODO: do checks when getting data in add guild etc. + println!("Initialize guild voice popin state"); + utils::guild_popin::init(client); + if let Err(why) = client.start().await { println!("Client error: {:?}", why); } diff --git a/src/utils/guild_popin.rs b/src/utils/guild_popin.rs index cde67f4..eb94b9a 100644 --- a/src/utils/guild_popin.rs +++ b/src/utils/guild_popin.rs @@ -2,6 +2,7 @@ use std::ops::Range; use std::sync::Arc; use std::time::{Duration, Instant}; use rand::prelude::*; +use serenity::Client; use songbird::id::ChannelId; use std::thread::sleep; use std::collections::HashMap; @@ -85,8 +86,8 @@ async fn popin_soon(ctx: Context, guild: Guild) { tokio::spawn(popin(ctx.clone(),guild)); } -pub async fn init(ctx: Context) { - let mut data = ctx.data.write().await; +pub async fn init(client: Client) { + let mut data = client.data.write().await; data.insert::(Arc::new(RwLock::new(HashMap::default()))) }