added token in config

This commit is contained in:
WanderingPenwing 2024-07-14 12:07:48 +02:00
parent a76953a9eb
commit b87195ab71
3 changed files with 17 additions and 20 deletions

View file

@ -245,29 +245,15 @@ async fn get_guilds(context: &Context) {
} }
} }
pub async fn start_discord_bot(token: &str, sender: mpsc::Sender<postman::Packet>, receiver: Mutex<mpsc::Receiver<postman::Packet>>) { pub async fn start_discord_bot(token: String, sender: mpsc::Sender<postman::Packet>, receiver: Mutex<mpsc::Receiver<postman::Packet>>) {
println!("bot : connection process started..."); println!("bot : connection process started...");
let maybe_client = Client::builder(token) let maybe_client = Client::builder(&token)
.event_handler(Handler { .event_handler(Handler {
is_loop_running: AtomicBool::new(false), is_loop_running: AtomicBool::new(false),
}) })
.type_map_insert::<postman::Sender>(sender.clone()) .type_map_insert::<postman::Sender>(sender.clone())
.type_map_insert::<postman::Receiver>(receiver) .type_map_insert::<postman::Receiver>(receiver)
.await .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;
// }
match maybe_client { match maybe_client {
Ok(mut client) => { Ok(mut client) => {
@ -277,7 +263,7 @@ pub async fn start_discord_bot(token: &str, sender: mpsc::Sender<postman::Packet
} }
} }
Err(why) => { Err(why) => {
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");
} }
} }
} }

View file

@ -22,7 +22,9 @@ fn main() {
let (gui_tx, bot_rx) = mpsc::channel::<postman::Packet>(); //tx transmiter let (gui_tx, bot_rx) = mpsc::channel::<postman::Packet>(); //tx transmiter
let bot_rx = Mutex::new(bot_rx); 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 || { let _handle = thread::spawn(move || {
println!("main : bot thread spawned"); println!("main : bot thread spawned");
@ -52,6 +54,7 @@ struct Jiji {
sender: mpsc::Sender<postman::Packet>, sender: mpsc::Sender<postman::Packet>,
receiver: mpsc::Receiver<postman::Packet>, receiver: mpsc::Receiver<postman::Packet>,
bot_token: String, bot_token: String,
edit_token: bool,
guilds: Vec<discord_structure::Guild>, guilds: Vec<discord_structure::Guild>,
selected_guild: Option<usize>, selected_guild: Option<usize>,
selected_channel: Option<usize>, selected_channel: Option<usize>,
@ -84,6 +87,7 @@ impl Jiji {
sender, sender,
receiver, receiver,
bot_token: app_state.bot_token.clone(), bot_token: app_state.bot_token.clone(),
edit_token: false,
guilds: vec![dms], guilds: vec![dms],
selected_guild: None, selected_guild: None,
selected_channel: None, selected_channel: None,

View file

@ -23,7 +23,14 @@ impl Jiji {
self.errors.remove(index); self.errors.remove(index);
} }
ui.horizontal(|ui| { 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 { let selected_guild_text = if let Some(selected_guild_index) = &self.selected_guild {
self.guilds[*selected_guild_index].display() self.guilds[*selected_guild_index].display()
} else { } else {