Skip to content

Commit

Permalink
Merge pull request #1302 from HTGAzureX1212/nightly
Browse files Browse the repository at this point in the history
``/info server`: Add Role Count
  • Loading branch information
HTGAzureX1212 authored Aug 10, 2023
2 parents d86e2c5 + 6b8b352 commit cd33acd
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api-backend/hartex-backend-routes-v1/src/bors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub async fn v1_repositories_repository_permissions_permissions(
) -> (Status, Value) {
log::trace!("attempting to retrieve permissions data");
let result = File::open(format!(
"./backend-data/bors.{}.permissions.{}",
"../backend-data/bors.{}.permissions.{}",
repository.to_lowercase(),
permission.to_lowercase()
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use hartex_discord_core::discord::util::snowflake::Snowflake;
use hartex_discord_entitycache_core::traits::Repository;
use hartex_discord_entitycache_repositories::guild::CachedGuildRepository;
use hartex_discord_entitycache_repositories::member::CachedMemberRepository;
use hartex_discord_entitycache_repositories::role::CachedRoleRepository;
use hartex_discord_entitycache_repositories::user::CachedUserRepository;
use hartex_discord_utils::markdown::MarkdownStyle;
use hartex_discord_utils::CLIENT;
Expand Down Expand Up @@ -107,6 +108,10 @@ pub async fn execute(interaction: Interaction, option: CommandDataOption) -> mie
handle_errors(errors)?;
bundle_get!(bundle."serverinfo-embed-memberinfo-botcount-subfield-name": message, out [serverinfo_embed_memberinfo_botcount_subfield_name, errors]);
handle_errors(errors)?;
bundle_get!(bundle."serverinfo-embed-roleinfo-field-name": message, out [serverinfo_embed_roleinfo_field_name, errors]);
handle_errors(errors)?;
bundle_get!(bundle."serverinfo-embed-roleinfo-rolecount-subfield-name": message, out [serverinfo_embed_roleinfo_rolecount_subfield_name, errors]);
handle_errors(errors)?;

let mut default_general_information = format!(
"{} {}\n{} {}\n{} {}",
Expand Down Expand Up @@ -180,6 +185,10 @@ pub async fn execute(interaction: Interaction, option: CommandDataOption) -> mie
));
}

let roles = CachedRoleRepository
.role_ids_in_guild(guild.id)
.into_diagnostic()?;

let embed = EmbedBuilder::new()
.color(0x41_A0_DE)
.field(EmbedFieldBuilder::new(
Expand Down Expand Up @@ -230,6 +239,14 @@ pub async fn execute(interaction: Interaction, option: CommandDataOption) -> mie
)
.inline(),
)
.field(EmbedFieldBuilder::new(
format!("<:role:1139004530277765211> {serverinfo_embed_roleinfo_field_name}"),
format!(
"{} {}",
serverinfo_embed_roleinfo_rolecount_subfield_name,
roles.len(),
),
))
.thumbnail(
ImageSource::url(Cdn::guild_icon(guild.id, guild.icon.unwrap())).into_diagnostic()?,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ pub struct CachedRoleRepository;
impl CachedRoleRepository {
#[allow(clippy::missing_errors_doc)]
#[allow(clippy::missing_panics_doc)]
pub fn role_ids_in_guild(
&self,
guild_id: Id<GuildMarker>,
) -> CacheResult<Vec<Id<RoleMarker>>> {
pub fn role_ids_in_guild(&self, guild_id: Id<GuildMarker>) -> CacheResult<Vec<Id<RoleMarker>>> {
let pass = env::var("DOCKER_REDIS_REQUIREPASS")?;
let client = Client::open(format!("redis://:{pass}@127.0.0.1/"))?;
let mut sync_connection = client.get_connection()?;
Expand All @@ -58,7 +55,7 @@ impl CachedRoleRepository {
Ok(keys
.iter()
.map(|key| {
let (_, role_id): (u64, u64) = scan!("guild_:{}:role:{}:name" <- key).unwrap();
let (_, role_id): (u64, u64) = scan!("guild:{}:role:{}:name" <- key).unwrap();

Id::new_checked(role_id).expect("unreachable")
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
# with HarTex. If not, see <https://www.gnu.org/licenses/>.
#

botinfo-embed-title=Runtime Information
botinfo-embed-botstarted-field-name=Bot Started
botinfo-embed-latency-field-name=Latency (Milliseconds)
serverinfo-embed-generalinfo-field-name=General Information
serverinfo-embed-generalinfo-id-subfield-name=ID:
serverinfo-embed-generalinfo-created-subfield-name=Created:
Expand All @@ -36,6 +39,5 @@ serverinfo-embed-memberinfo-field-name=Member Information
serverinfo-embed-memberinfo-membercount-subfield-name=Member Count:
serverinfo-embed-memberinfo-humancount-subfield-name=Human Count:
serverinfo-embed-memberinfo-botcount-subfield-name=Bot Count:
botinfo-embed-title=Runtime Information
botinfo-embed-botstarted-field-name=Bot Started
botinfo-embed-latency-field-name=Latency (Milliseconds)
serverinfo-embed-roleinfo-field-name=Role Information
serverinfo-embed-roleinfo-rolecount-subfield-name=Role Count:
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# You should have received a copy of the GNU Affero General Public License along
# with HarTex. If not, see <https://www.gnu.org/licenses/>.
#

about-embed-description=HarTex 是一款开源且轻量的服务器管理机器人,为有复杂需求与大量机器人配置的社区服务器量身定制
about-embed-footer=遇到问题?加入我们的社区服务器:{$inviteLink}.
about-embed-github-repo-field-name=GitHub 项目地址:
Expand All @@ -29,6 +30,3 @@ contributors-embed-global-admin-field-name=全局管理员 & 首席开发人员
contributors-embed-front-dev-field-name=前端开发人员
contributors-embed-translation-team-field-name=翻译组
contributors-embed-footer=这并不是一个完整的名单(保留更多的屏幕空间)但感谢所有的贡献者!
-latency-initial-response = 您需要什么吗?
latency-edited-response = {-latency-initial-response} 哦,我的延迟为:`{$latency}毫秒`.
uptime-response={$component} 在 <t:{$timestamp}:R> 启动.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
# with HarTex. If not, see <https://www.gnu.org/licenses/>.
#

botinfo-embed-title=运行时信息
botinfo-embed-botstarted-field-name=机器人已启动
botinfo-embed-latency-field-name=延迟(毫秒)
serverinfo-embed-generalinfo-field-name=常规信息
serverinfo-embed-generalinfo-id-subfield-name=ID:
serverinfo-embed-generalinfo-created-subfield-name=创建:
Expand All @@ -35,7 +38,4 @@ serverinfo-embed-channelinfo-forumchannels-subfield-name=论坛频道:
serverinfo-embed-memberinfo-field-name=成员信息
serverinfo-embed-memberinfo-membercount-subfield-name=成员数量:
serverinfo-embed-memberinfo-humancount-subfield-name=人类数量:
serverinfo-embed-memberinfo-botcount-subfield-name=机器人数量:
botinfo-embed-title=运行时信息
botinfo-embed-botstarted-field-name=机器人已启动
botinfo-embed-latency-field-name=延迟(毫秒)
serverinfo-embed-memberinfo-botcount-subfield-name=机器人数量:
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
# with HarTex. If not, see <https://www.gnu.org/licenses/>.
#

botinfo-embed-title=運行資訊
botinfo-embed-botstarted-field-name=機器人已啟動
botinfo-embed-latency-field-name=延遲(毫秒)
serverinfo-embed-generalinfo-field-name=一般資訊
serverinfo-embed-generalinfo-id-subfield-name=ID:
serverinfo-embed-generalinfo-created-subfield-name=創建於:
Expand All @@ -36,6 +39,3 @@ serverinfo-embed-memberinfo-field-name=成員資訊
serverinfo-embed-memberinfo-membercount-subfield-name=成員數:
serverinfo-embed-memberinfo-humancount-subfield-name=真人數:
serverinfo-embed-memberinfo-botcount-subfield-name=機器人數:
botinfo-embed-title=運行資訊
botinfo-embed-botstarted-field-name=機器人已啟動
botinfo-embed-latency-field-name=延遲(毫秒)

0 comments on commit cd33acd

Please sign in to comment.