async fn handle_generate_channels(
    ctx: &Context,
    interaction: &ApplicationCommandInteraction,
) -> Option<SerenityResult<()>> {
    // Create channel for small groups
    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,
        );
    }

    // Get list of discord association information for small groups.
    let small_groups_associate_info = rcos_api_response.unwrap().small_groups;

    for small_group in small_groups_associate_info {
        // Get parent channel(category) from data.
        let categories = small_group.small_group_categories;
        // Get list of projects of small group.
        let small_group_projects = &small_group.small_group_projects;
        for category in categories {
            // Create Voice and Text channel under small group category
            for small_group_project in small_group_projects {
                // Create channels for small group projects if not previously created.
                if small_group_project.project.project_channels.is_empty() {
                    // Generate permission for certain groups for the channel.
                    let overwrite = if let None = small_group_project.project.project_role {
                        generate_permission(None, get_roles(ctx).await)
                    } else {
                        generate_permission(
                            Some(RoleId(
                                small_group_project
                                    .project
                                    .project_role
                                    .as_ref()
                                    .unwrap()
                                    .role_id
                                    .parse::<u64>()
                                    .unwrap(),
                            )),
                            get_roles(ctx).await,
                        )
                    };

                    // Create voice channel.
                    let voice_channel = GuildId(global_config().discord_config.rcos_guild_id())
                        .create_channel(&ctx.http, |c| {
                            c.name(&small_group_project.project.title)
                                .kind(SerenityChannelType::Voice)
                                .permissions(overwrite.clone())
                                .category(ChannelId(category.category_id.parse::<u64>().unwrap()))
                        })
                        .await
                        .map_err(|err| {
                            error!("Could not create the voice channel: {}", err);
                            err
                        });

                    // Create text channel.
                    let text_channel = GuildId(global_config().discord_config.rcos_guild_id())
                        .create_channel(&ctx.http, |c| {
                            c.name(&small_group_project.project.title)
                                .kind(SerenityChannelType::Text)
                                .permissions(overwrite.clone())
                                .category(ChannelId(category.category_id.parse::<u64>().unwrap()))
                        })
                        .await
                        .map_err(|err| {
                            error!("Could not create the text channel: {}", err);
                            err
                        });

                    if let Err(err) = voice_channel {
                        return Some(
                            interaction_error(
                                "Discord Error",
                                "We could not create voice channel for projects",
                                &err,
                                &ctx,
                                &interaction,
                            )
                            .await,
                        );
                    }

                    if let Err(err) = text_channel {
                        return Some(
                            interaction_error(
                                "Discord Error",
                                "We could not create text channel for projects",
                                &err,
                                &ctx,
                                &interaction,
                            )
                            .await,
                        );
                    }

                    // insert voice channel data into database
                    let insert_voice_channel =
                        create_project_channel::CreateOneProjectChannel::execute(
                            small_group_project.project.project_id,
                            voice_channel.unwrap().id.to_string(),
                            ChannelType::DiscordVoice,
                        )
                        .await
                        .map_err(|err| {
                            error!(
                                "Could not insert project voice channel data to into database: {}",
                                err
                            );
                            err
                        });

                    // insert text channel data into database
                    let insert_text_channel =
                        create_project_channel::CreateOneProjectChannel::execute(
                            small_group_project.project.project_id,
                            text_channel.unwrap().id.to_string(),
                            ChannelType::DiscordText,
                        )
                        .await
                        .map_err(|err| {
                            error!(
                                "Could not insert project text channel data to into database: {}",
                                err
                            );
                            err
                        });

                    if let Err(err) = insert_voice_channel {
                        return Some(
                            interaction_error(
                                "Database Error",
                                "We could not insert voice channel for projects into database",
                                &err,
                                &ctx,
                                &interaction,
                            )
                            .await,
                        );
                    }
                    if let Err(err) = insert_text_channel {
                        return Some(
                            interaction_error(
                                "Database Error",
                                "We could not insert text channel for projects into database",
                                &err,
                                &ctx,
                                &interaction,
                            )
                            .await,
                        );
                    }
                }
            }
        }
    }
    return None;
}
// handler for /generate channel commands
handler for /generate channel commands
handler for / generate channel commands
async fn handle_generate_channels(
    ctx: &Context,
    interaction: &ApplicationCommandInteraction,
) -> Option<SerenityResult<()>> {
    // Create channel for small groups
    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,
        );
    }
    // Get list of discord association information for small groups.
    let small_groups_associate_info = rcos_api_response.unwrap().small_groups;
    for small_group in small_groups_associate_info {
        // Get parent channel(category) from data.
        let categories = small_group.small_group_categories;
        // Get list of projects of small group.
        let small_group_projects = &small_group.small_group_projects;
        for category in categories {
            // Create Voice and Text channel under small group category
            for small_group_project in small_group_projects {
                // Create channels for small group projects if not previously created.
                if small_group_project.project.project_channels.is_empty() {
                    // Generate permission for certain groups for the channel.
                    let overwrite = if let None = small_group_project.project.project_role {
                        generate_permission(None, get_roles(ctx).await)
                    } else {
                        generate_permission(
                            Some(RoleId(
                                small_group_project
                                    .project
                                    .project_role
                                    .as_ref()
                                    .unwrap()
                                    .role_id
                                    .parse::<u64>()
                                    .unwrap(),
                            )),
                            get_roles(ctx).await,
                        )
                    };
                    // Create voice channel.
                    let voice_channel = GuildId(global_config().discord_config.rcos_guild_id())
                        .create_channel(&ctx.http, |c| {
                            c.name(&small_group_project.project.title)
                                .kind(SerenityChannelType::Voice)
                                .permissions(overwrite.clone())
                                .category(ChannelId(category.category_id.parse::<u64>().unwrap()))
                        })
                        .await
                        .map_err(|err| {
                            error!("Could not create the voice channel: {}", err);
                            err
                        });
                    // Create text channel.
                    let text_channel = GuildId(global_config().discord_config.rcos_guild_id())
                        .create_channel(&ctx.http, |c| {
                            c.name(&small_group_project.project.title)
                                .kind(SerenityChannelType::Text)
                                .permissions(overwrite.clone())
                                .category(ChannelId(category.category_id.parse::<u64>().unwrap()))
                        })
                        .await
                        .map_err(|err| {
                            error!("Could not create the text channel: {}", err);
                            err
                        });
                    if let Err(err) = voice_channel {
                        return Some(
                            interaction_error(
                                "Discord Error",
                                "We could not create voice channel for projects",
                                &err,
                                &ctx,
                                &interaction,
                            )
                            .await,
                        );
                    }
                    if let Err(err) = text_channel {
                        return Some(
                            interaction_error(
                                "Discord Error",
                                "We could not create text channel for projects",
                                &err,
                                &ctx,
                                &interaction,
                            )
                            .await,
                        );
                    }
                    // insert voice channel data into database
                    let insert_voice_channel =
                        create_project_channel::CreateOneProjectChannel::execute(
                            small_group_project.project.project_id,
                            voice_channel.unwrap().id.to_string(),
                            ChannelType::DiscordVoice,
                        )
                        .await
                        .map_err(|err| {
                            error!(
                                "Could not insert project voice channel data to into database: {}",
                                err
                            );
                            err
                        });
                    // insert text channel data into database
                    let insert_text_channel =
                        create_project_channel::CreateOneProjectChannel::execute(
                            small_group_project.project.project_id,
                            text_channel.unwrap().id.to_string(),
                            ChannelType::DiscordText,
                        )
                        .await
                        .map_err(|err| {
                            error!(
                                "Could not insert project text channel data to into database: {}",
                                err
                            );
                            err
                        });
                    if let Err(err) = insert_voice_channel {
                        return Some(
                            interaction_error(
                                "Database Error",
                                "We could not insert voice channel for projects into database",
                                &err,
                                &ctx,
                                &interaction,
                            )
                            .await,
                        );
                    }
                    if let Err(err) = insert_text_channel {
                        return Some(
                            interaction_error(
                                "Database Error",
                                "We could not insert text channel for projects into database",
                                &err,
                                &ctx,
                                &interaction,
                            )
                            .await,
                        );
                    }
                }
            }
        }
    }
    return None;
}
async fn handle_generate_channels ( ctx : & Context , interaction : & ApplicationCommandInteraction , ) -> Option < SerenityResult < ( ) > > { // Create channel for small groups 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 , ) ; } // Get list of discord association information for small groups. let small_groups_associate_info = rcos_api_response . unwrap ( ) . small_groups ; for small_group in small_groups_associate_info { // Get parent channel(category) from data. let categories = small_group . small_group_categories ; // Get list of projects of small group. let small_group_projects = & small_group . small_group_projects ; for category in categories { // Create Voice and Text channel under small group category for small_group_project in small_group_projects { // Create channels for small group projects if not previously created. if small_group_project . project . project_channels . is_empty ( ) { // Generate permission for certain groups for the channel. let overwrite = if let None = small_group_project . project . project_role { generate_permission ( None , get_roles ( ctx ) . await ) } else { generate_permission ( Some ( RoleId ( small_group_project . project . project_role . as_ref ( ) . unwrap ( ) . role_id . parse :: < u64 > ( ) . unwrap ( ) , ) ) , get_roles ( ctx ) . await , ) } ; // Create voice channel. let voice_channel = GuildId ( global_config ( ) . discord_config . rcos_guild_id ( ) ) . create_channel ( & ctx . http , | c | { c . name ( & small_group_project . project . title ) . kind ( SerenityChannelType :: Voice ) . permissions ( overwrite . clone ( ) ) . category ( ChannelId ( category . category_id . parse :: < u64 > ( ) . unwrap ( ) ) ) } ) . await . map_err ( | err | { error ! ( " " err ) ; err } ) ; // Create text channel. let text_channel = GuildId ( global_config ( ) . discord_config . rcos_guild_id ( ) ) . create_channel ( & ctx . http , | c | { c . name ( & small_group_project . project . title ) . kind ( SerenityChannelType :: Text ) . permissions ( overwrite . clone ( ) ) . category ( ChannelId ( category . category_id . parse :: < u64 > ( ) . unwrap ( ) ) ) } ) . await . map_err ( | err | { error ! ( " " err ) ; err } ) ; if let Err ( err ) = voice_channel { return Some ( interaction_error ( " " , " " , & err , & ctx , & interaction , ) . await , ) ; } if let Err ( err ) = text_channel { return Some ( interaction_error ( " " , " " , & err , & ctx , & interaction , ) . await , ) ; } // insert voice channel data into database let insert_voice_channel = create_project_channel :: CreateOneProjectChannel :: execute ( small_group_project . project . project_id , voice_channel . unwrap ( ) . id . to_string ( ) , ChannelType :: DiscordVoice , ) . await . map_err ( | err | { error ! ( " " err ) ; err } ) ; // insert text channel data into database let insert_text_channel = create_project_channel :: CreateOneProjectChannel :: execute ( small_group_project . project . project_id , text_channel . unwrap ( ) . id . to_string ( ) , ChannelType :: DiscordText , ) . await . map_err ( | err | { error ! ( " " err ) ; err } ) ; if let Err ( err ) = insert_voice_channel { return Some ( interaction_error ( " " , " " , & err , & ctx , & interaction , ) . await , ) ; } if let Err ( err ) = insert_text_channel { return Some ( interaction_error ( " " , " " , & err , & ctx , & interaction , ) . await , ) ; } } } } } return None ; }
handler for /generate channel commands
handler for / generate channel commands
ctx
&Context
interaction
&ApplicationCommandInteraction
ctx
&Context
interaction
&ApplicationCommandInteraction