moved token access
This commit is contained in:
parent
8cfa9568d0
commit
a76953a9eb
|
@ -1 +1 @@
|
|||
{"categories":[{"name":"to do","content":[{"name":"ability to change token","description":"use a config file to store token so that \n\n1- it is away from github\n\n2- it is configurable if need be","id":1},{"name":"clean up bot code","description":"try to remove unnecessary code\n\nunindent\n\ngive sender to function ?","id":2},{"name":"trayable ?","description":"// Hello there","id":5},{"name":"new message marker","description":"perma if too complicated to detect read","id":2},{"name":"proper links","description":"when there is a link, ability to click it","id":3}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"run discord bot","description":"make it so the bot is running","id":1},{"name":"fixed token in github","description":"// Hello there","id":1},{"name":"fetch previous messages","description":"// Hello there","id":4},{"name":"ability to write messages","description":"// Hello there","id":5},{"name":"get incoming messages","description":"read","id":2},{"name":"unread system","description":"add a * when a channel just received a message","id":1},{"name":"remember channel id for dm","description":"and put in config file\n\nmaybe load message ? dm first ?","id":3},{"name":"bug : does not save notification state for dm","description":"// Hello there","id":1},{"name":"handle unknown channel better","description":"when receiving a message from a not yet scanned guild, create the channel and put the message\n\nallow scanning if guild selected\n\ndo not add duplicate channel","id":1},{"name":"guild unread ?","description":"// Hello there","id":2},{"name":"timestamps","description":"// Hello there","id":1},{"name":"better ui error display","description":"handle the error packet for better display","id":1},{"name":"notifications !!!","description":"// Hello there","id":4}]},{"name":"bugs","content":[]},{"name":"v1.0","content":[]},{"name":"+","content":[]}]}
|
||||
{"categories":[{"name":"to do","content":[{"name":"clean up bot code","description":"try to remove unnecessary code\n\nunindent\n\ngive sender to function ?","id":2},{"name":"trayable ?","description":"// Hello there","id":5},{"name":"new message marker","description":"perma if too complicated to detect read","id":2},{"name":"proper links","description":"when there is a link, ability to click it","id":3}]},{"name":"in progress","content":[]},{"name":"done","content":[{"name":"run discord bot","description":"make it so the bot is running","id":1},{"name":"fixed token in github","description":"// Hello there","id":1},{"name":"fetch previous messages","description":"// Hello there","id":4},{"name":"ability to write messages","description":"// Hello there","id":5},{"name":"get incoming messages","description":"read","id":2},{"name":"unread system","description":"add a * when a channel just received a message","id":1},{"name":"remember channel id for dm","description":"and put in config file\n\nmaybe load message ? dm first ?","id":3},{"name":"bug : does not save notification state for dm","description":"// Hello there","id":1},{"name":"handle unknown channel better","description":"when receiving a message from a not yet scanned guild, create the channel and put the message\n\nallow scanning if guild selected\n\ndo not add duplicate channel","id":1},{"name":"guild unread ?","description":"// Hello there","id":2},{"name":"timestamps","description":"// Hello there","id":1},{"name":"better ui error display","description":"handle the error packet for better display","id":1},{"name":"notifications !!!","description":"// Hello there","id":4}]},{"name":"bugs","content":[]},{"name":"v1.0","content":[{"name":"ability to change token","description":"use a config file to store token so that \n\n1- it is away from github\n\n2- it is configurable if need be","id":1}]},{"name":"+","content":[]}]}
|
32
src/bot.rs
32
src/bot.rs
|
@ -17,7 +17,7 @@ use tokio::time::interval;
|
|||
use crate::postman;
|
||||
use crate::discord_structure;
|
||||
|
||||
mod token;
|
||||
pub mod token;
|
||||
|
||||
const HELP_MESSAGE: &str = "Hello there, Human! I am a messenger for the wandering penwing.";
|
||||
const HELP_COMMAND: &str = "!penwing";
|
||||
|
@ -245,13 +245,13 @@ async fn get_guilds(context: &Context) {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn start_discord_bot(sender: mpsc::Sender<postman::Packet>, receiver: Mutex<mpsc::Receiver<postman::Packet>>) {
|
||||
pub async fn start_discord_bot(token: &str, sender: mpsc::Sender<postman::Packet>, receiver: Mutex<mpsc::Receiver<postman::Packet>>) {
|
||||
println!("bot : connection process started...");
|
||||
let maybe_client = Client::builder(token::TOKEN)
|
||||
let maybe_client = Client::builder(token)
|
||||
.event_handler(Handler {
|
||||
is_loop_running: AtomicBool::new(false),
|
||||
})
|
||||
.type_map_insert::<postman::Sender>(sender)
|
||||
.type_map_insert::<postman::Sender>(sender.clone())
|
||||
.type_map_insert::<postman::Receiver>(receiver)
|
||||
.await
|
||||
.map_err(|why| format!("Client error: {:?}", why));
|
||||
|
@ -259,13 +259,25 @@ pub async fn start_discord_bot(sender: mpsc::Sender<postman::Packet>, receiver:
|
|||
//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 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 {
|
||||
Ok(mut client) => {
|
||||
if let Err(why) = client.start().await {
|
||||
println!("bot : client error: {:?}", why);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
println!("bot : no client");
|
||||
sender.send(postman::Packet::Error(format!("Start error: {:?}", why))).expect("Failed to send packet");
|
||||
return;
|
||||
}
|
||||
}
|
||||
Err(why) => {
|
||||
sender.send(postman::Packet::Error(why)).expect("Failed to send packet");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,12 @@ fn main() {
|
|||
let (gui_tx, bot_rx) = mpsc::channel::<postman::Packet>(); //tx transmiter
|
||||
let bot_rx = Mutex::new(bot_rx);
|
||||
|
||||
let token = bot::token::TOKEN;
|
||||
|
||||
let _handle = thread::spawn(move || {
|
||||
println!("main : bot thread spawned");
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
rt.block_on(bot::start_discord_bot(bot_tx, bot_rx));
|
||||
rt.block_on(bot::start_discord_bot(token, bot_tx, bot_rx));
|
||||
});
|
||||
|
||||
// Run the GUI on the main thread
|
||||
|
|
Loading…
Reference in a new issue