From b87195ab71c370736d10f20ea15c53bb4a855303 Mon Sep 17 00:00:00 2001 From: WanderingPenwing Date: Sun, 14 Jul 2024 12:07:48 +0200 Subject: [PATCH] added token in config --- src/bot.rs | 22 ++++------------------ src/main.rs | 6 +++++- src/ui.rs | 9 ++++++++- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index 5bd3f9f..729a38e 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -245,29 +245,15 @@ async fn get_guilds(context: &Context) { } } -pub async fn start_discord_bot(token: &str, sender: mpsc::Sender, receiver: Mutex>) { +pub async fn start_discord_bot(token: String, sender: mpsc::Sender, receiver: Mutex>) { println!("bot : connection process started..."); - let maybe_client = Client::builder(token) + let maybe_client = Client::builder(&token) .event_handler(Handler { is_loop_running: AtomicBool::new(false), }) .type_map_insert::(sender.clone()) .type_map_insert::(receiver) - .await - .map_err(|why| format!("Client error: {:?}", why)); - - //let mut rx = bot_rx.lock().unwrap(); // Lock the receiver - //let msg = rx.recv().unwrap(); // Receive a message - -// if let Ok(mut client) = maybe_client { -// if let Err(why) = client.start().await { -// println!("bot : client error: {:?}", why); -// return; -// } -// } else { -// println!("bot : no client"); -// return; -// } + .await; match maybe_client { Ok(mut client) => { @@ -277,7 +263,7 @@ pub async fn start_discord_bot(token: &str, sender: mpsc::Sender { - sender.send(postman::Packet::Error(why)).expect("Failed to send packet"); + sender.send(postman::Packet::Error(format!("Client error: {:?}", why))).expect("Failed to send packet"); } } } diff --git a/src/main.rs b/src/main.rs index 1b35f6e..d4cb08a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,9 @@ fn main() { let (gui_tx, bot_rx) = mpsc::channel::(); //tx transmiter let bot_rx = Mutex::new(bot_rx); - let token = bot::token::TOKEN; + let app_state = state::load_state(&save_path()); + + let token: String = app_state.bot_token.clone();//bot::token::TOKEN; let _handle = thread::spawn(move || { println!("main : bot thread spawned"); @@ -52,6 +54,7 @@ struct Jiji { sender: mpsc::Sender, receiver: mpsc::Receiver, bot_token: String, + edit_token: bool, guilds: Vec, selected_guild: Option, selected_channel: Option, @@ -84,6 +87,7 @@ impl Jiji { sender, receiver, bot_token: app_state.bot_token.clone(), + edit_token: false, guilds: vec![dms], selected_guild: None, selected_channel: None, diff --git a/src/ui.rs b/src/ui.rs index 6faf09a..989f359 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -23,7 +23,14 @@ impl Jiji { self.errors.remove(index); } ui.horizontal(|ui| { - ui.label("Where do you want to look ? "); + if ui.button("⚙").clicked() { + self.edit_token = !self.edit_token; + } + if self.edit_token { + ui.label("Token :"); + ui.add(egui::TextEdit::singleline(&mut self.bot_token).desired_width(30.0)); + } + ui.label(" "); let selected_guild_text = if let Some(selected_guild_index) = &self.selected_guild { self.guilds[*selected_guild_index].display() } else {