tried to spawn a thread for the bot to run freely
This commit is contained in:
parent
5b5f4fb958
commit
2317a41bba
19
src/bot.rs
19
src/bot.rs
|
@ -26,14 +26,19 @@ impl EventHandler for Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn start_discord_bot() -> Result<Client, String> {
|
pub async fn start_discord_bot() {
|
||||||
let mut client = Client::builder(token::TOKEN)
|
let maybe_client = Client::builder(token::TOKEN)
|
||||||
.event_handler(Handler)
|
.event_handler(Handler)
|
||||||
.await
|
.await
|
||||||
.map_err(|why| format!("Client error: {:?}", why))?;
|
.map_err(|why| format!("Client error: {:?}", why));
|
||||||
|
|
||||||
if let Err(why) = client.start().await {
|
if let Ok(mut client) = maybe_client {
|
||||||
return Err(format!("Client error: {:?}", why));
|
if let Err(why) = client.start().await {
|
||||||
|
eprintln!("Client error: {:?}", why);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("No Client");
|
||||||
|
return
|
||||||
}
|
}
|
||||||
Ok(client)
|
|
||||||
}
|
}
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -1,8 +1,6 @@
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use image::GenericImageView;
|
use image::GenericImageView;
|
||||||
use serenity::prelude::*;
|
use std::{error::Error, sync::Arc, thread, time};
|
||||||
use std::{error::Error, sync::Arc, thread, time, future::Future};
|
|
||||||
|
|
||||||
mod bot;
|
mod bot;
|
||||||
|
|
||||||
const MAX_FPS: f32 = 30.0;
|
const MAX_FPS: f32 = 30.0;
|
||||||
|
@ -26,16 +24,16 @@ fn main() -> Result<(), eframe::Error> {
|
||||||
|
|
||||||
struct Jiji {
|
struct Jiji {
|
||||||
next_frame: time::Instant,
|
next_frame: time::Instant,
|
||||||
bot: Option<Client>,
|
bot: thread::JoinHandle<()>,
|
||||||
bot_future: Option<Box<dyn Future<Output = Result<Client, String>>>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Jiji {
|
impl Default for Jiji {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
next_frame: time::Instant::now(),
|
next_frame: time::Instant::now(),
|
||||||
bot: None,
|
bot: thread::spawn(|| {
|
||||||
bot_future: Some(Box::new(bot::start_discord_bot())),
|
bot::start_discord_bot();
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue