Updated bye functionality.
This commit is contained in:
@@ -1,16 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
[ -f functions.sh ] && source functions.sh
|
||||
# All names to match are completely lowercase.
|
||||
exitName="${1%% *}"
|
||||
|
||||
farewellsFile="triggers/bye/farewells.txt"
|
||||
|
||||
# All names to match are completely lowercase.
|
||||
case "${1,,}" in
|
||||
storm_dragon)
|
||||
msg "${2%% :*}" "NOOOOOOOOOO!!! $1: come back!!!"
|
||||
;;
|
||||
*)
|
||||
bye=(
|
||||
"Bye $1."
|
||||
"Alas $1, you will be missed."
|
||||
)
|
||||
msg "${2%% :*}" "${bye[$(($RANDOM % ${#bye[@]}))]}"
|
||||
# Read farewells from file into array
|
||||
if [[ -f "$farewellsFile" ]]; then
|
||||
mapfile -t farewell < "$farewellsFile"
|
||||
else
|
||||
# Fallback if file doesn't exist
|
||||
farewell=("Goodbye" "Farewell!")
|
||||
fi
|
||||
|
||||
# Replace placeholders with actual values
|
||||
selectedFarewell="${farewell[$((RANDOM % ${#farewell[@]}))]}"
|
||||
selectedFarewell="${selectedFarewell//\{channel\}/${2%% :*}}"
|
||||
|
||||
# Check if farewell contains {name} placeholder
|
||||
if [[ "$selectedFarewell" == *"{name}"* ]]; then
|
||||
# Replace {name} with actual name, don't add prefix
|
||||
selectedFarewell="${selectedFarewell//\{name\}/$1}"
|
||||
msg "${2%% :*}" "$selectedFarewell"
|
||||
else
|
||||
# No {name} placeholder, use traditional "name: farewell" format
|
||||
msg "${2%% :*}" "$1: $selectedFarewell"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
7
triggers/bye/farewells.txt.example
Normal file
7
triggers/bye/farewells.txt.example
Normal file
@@ -0,0 +1,7 @@
|
||||
Goodbye!
|
||||
Farewell {name}, until we meet again!
|
||||
Alas, you will be missed.
|
||||
See you later!
|
||||
Bye {name}!
|
||||
Safe travels from {channel}!
|
||||
Catch you later {name}!
|
||||
Reference in New Issue
Block a user