pub async fn post_training(ctx: &Context, training: &mut db::Training) -> Result<Message> {
        let channel = {
            let lock = SignupBoard::get(ctx).await.clone();
            let sb = lock.read().await;
            sb.post_channel(ctx, training).await?
        };

        let mut msg = match training.board_message() {
            Some(msg_id) => {
                if let Ok(msg) = channel.message(ctx, msg_id).await {
                    // Message already registered and still in channel
                    msg
                } else {
                    // Message already registered but not found anymore. Create new
                    let msg = channel
                        .send_message(ctx, |f| f.content("Loading training"))
                        .await?;
                    training.set_board_msg(ctx, Some(msg.id.0)).await?;
                    msg
                }
            }
            None => {
                // Message not registered in db
                let msg = channel
                    .send_message(ctx, |f| f.content("Loading training"))
                    .await?;
                training.set_board_msg(ctx, Some(msg.id.0)).await?;
                msg
            }
        };

        update_signup_board_training(ctx, &mut msg, training).await?;
        Ok(msg)
    }
// Posts a training on the signup board
// This first checks if a msg is already registered with that training
// if so, it will check if the message still exists and updates it
// if no message registered or message not found create a new one
// we need a mutable reference to training to update msg id if needed
Posts a training on the signup board
This first checks if a msg is already registered with that training
if so, it will check if the message still exists and updates it
if no message registered or message not found create a new one
we need a mutable reference to training to update msg id if needed
Posts a training on the signup board This first checks if a msg is already registered with that training if so it will check if the message still exists and updates it if no message registered or message not found create a new one we need a mutable reference to training to update msg id if needed
pub async fn post_training(ctx: &Context, training: &mut db::Training) -> Result<Message> {
        let channel = {
            let lock = SignupBoard::get(ctx).await.clone();
            let sb = lock.read().await;
            sb.post_channel(ctx, training).await?
        };
        let mut msg = match training.board_message() {
            Some(msg_id) => {
                if let Ok(msg) = channel.message(ctx, msg_id).await {
                    // Message already registered and still in channel
                    msg
                } else {
                    // Message already registered but not found anymore. Create new
                    let msg = channel
                        .send_message(ctx, |f| f.content("Loading training"))
                        .await?;
                    training.set_board_msg(ctx, Some(msg.id.0)).await?;
                    msg
                }
            }
            None => {
                // Message not registered in db
                let msg = channel
                    .send_message(ctx, |f| f.content("Loading training"))
                    .await?;
                training.set_board_msg(ctx, Some(msg.id.0)).await?;
                msg
            }
        };
        update_signup_board_training(ctx, &mut msg, training).await?;
        Ok(msg)
    }
pub async fn post_training ( ctx : & Context , training : & mut db :: Training ) -> Result < Message > { let channel = { let lock = SignupBoard :: get ( ctx ) . await . clone ( ) ; let sb = lock . read ( ) . await ; sb . post_channel ( ctx , training ) . await ? } ; let mut msg = match training . board_message ( ) { Some ( msg_id ) => { if let Ok ( msg ) = channel . message ( ctx , msg_id ) . await { // Message already registered and still in channel msg } else { // Message already registered but not found anymore. Create new let msg = channel . send_message ( ctx , | f | f . content ( " " ) ) . await ? ; training . set_board_msg ( ctx , Some ( msg . id . 0 ) ) . await ? ; msg } } None => { // Message not registered in db let msg = channel . send_message ( ctx , | f | f . content ( " " ) ) . await ? ; training . set_board_msg ( ctx , Some ( msg . id . 0 ) ) . await ? ; msg } } ; update_signup_board_training ( ctx , & mut msg , training ) . await ? ; Ok ( msg ) }
Posts a training on the signup board
This first checks if a msg is already registered with that training
if so, it will check if the message still exists and updates it
if no message registered or message not found create a new one
we need a mutable reference to training to update msg id if needed
Posts a training on the signup board This first checks if a msg is already registered with that training if so it will check if the message still exists and updates it if no message registered or message not found create a new one we need a mutable reference to training to update msg id if needed
ctx
&Context
training
&mut db::Training