do not use unwrap in botscript/application.rs
This commit is contained in:
parent
18d6331344
commit
c9a3916304
@ -26,21 +26,27 @@ pub fn attach_user_application(
|
|||||||
let user_application =
|
let user_application =
|
||||||
c.create_callback(move |q: OwnedJsObject| -> Result<_, ScriptError> {
|
c.create_callback(move |q: OwnedJsObject| -> Result<_, ScriptError> {
|
||||||
let bot1 = bot.clone();
|
let bot1 = bot.clone();
|
||||||
let bot1 = bot1.read().unwrap();
|
let bot1 = bot1.read().expect("Can't read bot");
|
||||||
let bot2 = bot.read().unwrap();
|
let bot2 = bot.read().expect("Can't read bot");
|
||||||
let user: teloxide::types::User = match from_js(q.context(), &q) {
|
let user: teloxide::types::User = match from_js(q.context(), &q) {
|
||||||
Ok(q) => q,
|
Ok(q) => q,
|
||||||
Err(_) => todo!(),
|
Err(_) => todo!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let application = futures::executor::block_on(
|
let application = futures::executor::block_on(
|
||||||
Application::new(user.clone()).store_db(&mut db.write().unwrap()),
|
Application::new(user.clone())
|
||||||
|
.store_db(&mut db.write().expect("Can't write to db rwlock")),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let db2 = db.clone();
|
let db2 = db.clone();
|
||||||
let msg = tokio::task::block_in_place(move || {
|
let msg = tokio::task::block_in_place(move || {
|
||||||
Handle::current().block_on(async move {
|
Handle::current().block_on(async move {
|
||||||
send_application_to_chat(&bot1, &mut db2.write().unwrap(), &application).await
|
send_application_to_chat(
|
||||||
|
&bot1,
|
||||||
|
&mut db2.write().expect("Can't write to db rwlock"),
|
||||||
|
&application,
|
||||||
|
)
|
||||||
|
.await
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
let msg = match msg {
|
let msg = match msg {
|
||||||
@ -52,13 +58,13 @@ pub fn attach_user_application(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let (chat_id, msg_id) = futures::executor::block_on(
|
let (chat_id, msg_id) = futures::executor::block_on(
|
||||||
MessageAnswerer::new(&bot2, &mut db.write().unwrap(), user.id.0 as i64).answer(
|
MessageAnswerer::new(
|
||||||
"left_application_msg",
|
&bot2,
|
||||||
None,
|
&mut db.write().expect("Can't write to db rwlock"),
|
||||||
None,
|
user.id.0 as i64,
|
||||||
),
|
)
|
||||||
)
|
.answer("left_application_msg", None, None),
|
||||||
.unwrap();
|
)?;
|
||||||
futures::executor::block_on(
|
futures::executor::block_on(
|
||||||
MessageForward::new(msg.chat.id.0, msg.id.0, chat_id, msg_id, false)
|
MessageForward::new(msg.chat.id.0, msg.id.0, chat_id, msg_id, false)
|
||||||
.store_db(&mut db.write().unwrap()),
|
.store_db(&mut db.write().unwrap()),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user