Hopefully fixed weird bug where it was using the message sender as the channel to check.

This commit is contained in:
Storm Dragon
2025-11-20 13:07:08 -05:00
parent 59c5f15321
commit fc5726a4f1

View File

@@ -25,19 +25,20 @@ fi
# Check if invoked from a PM (channel name equals username) # Check if invoked from a PM (channel name equals username)
if [[ "$channelName" == "$userName" ]]; then if [[ "$channelName" == "$userName" ]]; then
# PM context: check if first argument is a channel name # PM context: check if first argument is a channel name
firstArg="$1" # Extract just the first word (bot.sh passes all remaining args as a single string)
echo "DEBUG say.sh: PM context detected, firstArg='$firstArg'" >> "$log" firstWord="${1%% *}"
echo "DEBUG say.sh: PM context detected, firstWord='$firstWord', allArgs='$*'" >> "$log"
# Note: bot.sh strips "# " (hash-space) from commands, but "#channel" stays intact # Note: bot.sh strips "# " (hash-space) from commands, but "#channel" stays intact
# Remove # prefix if present for comparison # Remove # prefix if present for comparison
firstArgNoHash="${firstArg#\#}" firstWordNoHash="${firstWord#\#}"
# Check if first argument looks like a channel name (matches configured channels) # Check if first word looks like a channel name (matches configured channels)
isConnected=false isConnected=false
targetChannel="" targetChannel=""
for configuredChannel in "${channels[@]}"; do for configuredChannel in "${channels[@]}"; do
if [[ "$firstArgNoHash" == "$configuredChannel" ]]; then if [[ "$firstWordNoHash" == "$configuredChannel" ]]; then
isConnected=true isConnected=true
targetChannel="$configuredChannel" targetChannel="$configuredChannel"
break break
@@ -45,19 +46,20 @@ if [[ "$channelName" == "$userName" ]]; then
done done
if [[ "$isConnected" == "true" ]]; then if [[ "$isConnected" == "true" ]]; then
# First arg is a known channel, send message there # First word is a known channel, extract the rest as the message
shift restOfMessage="${1#* }"
if [[ -z "$*" ]]; then # If firstWord == $1, there was no space, so no message
if [[ "$firstWord" == "$1" ]]; then
msg "$userName" "Please provide a message to say in #$targetChannel." msg "$userName" "Please provide a message to say in #$targetChannel."
else else
msg "#$targetChannel" "$*" msg "#$targetChannel" "$restOfMessage"
fi fi
else else
# Check if first arg looks like it could be a channel name (not in our list) # Check if first word looks like it could be a channel name (not in our list)
# If it contains no spaces and looks channel-ish, assume user specified wrong channel # If it contains no spaces and looks channel-ish, assume user specified wrong channel
if [[ "$firstArgNoHash" =~ ^[a-zA-Z0-9_-]+$ ]] && [[ ! "$firstArgNoHash" =~ [[:space:]] ]]; then if [[ "$firstWordNoHash" =~ ^[a-zA-Z0-9_-]+$ ]] && [[ ! "$firstWordNoHash" =~ [[:space:]] ]]; then
# Looks like a channel name but we're not connected # Looks like a channel name but we're not connected
msg "$userName" "I am not connected to #$firstArgNoHash." msg "$userName" "I am not connected to #$firstWordNoHash."
else else
# No channel specified, broadcast to all channels # No channel specified, broadcast to all channels
for configuredChannel in "${channels[@]}"; do for configuredChannel in "${channels[@]}"; do