feat(discord): dynamic embed color

This commit is contained in:
ibo 2024-06-25 06:29:10 +02:00 committed by GitHub
parent 665b558b1f
commit 2180086573
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -120,12 +120,22 @@ jobs:
avatar_url=$(echo "$user_details" | jq -r '.avatar_url') avatar_url=$(echo "$user_details" | jq -r '.avatar_url')
echo "$name|$login|$avatar_url" echo "$name|$login|$avatar_url"
} }
# Additional information for the goats # Additional information for the goats
declare -A additional_info declare -A additional_info
additional_info["ibo"]="\n Discord: <@951737931159187457>\n AniList: [takarealist112](<https://anilist.co/user/takarealist112/>)" additional_info["ibo"]="\n Discord: <@951737931159187457>\n AniList: [takarealist112](<https://anilist.co/user/takarealist112/>)"
additional_info["aayush262"]="\n Discord: <@918825160654598224>\n AniList: [aayush262](<https://anilist.co/user/aayush262/>)" additional_info["aayush262"]="\n Discord: <@918825160654598224>\n AniList: [aayush262](<https://anilist.co/user/aayush262/>)"
additional_info["rebelonion"]="\n Discord: <@714249925248024617>\n AniList: [rebelonion](<https://anilist.co/user/rebelonion/>)\n PornHub: [rebelonion](<https://www.cornhub.com/model/rebelonion>)" additional_info["rebelonion"]="\n Discord: <@714249925248024617>\n AniList: [rebelonion](<https://anilist.co/user/rebelonion/>)\n PornHub: [rebelonion](<https://www.cornhub.com/model/rebelonion>)"
# Decimal color codes for contributors
declare -A contributor_colors
default_color="#ff25f9"
contributor_colors["ibo"]="#ff7500"
contributor_colors["aayush262"]="#5d689d"
contributor_colors["Sadwhy"]="#ff7e95"
contributor_colors["rebelonion"]="#d4e5ed"
hex_to_decimal() { printf '%d' "0x${1#"#"}"; }
# Count recent commits and create an associative array # Count recent commits and create an associative array
declare -A recent_commit_counts declare -A recent_commit_counts
while read -r count name; do while read -r count name; do
@ -150,6 +160,7 @@ jobs:
top_contributor="" top_contributor=""
top_contributor_count=0 top_contributor_count=0
top_contributor_avatar="" top_contributor_avatar=""
embed_color=$default_color
# Process contributors in the new order # Process contributors in the new order
while read -r login; do while read -r login; do
@ -164,11 +175,14 @@ jobs:
# Update top contributor information # Update top contributor information
if [ $commit_count -gt $max_commits ]; then if [ $commit_count -gt $max_commits ]; then
max_commits=$commit_count max_commits=$commit_count
top_contributor="$login" top_contributors=("$login")
top_contributor_count=1 top_contributor_count=1
top_contributor_avatar="$avatar_url" top_contributor_avatar="$avatar_url"
embed_color=$(hex_to_decimal "${contributor_colors[$name]:-$default_color}")
elif [ $commit_count -eq $max_commits ]; then elif [ $commit_count -eq $max_commits ]; then
top_contributors+=("$login")
top_contributor_count=$((top_contributor_count + 1)) top_contributor_count=$((top_contributor_count + 1))
embed_color=$default_color
fi fi
# Get commit count for this contributor on the dev branch # Get commit count for this contributor on the dev branch
@ -191,16 +205,16 @@ jobs:
else else
developers="${developer_entry}" developers="${developer_entry}"
fi fi
committers_count=$((committers_count + 1)) committers_count=$((committers_count + 1))
fi fi
done <<< "$sorted_contributors" done <<< "$sorted_contributors"
# Set the thumbnail URL based on top contributor(s) # Set the thumbnail URL and color based on top contributor(s)
if [ $top_contributor_count -eq 1 ]; then if [ $top_contributor_count -eq 1 ]; then
thumbnail_url="$top_contributor_avatar" thumbnail_url="$top_contributor_avatar"
else else
thumbnail_url="https://i.imgur.com/5o3Y9Jb.gif" thumbnail_url="https://i.imgur.com/5o3Y9Jb.gif"
embed_color=$default_color
fi fi
# Truncate field values # Truncate field values
@ -220,12 +234,13 @@ jobs:
--arg footer_text "Version $VERSION" \ --arg footer_text "Version $VERSION" \
--arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" \ --arg timestamp "$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" \
--arg thumbnail_url "$thumbnail_url" \ --arg thumbnail_url "$thumbnail_url" \
--argjson embed_color "$embed_color" \
'{ '{
"content": "<@&1225347048321191996>", "content": "<@&1225347048321191996>",
"embeds": [ "embeds": [
{ {
"title": "New Alpha-Build dropped", "title": "New Alpha-Build dropped",
"color": 15532323, "color": $embed_color,
"fields": [ "fields": [
{ {
"name": "Commits:", "name": "Commits:",