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)
if [[ "$channelName" == "$userName" ]]; then
# PM context: check if first argument is a channel name
firstArg="$1"
echo "DEBUG say.sh: PM context detected, firstArg='$firstArg'" >> "$log"
# Extract just the first word (bot.sh passes all remaining args as a single string)
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
# 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
targetChannel=""
for configuredChannel in "${channels[@]}"; do
if [[ "$firstArgNoHash" == "$configuredChannel" ]]; then
if [[ "$firstWordNoHash" == "$configuredChannel" ]]; then
isConnected=true
targetChannel="$configuredChannel"
break
@@ -45,19 +46,20 @@ if [[ "$channelName" == "$userName" ]]; then
done
if [[ "$isConnected" == "true" ]]; then
# First arg is a known channel, send message there
shift
if [[ -z "$*" ]]; then
# First word is a known channel, extract the rest as the message
restOfMessage="${1#* }"
# If firstWord == $1, there was no space, so no message
if [[ "$firstWord" == "$1" ]]; then
msg "$userName" "Please provide a message to say in #$targetChannel."
else
msg "#$targetChannel" "$*"
msg "#$targetChannel" "$restOfMessage"
fi
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 [[ "$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
msg "$userName" "I am not connected to #$firstArgNoHash."
msg "$userName" "I am not connected to #$firstWordNoHash."
else
# No channel specified, broadcast to all channels
for configuredChannel in "${channels[@]}"; do