mirror of
https://github.com/dsec-hub/dsec-discord-bot.git
synced 2026-09-22 15:53:56 +00:00
updated server info command
This commit is contained in:
parent
d693725d2d
commit
d0a4430b57
1 changed files with 41 additions and 34 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
use poise::CreateReply;
|
use poise::CreateReply;
|
||||||
use serenity::all::{Colour, CreateEmbed, GuildId, User};
|
use serenity::all::{ChannelType, Colour, CreateEmbed, CreateEmbedFooter, GuildId, User};
|
||||||
|
|
||||||
use crate::{Context, Error};
|
use crate::{Context, Error};
|
||||||
use std::time::Instant;
|
use std::{collections::HashMap, time::Instant};
|
||||||
|
|
||||||
/// Show this help menu
|
/// Show this help menu
|
||||||
#[poise::command(track_edits, slash_command)]
|
#[poise::command(track_edits, slash_command)]
|
||||||
|
|
@ -123,53 +123,60 @@ pub async fn serverinfo(ctx: Context<'_>) -> Result<(), Error> {
|
||||||
guild.as_deref().unwrap().member_count
|
guild.as_deref().unwrap().member_count
|
||||||
};
|
};
|
||||||
|
|
||||||
let server_description_option = &partial_guild.description;
|
// count different types of channels
|
||||||
|
let channels_hashmap = partial_guild.clone().channels(ctx).await?;
|
||||||
|
|
||||||
|
let guild_channels = channels_hashmap.into_values();
|
||||||
|
|
||||||
|
let mut counts: HashMap<ChannelType, u32> = HashMap::new();
|
||||||
|
|
||||||
|
for channel in guild_channels {
|
||||||
|
let kind = match channel.kind {
|
||||||
|
ChannelType::Category => ChannelType::Category,
|
||||||
|
ChannelType::Text => ChannelType::Text,
|
||||||
|
ChannelType::Voice => ChannelType::Voice,
|
||||||
|
_ => ChannelType::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
*counts.entry(kind).or_insert(0) += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let category_channel_count = counts.get(&ChannelType::Category).unwrap_or(&0);
|
||||||
|
let text_channel_count = counts.get(&ChannelType::Text).unwrap_or(&0);
|
||||||
|
let voice_channel_count = counts.get(&ChannelType::Voice).unwrap_or(&0);
|
||||||
|
|
||||||
let server_id = &partial_guild.id;
|
let server_id = &partial_guild.id;
|
||||||
let server_name = &partial_guild.name;
|
let server_name = &partial_guild.name;
|
||||||
// let no_of_members = &discord_server.approximate_member_count.unwrap();
|
|
||||||
let owner_id = &partial_guild.owner_id;
|
let owner_id = &partial_guild.owner_id;
|
||||||
|
|
||||||
|
let server_description_option = &partial_guild.description;
|
||||||
let server_description = server_description_option.as_deref().unwrap_or("N/A");
|
let server_description = server_description_option.as_deref().unwrap_or("N/A");
|
||||||
|
|
||||||
let server_icon = &partial_guild.icon_url().unwrap_or_default();
|
let server_icon = &partial_guild.icon_url().unwrap_or_default();
|
||||||
|
|
||||||
let roles: &Vec<String> = &partial_guild
|
let rules_channel = if (&partial_guild.rules_channel_id).is_none() {
|
||||||
.roles
|
|
||||||
.into_keys()
|
|
||||||
.filter(|role_id| format!("{}", role_id) != format!("{}", server_id))
|
|
||||||
.map(|role_id| format!("<@&{}>", role_id))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let rules_channel_id = &partial_guild.rules_channel_id;
|
|
||||||
|
|
||||||
let rules_channel = if rules_channel_id.is_none() {
|
|
||||||
"N/A"
|
"N/A"
|
||||||
} else {
|
} else {
|
||||||
&format!("<#{}>", rules_channel_id.unwrap())
|
&format!("<#{}>", &partial_guild.rules_channel_id.unwrap())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let embed_footer = CreateEmbedFooter::new(format!("ID: {}", server_id));
|
||||||
|
|
||||||
let result_embed_msg = CreateEmbed::new()
|
let result_embed_msg = CreateEmbed::new()
|
||||||
.thumbnail(server_icon)
|
.thumbnail(server_icon)
|
||||||
.title("Server Info")
|
.title(server_name)
|
||||||
.description(format!(
|
.field("Owner", format!("<@{}>", owner_id), true)
|
||||||
"
|
.field("Rules", rules_channel, true)
|
||||||
**Name**: {}\n\
|
.field("Members", format!("{}", member_count), true)
|
||||||
**ID**: {}\n\
|
.field(
|
||||||
**Owner**: <@{}>\n\
|
"Category Channels",
|
||||||
**Description**: {}\n\
|
format!("{}", category_channel_count),
|
||||||
**Rules Channel**: {}\n\
|
true,
|
||||||
**No. of Members**: {}\n\
|
)
|
||||||
**Roles**: {}
|
.field("Text Channels", format!("{}", text_channel_count), true)
|
||||||
",
|
.field("Voice Channels", format!("{}", voice_channel_count), true)
|
||||||
server_id,
|
.field("Description", server_description, false)
|
||||||
server_name,
|
.footer(embed_footer)
|
||||||
owner_id,
|
|
||||||
server_description,
|
|
||||||
rules_channel,
|
|
||||||
member_count,
|
|
||||||
roles.join(" ")
|
|
||||||
))
|
|
||||||
.color(embed_color);
|
.color(embed_color);
|
||||||
|
|
||||||
ctx.send(CreateReply::default().embed(result_embed_msg))
|
ctx.send(CreateReply::default().embed(result_embed_msg))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue