Added optional random percent for bot to not respond on keywords.
This commit is contained in:
@@ -10,8 +10,9 @@ shift
|
|||||||
# each word is stored in an associative array, with the actions to be taken as the array's contents.
|
# each word is stored in an associative array, with the actions to be taken as the array's contents.
|
||||||
# the variable $chan contains the channel that caused the trigger.
|
# the variable $chan contains the channel that caused the trigger.
|
||||||
# the variable $who contains the nick that caused the trigger.
|
# the variable $who contains the nick that caused the trigger.
|
||||||
|
# Optional: Add a percentage (e.g., "50%") as the last element to respond only that percent of the time.
|
||||||
declare -A keywords
|
declare -A keywords
|
||||||
keywords[linux]="msg \"$chan\" \"Linux is $(shuf -n1 -e awesome God great lovely fantastic amazing wonderful)!\""
|
keywords[linux]="msg \"$chan\" \"Linux is $(shuf -n1 -e awesome God great lovely fantastic amazing wonderful)!\" 25%"
|
||||||
keywords[windows]="msg \"$chan\" \"$(shuf -n1 -e\
|
keywords[windows]="msg \"$chan\" \"$(shuf -n1 -e\
|
||||||
"Failure is not an option, it comes bundled with Windows!"\
|
"Failure is not an option, it comes bundled with Windows!"\
|
||||||
"Apple got all pissed off because I farted in their store. It's not my falt they don't have Windows..."\
|
"Apple got all pissed off because I farted in their store. It's not my falt they don't have Windows..."\
|
||||||
@@ -22,8 +23,8 @@ keywords[windows]="msg \"$chan\" \"$(shuf -n1 -e\
|
|||||||
"In a world without walls and fences - who needs windows and gates?"\
|
"In a world without walls and fences - who needs windows and gates?"\
|
||||||
"Windows, plug and pray."\
|
"Windows, plug and pray."\
|
||||||
"Windows - Just another pain in the glass."\
|
"Windows - Just another pain in the glass."\
|
||||||
"Windows, it's not pretty, it's not ugly, but it's pretty ugly.")!\""
|
"Windows, it's not pretty, it's not ugly, but it's pretty ugly.")!\" 25%"
|
||||||
keywords[emacs]="msg \"$chan\" \"$who, Real men of genius use vim!\""
|
keywords[emacs]="msg \"$chan\" \"$who, Real men of genius use vim!\" 50%"
|
||||||
keywords[jaws]="msg \"$chan\" \"${who}: watch out for sharks!\""
|
keywords[jaws]="msg \"$chan\" \"${who}: watch out for sharks!\""
|
||||||
keywords[emacspeak]="msg \"$chan\" \"$who, Real men of genius use vim!\""
|
keywords[emacspeak]="msg \"$chan\" \"$who, Real men of genius use vim!\""
|
||||||
keywords[nano]="msg \"$chan\" \"$who, Real men of genius use vim!\""
|
keywords[nano]="msg \"$chan\" \"$who, Real men of genius use vim!\""
|
||||||
@@ -43,7 +44,20 @@ keywords[vim]="msg \"$chan\" \"$(shuf -n1 -e \
|
|||||||
wordList="$(echo "${@,,}" | tr '[:space:]' $'\n' | sort -u)"
|
wordList="$(echo "${@,,}" | tr '[:space:]' $'\n' | sort -u)"
|
||||||
for w in ${wordList//[[:punct:]]/} ; do
|
for w in ${wordList//[[:punct:]]/} ; do
|
||||||
if [[ -n "${keywords[${w,,}]}" && "$lastWordMatch" != "${keywords[${w,,}]}" ]]; then
|
if [[ -n "${keywords[${w,,}]}" && "$lastWordMatch" != "${keywords[${w,,}]}" ]]; then
|
||||||
eval "${keywords[${w,,}]}"
|
keywordAction="${keywords[${w,,}]}"
|
||||||
|
# Check if the last element is a percentage
|
||||||
|
if [[ "$keywordAction" =~ (.*)\ ([0-9]+)%$ ]]; then
|
||||||
|
command="${BASH_REMATCH[1]}"
|
||||||
|
percentage="${BASH_REMATCH[2]}"
|
||||||
|
# Generate random number between 1-100 and only respond if within percentage
|
||||||
|
randomNum=$((RANDOM % 100 + 1))
|
||||||
|
if [[ $randomNum -le $percentage ]]; then
|
||||||
|
eval "$command"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# No percentage specified, always respond
|
||||||
|
eval "$keywordAction"
|
||||||
|
fi
|
||||||
lastWordMatch="${keywords[${w,,}]}"
|
lastWordMatch="${keywords[${w,,}]}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user