Created
September 29, 2020 12:43
-
-
Save tyzbit/ee5f392bcab4cd779aa99d7d0c81afdd to your computer and use it in GitHub Desktop.
A CGI script to show the top chat messages from IRC logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
twitchroot="/home/eggdrop/twitcher/logs/" | |
alllogs=$(echo $twitchroot"*") | |
logpath="http://qtosw.com/pubfiles/twitchlogs/?C=M;O=D" | |
echo -e "Content-type: text/html; charset=utf-8\n" | |
echo "<html><head>" | |
echo "<meta charset=utf-8>" | |
echo "<link rel=\"stylesheet\" href=\"style.css\" />" | |
echo "</head><body>" | |
#initialize what we have to work with | |
i=0 | |
chatarray=() | |
#find the name of each log file, removing extensions and duplicates | |
for f in $(find $twitchroot -type f -printf "%f\n"| sed 's/\.[^.]*\.[^.]*$//' | sort | uniq) | |
do | |
chatarray+=("$f") | |
done | |
#did we get any variables? no? | |
if [ -z $1 ]; then | |
echo "<h2>Please pick a chat:</h2><br>" | |
echo "<table><tr><td>" | |
i=0 | |
for f in ${chatarray[@]} | |
do | |
echo $(echo "<a href=?"$i">$f</a><br>") | |
let i=i+1 | |
done | |
echo "</td><td style=\"text-align:right\">" | |
echo "<h3><p><a href=?today>See all from today</a></p></h3>" | |
echo "<h3><p><a href=?yesterday>See all logs from yesterday</a></p></h3>" | |
echo "<h3><p><a href=$logpath>All logs ever</a></p></h3>" | |
echo "</td></tr></table>" | |
else | |
if [ "$1" = "today" ]; then | |
cat $alllogs.log.$(date +%d%m%Y) | sed 's/<[^>]*> //g' | sed 's/\[[^>]*] //g' | sort | uniq -c -d | sort -r | sed 's/$/<br>/' | |
# cat $alllogs | sed 's/<[^>]*> //g' | sed 's/\[[^>]*] //g' | sort | uniq -c -d | sort -r | sed 's/$/<br>/' | |
else | |
if [ "$1" = "yesterday" ]; then | |
cat $alllogs.log.$(date --date='yesterday' +%d%m%Y) | sed 's/<[^>]*> //g' | sed 's/\[[^>]*] //g' | sort | uniq -c -d | sort -r | sed 's/$/<br>/' | |
else | |
option1=$(echo $1 | sed 's/\\&.*//g') | |
option2=$(echo $1 | sed 's/.*\&//') | |
if [ $option2 == $option1 ]; then | |
echo "<h2>Now pick a date:</h2><br>" | |
echo "<a href=?"$1"&"$(date +%d%m%Y)">Today</a><br><br>" | |
for f in $(find $twitchroot -type f -printf "%f\n" | grep ${chatarray[$option1]} | sed 's/^.*\.log.//') | |
do | |
echo "<a href=./?"$1"&"$f">$f</a><br>" | |
done | |
else | |
# cat $(echo $twitchroot"/"${chatarray[$option1]}".log."$option2) | |
echo "<h3>${chatarray[$option1]}'s copypasta from $option2:</h3>" | |
cat $(echo $twitchroot"/"${chatarray[$option1]}".log."$option2) | sed 's/<[^>]*> //g' | sed 's/\[[^>]*] //g' | sort | uniq -c -d | sort -r | sed 's/$/<br>/' | |
fi | |
fi | |
fi | |
fi | |
echo "</html>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment