// handler for /generate categories commands
handler for /generate categories commands
handler for / generate categories commands
async fn handle_generate_categories(
    ctx: &Context,
    interaction: &ApplicationCommandInteraction,
) -> Option<SerenityResult<()>> {
    let rcos_api_response = small_group_info::CurrSmallGroups::get(0, None)
        .await
        .map_err(|err| {
            error!("Could not query the RCOS API: {}", err);
            err
        });
    if let Err(err) = rcos_api_response {
        return Some(
            interaction_error(
                "RCOS API Error",
                "We could not get data about small groups because the \
        RCOS API responded with an error. Please contact a coordinator and \
        report this error on Telescope's GitHub.",
                &err,
                &ctx,
                &interaction,
            )
            .await,
        );
    }
    let small_groups_associate_info = rcos_api_response.unwrap().small_groups;
    // Create category for projects if not previously created.
    for small_group in small_groups_associate_info {
        if small_group.small_group_categories.is_empty() {
            // Generate permission for certain groups for the channel.
            let overwrite = if let true = small_group.small_group_role.is_none() {
                generate_permission(None, get_roles(ctx).await)
            } else {
                generate_permission(
                    Some(RoleId(
                        small_group
                            .small_group_role
                            .unwrap()
                            .role_id
                            .parse::<u64>()
                            .unwrap(),
                    )),
                    get_roles(ctx).await,
                )
            };
            let category = GuildId(global_config().discord_config.rcos_guild_id())
                .create_channel(&ctx.http, |c| {
                    c.name(small_group.title)
                        .kind(SerenityChannelType::Category)
                        .permissions(overwrite)
                })
                .await
                .map_err(|err| {
                    error!("Could not create the category for small group: {}", err);
                    err
                });
            if let Err(err) = category {
                return Some(
                    interaction_error(
                        "Discord Error",
                        "We could not create category for small group",
                        &err,
                        &ctx,
                        &interaction,
                    )
                    .await,
                );
            }
            // insert category data into database
            let insert_category =
                create_small_group_category::CreateOneSmallGroupCategory::execute(
                    small_group.small_group_id,
                    category.unwrap().id.to_string(),
                )
                .await
                .map_err(|err| {
                    error!(
                        "Could not insert small group category data to into database: {}",
                        err
                    );
                    err
                });
            if let Err(err) = insert_category {
                return Some(
                    interaction_error(
                        "Database Error",
                        "We could not insert category for small group into database",
                        &err,
                        &ctx,
                        &interaction,
                    )
                    .await,
                );
            }
        }
    }
    return None;
}
async fn handle_generate_categories ( ctx : & Context , interaction : & ApplicationCommandInteraction , ) -> Option < SerenityResult < ( ) > > { let rcos_api_response = small_group_info :: CurrSmallGroups :: get ( 0 , None ) . await . map_err ( | err | { error ! ( " " err ) ; err } ) ; if let Err ( err ) = rcos_api_response { return Some ( interaction_error ( " " , " \
 \
 " , & err , & ctx , & interaction , ) . await , ) ; } let small_groups_associate_info = rcos_api_response . unwrap ( ) . small_groups ; // Create category for projects if not previously created. for small_group in small_groups_associate_info { if small_group . small_group_categories . is_empty ( ) { // Generate permission for certain groups for the channel. let overwrite = if let true = small_group . small_group_role . is_none ( ) { generate_permission ( None , get_roles ( ctx ) . await ) } else { generate_permission ( Some ( RoleId ( small_group . small_group_role . unwrap ( ) . role_id . parse :: < u64 > ( ) . unwrap ( ) , ) ) , get_roles ( ctx ) . await , ) } ; let category = GuildId ( global_config ( ) . discord_config . rcos_guild_id ( ) ) . create_channel ( & ctx . http , | c | { c . name ( small_group . title ) . kind ( SerenityChannelType :: Category ) . permissions ( overwrite ) } ) . await . map_err ( | err | { error ! ( " " err ) ; err } ) ; if let Err ( err ) = category { return Some ( interaction_error ( " " , " " , & err , & ctx , & interaction , ) . await , ) ; } // insert category data into database let insert_category = create_small_group_category :: CreateOneSmallGroupCategory :: execute ( small_group . small_group_id , category . unwrap ( ) . id . to_string ( ) , ) . await . map_err ( | err | { error ! ( " " err ) ; err } ) ; if let Err ( err ) = insert_category { return Some ( interaction_error ( " " , " " , & err , & ctx , & interaction , ) . await , ) ; } } } return None ; }
handler for /generate categories commands
handler for / generate categories commands
ctx
&Context
interaction
&ApplicationCommandInteraction