fn server(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
    let guild_id = if !args.is_empty() {
        GuildId(args.single::<u64>()?)
    } else if let Some(gid) = msg.guild_id {
        gid
    } else {
        msg.channel_id.say(
            &ctx.http,
            "I was unable to get the current guild id, try again later.",
        )?;
        return Ok(());
    };
    let guild = guild_id
        .to_guild_cached(&ctx)
        .ok_or("No server with this Guild ID can be found")?
        .read()
        .clone();
    let roles: String = {
        let role_hash = &guild.roles;
        let mut role_id_list = String::new();
        let mut role_vec: Vec<_> = role_hash
            .iter()
            .filter(|(_role_id, role)| !role.managed)
            .collect();
        // This sorts the vector by position, in reverse order. (so @@everyone is the last item)
        role_vec.sort_unstable_by(|(_role_id_a, role_a), (_role_id_b, role_b)| {
            role_a
                .position
                .partial_cmp(&role_b.position)
                .unwrap()
                .reverse()
        });
        if role_vec.len() < 60 {
            for (role_id, _role) in role_vec.iter() {
                role_id_list.push_str(format!("<@&{}> ", role_id.as_u64()).as_ref())
            }
        } else {
            // Take will panic if there isn't as many items in a iter as
            // the number you try to take, therefore it can only be done when the
            // the items we're itering over is known to be equal to or above the amount
            // we're trying to take
            for (role_id, _role) in role_vec.iter().take(60) {
                role_id_list.push_str(format!("<@&{}> ", role_id.as_u64()).as_ref())
            }
            role_id_list.push_str("*Unable to show all roles.*");
        }
        role_id_list
    };

    msg.channel_id
        .send_message(&ctx, move |m| {
            m.embed(move |e| {
                e.author(|a| a.name(&guild.name));
                if let Some(guild_icon) = &guild.icon_url() {
                    e.thumbnail(guild_icon);
                };
                e.field("Owner", format!("<@{}>", &guild.owner_id.as_u64()), true);
                e.field("Guild ID", format!("{}", guild_id), true);
                e.field("Members", guild.member_count, true);
                e.field(
                    "Guild created on",
                    guild_id
                        .created_at()
                        .format("%A, %d %B %Y \n%H:%M:%S UTC")
                        .to_string(),
                    true,
                );
                e.field("Region", &guild.region, true);
                e.field("Emojis", &guild.emojis.len(), true);
                e.field("Channels", guild.channels.len(), true);
                if !guild.features.is_empty() {
                    e.field("Features", guild.features.join(", "), true);
                }
                e.field(
                    "Nitro Boost Level",
                    format!("{:?}", guild.premium_tier),
                    true,
                );
                e.field("Nitro Boosts", guild.premium_subscription_count, true);
                e.description(format!("**Role list:** \n{}", roles));
                if let Some(splash) = guild.splash_url() {
                    e.image(splash);
                }
                if let Some(description) = guild.description {
                    e.description(description);
                }
                e.timestamp(msg.timestamp.to_rfc3339());
                e.footer(|f| {
                    f.text(format!("Requested by {}", msg.author.tag()));
                    f.icon_url(msg.author.face());
                    f
                });
                e
            })
        })
        .map_or_else(|e| Err(CommandError(e.to_string())), |_| Ok(()))
}
/// Shows various information about a guild.
Shows various information about a guild.
Shows various information about a guild .
fn server(ctx: &mut Context, msg: &Message, mut args: Args) -> CommandResult {
    let guild_id = if !args.is_empty() {
        GuildId(args.single::<u64>()?)
    } else if let Some(gid) = msg.guild_id {
        gid
    } else {
        msg.channel_id.say(
            &ctx.http,
            "I was unable to get the current guild id, try again later.",
        )?;
        return Ok(());
    };
    let guild = guild_id
        .to_guild_cached(&ctx)
        .ok_or("No server with this Guild ID can be found")?
        .read()
        .clone();
    let roles: String = {
        let role_hash = &guild.roles;
        let mut role_id_list = String::new();
        let mut role_vec: Vec<_> = role_hash
            .iter()
            .filter(|(_role_id, role)| !role.managed)
            .collect();
        // This sorts the vector by position, in reverse order. (so @@everyone is the last item)
        role_vec.sort_unstable_by(|(_role_id_a, role_a), (_role_id_b, role_b)| {
            role_a
                .position
                .partial_cmp(&role_b.position)
                .unwrap()
                .reverse()
        });
        if role_vec.len() < 60 {
            for (role_id, _role) in role_vec.iter() {
                role_id_list.push_str(format!("<@&{}> ", role_id.as_u64()).as_ref())
            }
        } else {
            // Take will panic if there isn't as many items in a iter as
            // the number you try to take, therefore it can only be done when the
            // the items we're itering over is known to be equal to or above the amount
            // we're trying to take
            for (role_id, _role) in role_vec.iter().take(60) {
                role_id_list.push_str(format!("<@&{}> ", role_id.as_u64()).as_ref())
            }
            role_id_list.push_str("*Unable to show all roles.*");
        }
        role_id_list
    };
    msg.channel_id
        .send_message(&ctx, move |m| {
            m.embed(move |e| {
                e.author(|a| a.name(&guild.name));
                if let Some(guild_icon) = &guild.icon_url() {
                    e.thumbnail(guild_icon);
                };
                e.field("Owner", format!("<@{}>", &guild.owner_id.as_u64()), true);
                e.field("Guild ID", format!("{}", guild_id), true);
                e.field("Members", guild.member_count, true);
                e.field(
                    "Guild created on",
                    guild_id
                        .created_at()
                        .format("%A, %d %B %Y \n%H:%M:%S UTC")
                        .to_string(),
                    true,
                );
                e.field("Region", &guild.region, true);
                e.field("Emojis", &guild.emojis.len(), true);
                e.field("Channels", guild.channels.len(), true);
                if !guild.features.is_empty() {
                    e.field("Features", guild.features.join(", "), true);
                }
                e.field(
                    "Nitro Boost Level",
                    format!("{:?}", guild.premium_tier),
                    true,
                );
                e.field("Nitro Boosts", guild.premium_subscription_count, true);
                e.description(format!("**Role list:** \n{}", roles));
                if let Some(splash) = guild.splash_url() {
                    e.image(splash);
                }
                if let Some(description) = guild.description {
                    e.description(description);
                }
                e.timestamp(msg.timestamp.to_rfc3339());
                e.footer(|f| {
                    f.text(format!("Requested by {}", msg.author.tag()));
                    f.icon_url(msg.author.face());
                    f
                });
                e
            })
        })
        .map_or_else(|e| Err(CommandError(e.to_string())), |_| Ok(()))
}
fn server ( ctx : & mut Context , msg : & Message , mut args : Args ) -> CommandResult { let guild_id = if ! args . is_empty ( ) { GuildId ( args . single :: < u64 > ( ) ? ) } else if let Some ( gid ) = msg . guild_id { gid } else { msg . channel_id . say ( & ctx . http , " " , ) ? ; return Ok ( ( ) ) ; } ; let guild = guild_id . to_guild_cached ( & ctx ) . ok_or ( " " ) ? . read ( ) . clone ( ) ; let roles : String = { let role_hash = & guild . roles ; let mut role_id_list = String :: new ( ) ; let mut role_vec : Vec < _ > = role_hash . iter ( ) . filter ( | ( _role_id , role ) | ! role . managed ) . collect ( ) ; // This sorts the vector by position, in reverse order. (so @@everyone is the last item) role_vec . sort_unstable_by ( | ( _role_id_a , role_a ) , ( _role_id_b , role_b ) | { role_a . position . partial_cmp ( & role_b . position ) . unwrap ( ) . reverse ( ) } ) ; if role_vec . len ( ) < 60 { for ( role_id , _role ) in role_vec . iter ( ) { role_id_list . push_str ( format ! ( " " role_id as_u64 ( ) ) . as_ref ( ) ) } } else { // Take will panic if there isn't as many items in a iter as // the number you try to take, therefore it can only be done when the // the items we're itering over is known to be equal to or above the amount // we're trying to take for ( role_id , _role ) in role_vec . iter ( ) . take ( 60 ) { role_id_list . push_str ( format ! ( " " role_id as_u64 ( ) ) . as_ref ( ) ) } role_id_list . push_str ( " " ) ; } role_id_list } ; msg . channel_id . send_message ( & ctx , move | m | { m . embed ( move | e | { e . author ( | a | a . name ( & guild . name ) ) ; if let Some ( guild_icon ) = & guild . icon_url ( ) { e . thumbnail ( guild_icon ) ; } ; e . field ( " " , format ! ( " " guild owner_id as_u64 ( ) ) , true ) ; e . field ( " " , format ! ( " " guild_id ) , true ) ; e . field ( " " , guild . member_count , true ) ; e . field ( " " , guild_id . created_at ( ) . format ( " \n " ) . to_string ( ) , true , ) ; e . field ( " " , & guild . region , true ) ; e . field ( " " , & guild . emojis . len ( ) , true ) ; e . field ( " " , guild . channels . len ( ) , true ) ; if ! guild . features . is_empty ( ) { e . field ( " " , guild . features . join ( " " ) , true ) ; } e . field ( " " , format ! ( " " guild premium_tier ) , true , ) ; e . field ( " " , guild . premium_subscription_count , true ) ; e . description ( format ! ( " \n " roles ) ) ; if let Some ( splash ) = guild . splash_url ( ) { e . image ( splash ) ; } if let Some ( description ) = guild . description { e . description ( description ) ; } e . timestamp ( msg . timestamp . to_rfc3339 ( ) ) ; e . footer ( | f | { f . text ( format ! ( " " msg author tag ( ) ) ) ; f . icon_url ( msg . author . face ( ) ) ; f } ) ; e } ) } ) . map_or_else ( | e | Err ( CommandError ( e . to_string ( ) ) ) , | _ | Ok ( ( ) ) ) }
Shows various information about a guild.
Shows various information about a guild .
ctx
&mut Context
msg
&Message
args
Args
ctx
&mut Context
msg
&Message
args
Args