Skip to content

Commit

Permalink
Add an option to show unknown users ids, instead of "@unknown-user" (#65
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Noskcaj19 committed Sep 10, 2020
1 parent cb58ba8 commit 19cee5c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct InnerConfig {
pub token: Option<String>,
pub log_directive: String,
pub auto_open_tracing: bool,
pub show_unknown_user_ids: bool,
pub message_fetch_count: i32,
pub nick_prefix: String,
pub nick_prefix_color: String,
Expand All @@ -53,6 +54,7 @@ impl InnerConfig {
token: None,
log_directive: "".to_string(),
auto_open_tracing: false,
show_unknown_user_ids: false,
message_fetch_count: 50,
nick_prefix: "".to_string(),
nick_prefix_color: "".to_string(),
Expand Down Expand Up @@ -136,6 +138,21 @@ impl Config {
)
.expect("Unable to create tracing window option");

let inner_clone = Weak::clone(&inner);
sec.new_boolean_option(
BooleanOptionSettings::new("show_unknown_user_ids")
.description(
"Should unknown users be shown as @<user-id> instead of @unknown-user",
)
.set_change_callback(move |_, option| {
let inner = inner_clone
.upgrade()
.expect("Outer config has outlived inner config");
inner.borrow_mut().show_unknown_user_ids = option.value();
}),
)
.expect("Unable to create show unknown user ids option");

let inner_clone = Weak::clone(&inner);
sec.new_string_option(
StringOptionSettings::new("autojoin_private")
Expand Down Expand Up @@ -230,6 +247,10 @@ impl Config {
self.inner.borrow().auto_open_tracing
}

pub fn show_unknown_user_ids(&self) -> bool {
self.inner.borrow().show_unknown_user_ids
}

pub fn token(&self) -> Option<String> {
self.inner.borrow().token.clone()
}
Expand Down
1 change: 1 addition & 0 deletions src/message_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ fn render_msg(
cache,
msg.guild_id,
&msg.content,
config.show_unknown_user_ids(),
unknown_members,
);

Expand Down
10 changes: 8 additions & 2 deletions src/twilight_utils/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ pub fn clean_all(
cache: &Cache,
guild_id: Option<GuildId>,
input: &str,
show_unknown_ids: bool,
unknown_members: &mut Vec<UserId>,
) -> String {
let mut out = clean_roles(cache, input);
out = clean_channels(cache, &out);
out = clean_users(cache, guild_id, &out, unknown_members);
out = clean_users(cache, guild_id, &out, show_unknown_ids, unknown_members);
out = clean_emojis(cache, &out);
out
}
Expand Down Expand Up @@ -111,6 +112,7 @@ pub fn clean_users(
cache: &Cache,
guild_id: Option<GuildId>,
input: &str,
show_unknown_ids: bool,
unknown_members: &mut Vec<UserId>,
) -> String {
let mut out = String::from(input);
Expand Down Expand Up @@ -148,7 +150,11 @@ pub fn clean_users(
unknown_members.push(id);
out = out.replace(
user_match.get(0).expect("match must exist").as_str(),
"@unknown-user",
&if show_unknown_ids {
format!("@{}", id.0)
} else {
"@unknown-user".into()
},
);
}
}
Expand Down

0 comments on commit 19cee5c

Please sign in to comment.