Skip to content

Commit

Permalink
Added hide_usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
tapnisu committed Feb 19, 2024
1 parent e06f943 commit 45004bb
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions assets/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ muted_channels_ids: []

allowed_users_ids: []
muted_users_ids: []

hide_usernames: false
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ fn empty_ids_vec() -> Vec<u64> {
vec![]
}

fn default_false() -> bool {
false
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Config {
pub discord_token: Option<String>,
Expand All @@ -27,6 +31,9 @@ pub struct Config {
pub allowed_users_ids: Vec<u64>,
#[serde(default = "empty_ids_vec")]
pub muted_users_ids: Vec<u64>,

#[serde(default = "default_false")]
pub hide_usernames: bool,
}

pub fn parse_config(path: String) -> Config {
Expand Down
4 changes: 3 additions & 1 deletion src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub struct Handler {

pub allowed_users_ids: Vec<u64>,
pub muted_users_ids: Vec<u64>,

pub hide_usernames: bool,
}

#[async_trait]
Expand All @@ -42,7 +44,7 @@ impl EventHandler for Handler {
}

self.bot
.send_message(self.output_chat_id.clone(), format_message(ctx, msg).await)
.send_message(self.output_chat_id.clone(), format_message(ctx, msg, self.hide_usernames).await)
.parse_mode(ParseMode::MarkdownV2)
.await
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async fn main() {
muted_channels_ids: config.muted_channels_ids,
allowed_users_ids: config.allowed_users_ids,
muted_users_ids: config.muted_users_ids,
hide_usernames: config.hide_usernames,
})
.await;

Expand Down
10 changes: 9 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ pub fn escape_markdownv2(text: &str) -> String {
.collect()
}

pub async fn format_message(ctx: Context, msg: Message) -> String {
pub async fn format_message(ctx: Context, msg: Message, hide_username: bool) -> String {
if hide_username {
return format!(
"{}\n{}",
escape_markdownv2(&msg.content_safe(ctx.cache)),
msg.embeds.into_iter().map(format_embed).collect::<String>()
);
}

let author_part = if msg.is_private() {
escape_markdownv2(&msg.author.tag())
} else {
Expand Down

0 comments on commit 45004bb

Please sign in to comment.