#!/bin/bash #2026 miredo version="3b" refresh_time=30 user_color=15 my_trip="" #strip out excess keypresses cleanbuffer() { while read -t 0 do read -N 1 -s done } #reset all colors reset_col() { echo -e -n "\033[0m" } #show the full scrollback check_scrollback() { echo "$msg_raw" | less } #set the color #usage: set_col color bold #color 30-37: blk, red, grn, ylw, blu, mag, cyn, wht #40-47 set the background color #bold is 1 or 0 set_col() { echo -e -n "\033[$2;$1m" } set_tripcode() { reset_col IFS= read -p "tripcode (optional): " -e -r my_trip } set_username() { reset_col IFS= read -p "username: " -e -r username } set_interval() { reset_col IFS= read -p "update interval (min 30): " -e -r refresh_time refresh_time=$(($refresh_time)) if (( refresh_time < 30 )) then refresh_time=30 fi } #sends a message via cURL #TODO: should we set our own referrer? might be useful/fun send_msg() { reset_col IFS= read -p "message: " -e -r mymsg curl -s \ --data-urlencode "mode=regist" \ --data-urlencode "name=$username" \ --data-urlencode "email=" \ --data-urlencode "password=$my_trip" \ --data-urlencode "comment=$mymsg" \ --data-urlencode "face=" \ --data-urlencode "color=$user_color" \ --data-urlencode "retime=0" \ --data-urlencode "lines=1" \ --data-urlencode "autoclear=on" \ https://cgi.heyuri.net/chat/comchat.cgi > /dev/null } #shows the help show_help() { reset_col clear set_col 36 1 echo "command keys:" reset_col echo "q - quit" echo "? - show this help message" echo "/ - send a message (leave the message blank to cancel)" echo "r - refresh" echo "p - view the chat scrollback (via the less command, press q to exit)" echo "# - set the tripcode" echo "i - set the update interval (min 30s)" echo set_col 36 1 echo "other notes:" reset_col echo "* refresh the screen if you change your terminal size" echo "* any unused key will also refresh, not just r" echo set_col 32 1 echo "Press any key to continue." reset_col read -N 1 -s } #main program starts here, shows the intro reset_col clear set_col 36 0 echo "miredo's very very lazy comchat client for Chat@Heyuri" echo "version $version" set_col 36 1 #IFS= read -e -r -p "username: " username set_username set_tripcode echo #main loop here while true do #get terminal size scr_w=`tput cols` scr_h=`tput lines` #load and format the message list reset_col set_col 31 1 echo -n "[loading...]" cleanbuffer #TODO: handle HTML entities somehow lol (or at least find and replace " and &) #TODO: strip all control characters - probably not ever going to be an issue, but there isn't a real reason to not do it for sanity's sake msg_raw="$( curl -s https://cgi.heyuri.net/chat/simplelog.txt) " msg="$( echo "$msg_raw" | fold -s -w $scr_w | head -n $(expr $scr_h - 4) )" clear set_col 44 0 set_col 37 1 echo "[refeshed on $(date) | ($scr_w"x"$scr_h) | reload: $refresh_time"s"]" #display the messages reset_col set_col 37 1 #dumb hack that admittedly doesn't matter to show the first line in a diferent color echo "$msg" | head -n 1 reset_col echo "$msg" | tail -n +2 set_col 44 0 set_col 37 1 echo "keys: q-quit, /-send, r-refresh, ?-help" reset_col #handle user commands read -t $refresh_time -N 1 -s inp #quit if [[ "$inp" == "q" ]] then clear exit 1 fi #post if [[ "$inp" == "/" ]] then send_msg fi #view whole scrollback of posts if [[ "$inp" == "p" ]] then check_scrollback fi if [[ "$inp" == "?" ]] then show_help fi if [[ "$inp" == "#" ]] then set_tripcode fi if [[ "$inp" == "i" ]] then set_interval fi cleanbuffer set_col 33 1 echo -n "[refreshing...] " reset_col sleep 1 #minimum time so we don't hammer the site with a bunch of requests done