Skip to content

Commit ba560df

Browse files
committed
refactor: update parse_user_status to return both symbol and text representation
1 parent 33bb4af commit ba560df

File tree

4 files changed

+11
-21
lines changed

4 files changed

+11
-21
lines changed

src/commands/user/memberlist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ async fn format_to_list(member_list: &[String], fmt_color: &str) -> String {
2727
};
2828

2929
let status_raw = *STATUS.read().await.get_by_name(user.username.as_str());
30-
let status = parse_user_status(status_raw, false);
30+
let status_symbol = parse_user_status(status_raw).0;
3131

32-
format!("{C_RESET}{status}{fmt_color} {username} {badge}")
32+
format!("{C_RESET}{status_symbol}{fmt_color} {username} {badge}")
3333
}
3434
});
3535

src/commands/user/status.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn status() -> commands::Command {
1111
async fn logic(ctx: &commands::Context) -> commands::CommandResponse {
1212
if ctx.args.is_empty() {
1313
let status = *STATUS.read().await.get_by_name(ctx.executor.username.as_str());
14-
return Ok(Some(format!("{BOLD}{GREEN}Your current status: {C_RESET}{}", parse_user_status(status, true))))
14+
return Ok(Some(format!("{BOLD}{GREEN}Your current status: {C_RESET}{}", parse_user_status(status).1)))
1515
}
1616

1717
let arg_status = &ctx.args[0];
@@ -25,7 +25,7 @@ pub fn status() -> commands::Command {
2525

2626
STATUS.write().await.append(ctx.executor.username.as_str(), status);
2727

28-
Ok(Some(format!("{BOLD}{GREEN}Changed your status to {C_RESET}{}", parse_user_status(status, true))))
28+
Ok(Some(format!("{BOLD}{GREEN}Changed your status to {C_RESET}{}", parse_user_status(status).1)))
2929
}
3030

3131
commands::Command {

src/commands/user/userinfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn userinfo() -> commands::Command {
6262
let date = DateTime::from_timestamp(i64::from(user.creation_date), 0).unwrap();
6363

6464
let status_raw = *STATUS.read().await.get_by_name(user.username.as_str());
65-
let status = parse_user_status(status_raw, false);
65+
let status = parse_user_status(status_raw).0;
6666

6767
let message = format!(
6868
"

src/utilities.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,12 @@ pub fn create_badge_list(row: &str) -> String {
123123
})
124124
}
125125

126-
pub fn parse_user_status(status: Status, with_text: bool) -> String {
127-
if with_text {
128-
match status {
129-
Status::Online => format!("{GREEN}Online (🟢){C_RESET}"),
130-
Status::Afk => format!("{YELLOW}Afk (🌙){C_RESET}"),
131-
Status::DoNotDisturb => format!("{RED}Do not disturb (🔴){C_RESET}"),
132-
Status::Offline => format!("{GRAY}{BOLD}Offline (〇){C_RESET}")
133-
}
134-
}
135-
else {
136-
match status {
137-
Status::Online => format!("{GREEN}🟢{C_RESET}"),
138-
Status::Afk => format!("{YELLOW}🌙{C_RESET}"),
139-
Status::DoNotDisturb => format!("{RED}🔴{C_RESET}"),
140-
Status::Offline => format!("{GRAY}{BOLD}〇{C_RESET}")
141-
}
126+
pub fn parse_user_status(status: Status) -> (String, String) {
127+
match status {
128+
Status::Online => (format!("{GREEN}🟢{C_RESET}"), format!("{GREEN}Online (🟢){C_RESET}")),
129+
Status::Afk => (format!("{YELLOW}🌙{C_RESET}"), format!("{YELLOW}Afk (🌙){C_RESET}")),
130+
Status::DoNotDisturb => (format!("{RED}🔴{C_RESET}"), format!("{RED}Do not disturb (🔴){C_RESET}")),
131+
Status::Offline => (format!("{GRAY}{BOLD}〇{C_RESET}"), format!("{GRAY}{BOLD}Offline (〇){C_RESET}"))
142132
}
143133
}
144134

0 commit comments

Comments
 (0)