Skip to content

Instantly share code, notes, and snippets.

@saulmaldonado
Created June 28, 2024 20:27
Show Gist options
  • Save saulmaldonado/137b5b6f96965d870b109c6c9db7f031 to your computer and use it in GitHub Desktop.
Save saulmaldonado/137b5b6f96965d870b109c6c9db7f031 to your computer and use it in GitHub Desktop.
#!/bin/bash
channel="$1"
oauth_username="justinfan80393"
oauth_token="SCHMOOPIIE"
log_file="$2"
get_timestamp() {
TZ="America/Los_Angeles" date +"[%Y-%m-%dT%H:%M:%S.%3N%:z]"
}
while true; do
exec 3>&- 3<>/dev/tcp/irc.chat.twitch.tv/6667
if [[ $? -ne 0 ]]; then
echo "Failed to connect to Twitch IRC server"
exit 1
fi
echo "PASS $oauth_token" >&3
echo "NICK $oauth_username" >&3
echo "JOIN #$channel" >&3
while read -r -u 3 line; do
if [[ "$line" =~ ^PING ]]; then
echo "${line/PING/PONG}" >&3
continue
fi
if [[ "$line" =~ :(.*)\!.*\ PRIVMSG\ #$channel\ :(.*)$ ]]; then
log="$(get_timestamp) ${BASH_REMATCH[1]}: ${BASH_REMATCH[2]}"
if [[ -n $log_file ]]; then
echo $log >> $log_file
else
echo $log
fi
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment