Skip to content

Commit

Permalink
feat: hash action too
Browse files Browse the repository at this point in the history
  • Loading branch information
backwardspy committed Sep 18, 2024
1 parent cca0a32 commit 54309a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "catppuccin-rockdove"
version = "0.12.0"
version = "0.13.0"
edition = "2021"
repository = "https://github.com/catppuccin/rockdove"

Expand Down
12 changes: 9 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const MAX_TITLE_LENGTH: usize = 100;
const MAX_DESCRIPTION_LENGTH: usize = 640;
const MAX_AUTHOR_NAME_LENGTH: usize = 256;

const BANNED_ACCENTS: [catppuccin::ColorName; 2] = [
catppuccin::ColorName::Rosewater, // NO DOGWATER
catppuccin::ColorName::Flamingo, // NO FRICKIN BIRDS
];

#[derive(serde::Deserialize)]
struct Config {
github_webhook_secret: String,
Expand Down Expand Up @@ -313,7 +318,7 @@ fn limit_text_length(text: &str, max_length: usize) -> String {
fn make_discord_message(event_type: &str, e: &Event) -> anyhow::Result<Option<serde_json::Value>> {
let mut embed = EmbedBuilder::default();

embed.color(pick_color(event_type));
embed.color(pick_color(event_type, &e.action));
embed.author(e.sender.clone());

let display_action = e.action.replace('_', " ");
Expand Down Expand Up @@ -469,16 +474,17 @@ fn make_discord_message(event_type: &str, e: &Event) -> anyhow::Result<Option<se
Ok(Some(embed.try_build()?))
}

fn pick_color(event_type: &str) -> catppuccin::Color {
fn pick_color(event_type: &str, action: &str) -> catppuccin::Color {
let options = catppuccin::PALETTE
.mocha
.colors
.iter()
.filter(|c| c.accent)
.filter(|c| c.accent && !BANNED_ACCENTS.contains(&c.name))
.collect::<Vec<_>>();

let mut hasher = DefaultHasher::new();
event_type.hash(&mut hasher);
action.hash(&mut hasher);
let hash = hasher.finish();

#[allow(clippy::cast_possible_truncation)]
Expand Down

0 comments on commit 54309a5

Please sign in to comment.