Initialize client, not on ready

This commit is contained in:
2023-03-11 20:19:38 -05:00
parent fe77b6662d
commit 3a1b35967a
3 changed files with 7 additions and 5 deletions

View File

@@ -18,9 +18,6 @@ impl EventHandler for Handler {
// In this case, just print what the current user's username is. // In this case, just print what the current user's username is.
async fn ready(&self, ctx: Context, ready: Ready) { async fn ready(&self, ctx: Context, ready: Ready) {
println!("{} is connected!", ready.user.name); 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) { async fn guild_create(&self, ctx: Context, guild: Guild, _new: bool) {

View File

@@ -43,6 +43,10 @@ async fn main() {
.await .await
.expect("Err creating client"); .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 { if let Err(why) = client.start().await {
println!("Client error: {:?}", why); println!("Client error: {:?}", why);
} }

View File

@@ -2,6 +2,7 @@ use std::ops::Range;
use std::sync::Arc; use std::sync::Arc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use rand::prelude::*; use rand::prelude::*;
use serenity::Client;
use songbird::id::ChannelId; use songbird::id::ChannelId;
use std::thread::sleep; use std::thread::sleep;
use std::collections::HashMap; use std::collections::HashMap;
@@ -85,8 +86,8 @@ async fn popin_soon(ctx: Context, guild: Guild) {
tokio::spawn(popin(ctx.clone(),guild)); tokio::spawn(popin(ctx.clone(),guild));
} }
pub async fn init(ctx: Context) { pub async fn init(client: Client) {
let mut data = ctx.data.write().await; let mut data = client.data.write().await;
data.insert::<GuildPopIn>(Arc::new(RwLock::new(HashMap::default()))) data.insert::<GuildPopIn>(Arc::new(RwLock::new(HashMap::default())))
} }