this commit is bound to break every single existing iron patch, but it's
a massive cleanup and most patches didn't apply anyway.
This commit is contained in:
parent
9d078ebd4a
commit
fc0a6724c4
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
|||
SHELL = /bin/sh
|
||||
NAME = iron
|
||||
VER = 1.2
|
||||
VER = 1.3
|
||||
|
||||
include options.mk
|
||||
|
||||
|
|
355
iron
355
iron
|
@ -5,75 +5,76 @@
|
|||
# See https://codeberg.org/speedie/iron or https://speedie.gq/iron for more information.
|
||||
|
||||
# wrapper funcs
|
||||
PRINTN() { printf "%s$@"; }
|
||||
PRINT() { PRINTN "%s$@\n"; }
|
||||
DIE() { PRINT "%s$@" && EXIT 1; }
|
||||
DEFAULT_INSTANCE="${DEFAULT_INSTANCE:-https://example.com}"
|
||||
printn() { printf "%s$*"; }
|
||||
printstr() { printn "%s$*\n"; }
|
||||
die() { printstr "%s$*" && exitclient 1; }
|
||||
definstance="${definstance:-https://example.com}"
|
||||
|
||||
CLEAN() {
|
||||
rm -f "$WDIR/iron-editor-message" \
|
||||
"$WDIR/iron-messagedata" \
|
||||
"$WDIR/iron-message" \
|
||||
"$WDIR/iron-api" \
|
||||
"$WDIR/iron-api-orig"
|
||||
cleancli() {
|
||||
rm -f "$working_dir/iron-editor-message" \
|
||||
"$working_dir/iron-messagedata" \
|
||||
"$working_dir/iron-message" \
|
||||
"$working_dir/iron-api" \
|
||||
"$working_dir/iron-api-orig"
|
||||
}
|
||||
|
||||
UPDATEBORDER() {
|
||||
FSEP="$(seq "$(tput cols)" | xargs -Iz printf "${COLOR_01}$SEP${COLOR_01}")"
|
||||
updateborder() {
|
||||
sp="$(seq "$(tput cols)" | xargs -Iz printf "${COLOR_01}$SEP${COLOR_01}")"
|
||||
return
|
||||
}
|
||||
|
||||
EXIT() {
|
||||
[ -z "$1" ] && EXITCODE="0" || EXITCODE="$1"
|
||||
ENDMSG="iron terminated. (exit code $EXITCODE)"
|
||||
exitclient() {
|
||||
[ -z "$1" ] && exitcode="0" || exitcode="$1"
|
||||
endmsg="iron terminated. (exit code $exitcode)"
|
||||
|
||||
# clean working dir
|
||||
rm -f "$WDIR/iron-editor-message" \
|
||||
"$WDIR/iron-messagedata" \
|
||||
"$WDIR/iron-message" \
|
||||
"$WDIR/iron-api" \
|
||||
"$WDIR/iron-api-orig"
|
||||
rm -f "$working_dir/iron-editor-message" \
|
||||
"$working_dir/iron-messagedata" \
|
||||
"$working_dir/iron-message" \
|
||||
"$working_dir/iron-api" \
|
||||
"$working_dir/iron-api-orig"
|
||||
clear
|
||||
PRINT "$ENDMSG"
|
||||
exit $EXITCODE
|
||||
printstr "$endmsg"
|
||||
exit "$exitcode"
|
||||
}
|
||||
|
||||
MAIN() {
|
||||
rm -f $WDIR/iron-session \
|
||||
$WDIR/iron-editor-message \
|
||||
$WDIR/iron-messagedata \
|
||||
$WDIR/iron-api \
|
||||
$WDIR/iron-api-orig
|
||||
end_session() {
|
||||
rm -f "$working_dir/iron-session" \
|
||||
"$working_dir/iron-editor-message" \
|
||||
"$working_dir/iron-messagedata" \
|
||||
"$working_dir/iron-api" \
|
||||
"$working_dir/iron-api-orig"
|
||||
clear
|
||||
${0}
|
||||
EXIT 0
|
||||
exitclient 0
|
||||
}
|
||||
|
||||
# init
|
||||
INIT() {
|
||||
main() {
|
||||
# few basic checks
|
||||
[ -z "$(command -v jq)" ] && DIE "error: jq not found."
|
||||
[ -z "$WDIR" ] && WDIR=$HOME/.local/share/iron
|
||||
[ -z "$(command -v jq)" ] && die "error: jq not found."
|
||||
[ -z "$working_dir" ] && working_dir=$HOME/.local/share/iron
|
||||
|
||||
# check args
|
||||
case "$1" in
|
||||
"-h") printf "usage: iron [-c]\n" && exit 0 ;;
|
||||
"") : ;;
|
||||
"-c") rm -rf "$WDIR" && exit 0 ;;
|
||||
"-c") rm -rf "$working_dir" && exit 0 ;;
|
||||
*) printf "usage: iron [-c]\n" && exit 1 ;;
|
||||
esac
|
||||
|
||||
CLEAN
|
||||
cleancli
|
||||
|
||||
mkdir -p "$WDIR"
|
||||
mkdir -p "$working_dir"
|
||||
|
||||
[ -e "$WDIR/iron-instance" ] || PRINT "$DEFAULT_INSTANCE" > "$WDIR/iron-instance"
|
||||
[ -e "$WDIR/iron-ckey" ] && [ -z "$CKEY" ] && CKEY="$(cat "$WDIR/iron-ckey")"
|
||||
[ -e "$working_dir/iron-instance" ] || printstr "$definstance" > "$working_dir/iron-instance"
|
||||
[ -e "$working_dir/iron-ckey" ] && [ -z "$CKEY" ] && CKEY="$(cat "$working_dir/iron-ckey")"
|
||||
|
||||
INSTANCE="$(cat $WDIR/iron-instance)"
|
||||
instance="$(cat "$working_dir/iron-instance")"
|
||||
[ -z "$instance" ] && instance="example.com" # fallback
|
||||
|
||||
# hardcoded line count, this is the max lines our messages can take up, otherwise this code sucks
|
||||
LINECOUNT="$(expr $(tput lines) "-" 7)"
|
||||
lc="$(($(tput lines) - 7))"
|
||||
|
||||
# ansi escape codes, by default we use 7 colors
|
||||
[ -z "$NOCOLOR" ] && \
|
||||
|
@ -89,64 +90,66 @@ INIT() {
|
|||
VERSION="1.3"
|
||||
EXTRAVERSION="12-09-2022-r1"
|
||||
SEP='─'
|
||||
SEPCOUNT="$(tput cols)"
|
||||
MODE="-- NORMAL --" # default mode is normal mode
|
||||
sc="$(tput cols)"
|
||||
curmode="-- NORMAL --" # default mode is normal mode
|
||||
|
||||
UPDATEBORDER
|
||||
updateborder
|
||||
|
||||
DAPI
|
||||
dl_api
|
||||
|
||||
[ -e "$WDIR/iron-session" ] && PRINT "Existing session exists, joining.." || PH
|
||||
[ -z "$EDITOR" ] && EDITOR=vim
|
||||
[ -f "$working_dir/iron-session" ] && \
|
||||
printstr "Existing session exists, joining.." || PH
|
||||
|
||||
EDITOR="${EDITOR:-vim}"
|
||||
|
||||
clear
|
||||
|
||||
HEADER
|
||||
printheader
|
||||
|
||||
# die if no instance
|
||||
if [ -z "$INSTANCE" ]; then
|
||||
PRINTN "${COLOR_06}000 - SYSTEM at $(date '+%Y/%m/%d %T:')\nInstance is not set. Please set it!.${COLOR_01}" && sleep 3
|
||||
rm "$WDIR/iron-session"
|
||||
$0 && EXIT 0
|
||||
if [ -z "$instance" ]; then
|
||||
printn "${COLOR_06}000 - SYSTEM at $(date '+%Y/%m/%d %T:')\nInstance is not set. Please set it!.${COLOR_01}" && sleep 3
|
||||
rm "$working_dir/iron-session"
|
||||
$0 && exitclient 0
|
||||
fi
|
||||
|
||||
[ "$CKEY" != "IRON_NO_CAPTCHA" ] && [ -z "$CKEY" ] && PRINTN "${COLOR_06}000 - SYSTEM at $(date '+%Y/%m/%d %T:')\nWarning: No captcha was provided. This may cause messages to not send properly. Set the captcha to IRON_NO_CAPTCHA to hide this warning.${COLOR_01}\n" && sleep 2 && clear && HEADER
|
||||
[ "$CKEY" != "IRON_NO_CAPTCHA" ] && [ -z "$CKEY" ] && printn "${COLOR_06}000 - SYSTEM at $(date '+%Y/%m/%d %T:')\nWarning: No captcha was provided. This may cause messages to not send properly. Set the captcha to IRON_NO_CAPTCHA to hide this warning.${COLOR_01}\n" && sleep 2 && clear && printheader
|
||||
[ "$CKEY" = "IRON_NO_CAPTCHA" ] && CKEY="" # then we don't need a captcha, according to the user who is probably an idiot
|
||||
|
||||
# check connection
|
||||
ping -q "$(dirname "$INSTANCE" | sed "s|https://||g")" -c 1 > /dev/null || DIE "error: could not download api data"
|
||||
ping -q "$(dirname "$instance" | sed "s|https://||g")" -c 1 > /dev/null || die "error: could not download api data"
|
||||
|
||||
PMSG
|
||||
CUPDATE
|
||||
parse_msgs
|
||||
checkupt
|
||||
}
|
||||
|
||||
DAPI()
|
||||
dl_api()
|
||||
{
|
||||
# download everything from the api
|
||||
curl -so "$WDIR/iron-api-orig" "$INSTANCE/api.php"
|
||||
[ -e "$WDIR/iron-api-orig" ] && sed "s|\n|${COLOR_01}\n|g" $WDIR/iron-api-orig > $WDIR/iron-api || DAPI
|
||||
curl -so "$working_dir/iron-api-orig" "$instance/api.php"
|
||||
[ -e "$working_dir/iron-api-orig" ] && sed "s|\n|${COLOR_01}\n|g" $working_dir/iron-api-orig > $working_dir/iron-api || dl_api
|
||||
}
|
||||
|
||||
PH()
|
||||
{
|
||||
clear
|
||||
|
||||
PRINTH() {
|
||||
PRINT "$NAME $VERSION"
|
||||
PRINT "$FSEP"
|
||||
PRINT "${COLOR_02}Last login: $(date '+%Y/%m/%d at %T')${COLOR_01}"
|
||||
PRINT "${COLOR_07}$NAME was started: '$(date '+%T')'.\n"
|
||||
PRINT "Welcome to $NAME $VERSION. $NAME is a rautafarmi textboard client with Vim keybinds."
|
||||
printstrh() {
|
||||
printstr "$NAME $VERSION"
|
||||
printstr "$sp"
|
||||
printstr "${COLOR_02}Last login: $(date '+%Y/%m/%d at %T')${COLOR_01}"
|
||||
printstr "${COLOR_07}$NAME was started: '$(date '+%T')'.\n"
|
||||
printstr "Welcome to $NAME $VERSION. $NAME is a rautafarmi textboard client with Vim keybinds."
|
||||
|
||||
[ -z "$INSTANCE" ] && PINSTANCE="None set." || PINSTANCE="$INSTANCE"
|
||||
[ -z "$instance" ] && Pinstance="None set." || Pinstance="$instance"
|
||||
|
||||
# print instance text/url
|
||||
PRINTN "\n${COLOR_03}Instance: '$PINSTANCE'\n${COLOR_01}"
|
||||
PRINTN "\n${COLOR_02}iron written by speedie & potential contributors and is licensed under the GNU General Public License version 3.0 free software license."
|
||||
PRINTN "\n${COLOR_05}See https://speedie.gq/projects/iron.php or https://codeberg.org/speedie/iron for more information.${COLOR_01}\n"
|
||||
printn "\n${COLOR_03}Instance: '$Pinstance'\n${COLOR_01}"
|
||||
printn "\n${COLOR_02}iron written by speedie & potential contributors and is licensed under the GNU General Public License version 3.0 free software license."
|
||||
printn "\n${COLOR_05}See https://speedie.gq/projects/iron.php or https://codeberg.org/speedie/iron for more information.${COLOR_01}\n"
|
||||
}
|
||||
|
||||
PRINTH
|
||||
printstrh
|
||||
|
||||
while true; do
|
||||
# get user cmd
|
||||
|
@ -158,89 +161,86 @@ PH()
|
|||
"Z") read -n 1 ZCM ;;
|
||||
esac
|
||||
|
||||
clear; PRINTH
|
||||
clear; printstrh
|
||||
else
|
||||
read CM
|
||||
fi
|
||||
|
||||
# ZZ and ZQ binds
|
||||
case "$ZCM" in
|
||||
"ZZ") $0 && EXIT 0 ;;
|
||||
"ZQ") EXIT 0 ;;
|
||||
"ZZ") $0 && exitclient 0 ;;
|
||||
"ZQ") exitclient 0 ;;
|
||||
esac
|
||||
|
||||
# misc binds
|
||||
case "$CM" in
|
||||
"Q") EXIT 0 ;;
|
||||
"Z") $0 && EXIT 0 ;;
|
||||
"q") EXIT 0 ;;
|
||||
"q!") EXIT 0 ;;
|
||||
"quit") EXIT 0 ;;
|
||||
"j") touch $WDIR/iron-session && INIT ;;
|
||||
"set captcha") CMSG ;;
|
||||
"set instance") clear ; HEADER ; PRINTN "Enter your instance (Example: https://example.com/ironfarms):\n> " ; read INSTANCE ; printf "$INSTANCE" > $WDIR/iron-instance && clear && HEADER && printf "${COLOR_06}000 - SYSTEM at $(date '+%Y/%m/%d %T:')\nSet instance to '$INSTANCE'.${COLOR_01}" && sleep 3 && ${0} && EXIT 0 ;;
|
||||
"set instance default") echo $DEFAULT_INSTANCE > $WDIR/iron-instance && clear && HEADER && printf "${COLOR_06}000 - SYSTEM at $(date '+%Y/%m/%d %T:')\nSet instance to '$DEFAULT_INSTANCE'.${COLOR_01}" && sleep 3 && ${0} && EXIT 0 ;;
|
||||
"reset") rm -rf $WDIR && ${0} && EXIT 0 ;;
|
||||
"Q") exitclient 0 ;;
|
||||
"Z") $0 && exitclient 0 ;;
|
||||
"q") exitclient 0 ;;
|
||||
"q!") exitclient 0 ;;
|
||||
"quit") exitclient 0 ;;
|
||||
"j") touch "$working_dir/iron-session" && main ;;
|
||||
"set captcha") CMSG ;;
|
||||
"set instance") clear ; printheader ; printn "Enter your instance (Example: https://example.com/ironfarms):\n> " ; read instance ; printf "%s" "$instance" > "$working_dir/iron-instance" && clear && printheader && \
|
||||
printf "%s000 - SYSTEM at %s\nSet instance to '%s'.%s" "${COLOR_06}" "$(date '+%Y/%m/%d %T:')" "$instance" "${COLOR_01}" && sleep 3 && ${0} && exitclient 0 ;;
|
||||
"set instance default") echo "$definstance" > "$working_dir/iron-instance" && clear && printheader && \
|
||||
printf "%s000 - SYSTEM at %s\nSet instance to '%s'.%s" "${COLOR_06}" "$(date '+%Y/%m/%d %T:')" "$definstance" "${COLOR_01}" && sleep 3 && ${0} && exitclient 0 ;;
|
||||
"reset") rm -rf "$working_dir" && ${0} && exitclient 0 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# print basic header and then the separator
|
||||
HEADER()
|
||||
{
|
||||
printf "$NAME $VERSION\n"
|
||||
printf "$FSEP\n"
|
||||
}
|
||||
printheader() { printf "%s %s\n%s\n" "$NAME" "$VERSION" "$sp"; }
|
||||
|
||||
# captcha
|
||||
CMSG() {
|
||||
clear
|
||||
HEADER
|
||||
PRINTN "Enter your captcha answer. This can often be found on the instance website. Note that if this is randomized then iron is not very convenient to use. In this case switch instance or use the official client instead. (Example: 43):\n> "
|
||||
read PCKEY
|
||||
PRINT "$PCKEY" > $WDIR/iron-ckey && clear && HEADER && printf "${COLOR_06}000 - SYSTEM at $(date '+%Y/%m/%d %T:')\nSet captcha to '$PCKEY'.${COLOR_01}" && sleep 3 && ${0} && EXIT 0
|
||||
printheader
|
||||
printn "Enter your captcha answer. This can often be found on the instance website. Note that if this is randomized then iron is not very convenient to use. In this case switch instance or use the official client instead. (Example: 43):\n> "
|
||||
read cap
|
||||
printstr "$cap" > "$working_dir/iron-ckey" && clear && printheader && printf "%s000 - SYSTEM at %s\nSet captcha to '%s'.%s" "${COLOR_06}" "$(date '+%Y/%m/%d %T:')" "$cap" "${COLOR_01}" && sleep 3 && ${0} && exitclient 0
|
||||
}
|
||||
|
||||
PMSG()
|
||||
{
|
||||
if [ "$DONOTREPARSE" != "true" ]; then
|
||||
parse_msgs() {
|
||||
if [ "$do_not_reparse" != "true" ]; then
|
||||
# fail if the json is not valid
|
||||
FAIL_COULD_NOT_PARSE() {
|
||||
# originally wanted to fail the client completely if the json isn't valid
|
||||
# there is currently some weird bug though so for now we'll restart it to hide the problem
|
||||
clear
|
||||
rm -f $WDIR/iron-messagedata $WDIR/iron-message
|
||||
$0 && EXIT 0
|
||||
rm -f "$working_dir/iron-messagedata" "$working_dir/iron-message"
|
||||
$0 && exitclient 0
|
||||
}
|
||||
|
||||
rm -f $WDIR/iron-editor-message \
|
||||
$WDIR/iron-messagedata \
|
||||
$WDIR/iron-message \
|
||||
$WDIR/iron-api \
|
||||
$WDIR/iron-api-orig
|
||||
rm -f "$working_dir/iron-editor-message" \
|
||||
"$working_dir/iron-messagedata" \
|
||||
"$working_dir/iron-message" \
|
||||
"$working_dir/iron-api" \
|
||||
"$working_dir/iron-api-orig"
|
||||
|
||||
DAPI
|
||||
dl_api
|
||||
|
||||
# save individual data to combine later
|
||||
jq -e ".posts[] .username" $WDIR/iron-api > $WDIR/iron-username || FAIL_COULD_NOT_PARSE
|
||||
jq -e ".posts[] .message" $WDIR/iron-api > $WDIR/iron-message || FAIL_COULD_NOT_PARSE
|
||||
jq -e ".posts[] .time" $WDIR/iron-api > $WDIR/iron-messagetime || FAIL_COULD_NOT_PARSE
|
||||
jq -e ".posts[] .postID" $WDIR/iron-api > $WDIR/iron-messageid || FAIL_COULD_NOT_PARSE
|
||||
jq -e ".posts[] .imageURL" $WDIR/iron-api > $WDIR/iron-messageimg || FAIL_COULD_NOT_PARSE
|
||||
jq -e ".posts[] .username" $working_dir/iron-api > "$working_dir/iron-username" || FAIL_COULD_NOT_PARSE
|
||||
jq -e ".posts[] .message" $working_dir/iron-api > "$working_dir/iron-message" || FAIL_COULD_NOT_PARSE
|
||||
jq -e ".posts[] .time" $working_dir/iron-api > "$working_dir/iron-messagetime" || FAIL_COULD_NOT_PARSE
|
||||
jq -e ".posts[] .postID" $working_dir/iron-api > "$working_dir/iron-messageid" || FAIL_COULD_NOT_PARSE
|
||||
jq -e ".posts[] .imageURL" $working_dir/iron-api > "$working_dir/iron-messageimg" || FAIL_COULD_NOT_PARSE
|
||||
|
||||
# delete prev message data
|
||||
rm -f $WDIR/iron-messagedata
|
||||
rm -f $working_dir/iron-messagedata
|
||||
|
||||
# format it somewhat
|
||||
# we will mostly print this file as it is
|
||||
# replace "" in username because it means none was specified.
|
||||
# replace "%" with "%%" so that printf will actually print it.
|
||||
for i in $(seq $LINECOUNT); do
|
||||
username="$(head -n $i $WDIR/iron-username | tail -n 1 | sed 's/""/Anonymous/g')"
|
||||
message="$(head -n $i $WDIR/iron-message | tail -n 1 | sed "s/%/%%/g; s/>>/DISREPLY/g; s/>/DISGTEXT/g; s/DISREPLY/${COLOR_04}>>/g; s/DISGTEXT/${COLOR_07}>/g; s/\" \"//g")"
|
||||
time="$(head -n $i $WDIR/iron-messagetime | tail -n 1)"
|
||||
id="$(head -n $i $WDIR/iron-messageid | tail -n 1)"
|
||||
imageurl="$(head -n $i $WDIR/iron-messageimg | tail -n 1 | sed 's/""/NoImg/g')"
|
||||
for i in $(seq $lc); do
|
||||
username="$(head -n $i $working_dir/iron-username | tail -n 1 | sed 's/""/Anonymous/g')"
|
||||
message="$(head -n $i $working_dir/iron-message | tail -n 1 | sed "s/%/%%/g; s/>>/DISREPLY/g; s/>/DISGTEXT/g; s/DISREPLY/${COLOR_04}>>/g; s/DISGTEXT/${COLOR_07}>/g; s/\" \"//g")"
|
||||
time="$(head -n $i $working_dir/iron-messagetime | tail -n 1)"
|
||||
id="$(head -n $i $working_dir/iron-messageid | tail -n 1)"
|
||||
imageurl="$(head -n $i $working_dir/iron-messageimg | tail -n 1 | sed 's/""/NoImg/g')"
|
||||
|
||||
# image url formatting
|
||||
imgformattingb="]"
|
||||
|
@ -249,122 +249,127 @@ PMSG()
|
|||
[ "$imageurl" = "NoImg" ] && imgformattinga="" && imgformattingb="" && imageurl=""
|
||||
|
||||
# print it
|
||||
printf "${COLOR_04}$id - ${COLOR_05}$username${COLOR_02} at ${COLOR_03}$time:${COLOR_01}\n$message${COLOR_01}${COLOR_04}$imgformattinga$imageurl$imgformattingb${COLOR_01}\n" | sed 's/"//g' | sed "s/.*/${COLOR_01}&${COLOR_01}/" >> $WDIR/iron-messagedata
|
||||
printf "${COLOR_04}$id - ${COLOR_05}$username${COLOR_02} at ${COLOR_03}$time:${COLOR_01}\n$message${COLOR_01}${COLOR_04}$imgformattinga$imageurl$imgformattingb${COLOR_01}\n" | sed 's/"//g' | sed "s/.*/${COLOR_01}&${COLOR_01}/" >> $working_dir/iron-messagedata
|
||||
done
|
||||
fi
|
||||
|
||||
# get the number of messages we need from the parsed list of stuff
|
||||
fold -w${SEPCOUNT} $WDIR/iron-messagedata | head -n $LINECOUNT
|
||||
PRINT "${COLOR_01}$FSEP"
|
||||
PRINT "${COLOR_04}I: ${INSTANCE} L: ${LINECOUNT}/$(cat $WDIR/iron-message | wc -l) LL: $(date '+%Y/%m/%d at %T')${COLOR_01}"
|
||||
PRINT "${FSEP}"
|
||||
fold -w${sc} "$working_dir/iron-messagedata" | head -n $lc
|
||||
|
||||
DONOTREPARSE=false
|
||||
# print footer
|
||||
printstr "${COLOR_01}$sp"
|
||||
printstr "${COLOR_04}I: ${instance} L: ${lc}/$(cat "$working_dir/iron-message" | wc -l) LL: $(date '+%Y/%m/%d at %T')${COLOR_01}"
|
||||
printstr "${sp}"
|
||||
|
||||
do_not_reparse=false
|
||||
}
|
||||
|
||||
# send the message using curl that we composed
|
||||
SENDMSG()
|
||||
sendmsg()
|
||||
{
|
||||
[ -e "$WDIR/iron-editor-message" ] && SMSG="$(cat $WDIR/iron-editor-message)"
|
||||
[ -e "$working_dir/iron-editor-message" ] && smsg="$(cat "$working_dir/iron-editor-message")"
|
||||
|
||||
if [ -z "$CKEY" ]; then
|
||||
curl -sX POST $INSTANCE/post.php -F "message=$SMSG" > /dev/null && STATUS=sent
|
||||
curl -sX POST "$instance/post.php" -F "message=$smsg" > /dev/null && curl_status=sent
|
||||
else
|
||||
curl -sX POST $INSTANCE/post.php -F "message=$SMSG" -F "captcha=$CKEY" > /dev/null && STATUS=sent
|
||||
curl -sX POST "$instance/post.php" -F "message=$smsg" -F "captcha=$CKEY" > /dev/null && curl_status=sent
|
||||
fi
|
||||
|
||||
# if it was sent properly
|
||||
if [ "$STATUS" = "sent" ]; then
|
||||
if [ "$curl_status" = "sent" ]; then
|
||||
# print system status, if message was sent
|
||||
if [ ! -z "$SMSG" ]; then
|
||||
if [ ! -z "$smsg" ]; then
|
||||
clear
|
||||
HEADER
|
||||
PRINTN "${COLOR_06}000 - SYSTEM at $(date '+%Y/%m/%d %T:')\nMessage '$SMSG' sent. ${COLOR_01}" && sleep 0.5
|
||||
printheader
|
||||
printn "${COLOR_06}000 - SYSTEM at $(date '+%Y/%m/%d %T:')\nMessage '$smsg' sent. ${COLOR_01}" && sleep 0.5
|
||||
else
|
||||
clear
|
||||
HEADER
|
||||
PRINTN "${COLOR_06}000 - SYSTEM at $(date '+%Y/%m/%d %T:')\nError: Message cannot be empty. ${COLOR_01}" && sleep 0.5
|
||||
printheader
|
||||
printn "${COLOR_06}000 - SYSTEM at $(date '+%Y/%m/%d %T:')\nError: Message cannot be empty. ${COLOR_01}" && sleep 0.5
|
||||
fi
|
||||
else
|
||||
clear
|
||||
HEADER
|
||||
PRINTN "${COLOR_06}000 - SYSTEM at $(date '+%Y/%m/%d %T:')\nError: Server did not accept the message.\nCheck with your instance maintainer or try composing another message. ${COLOR_01}" && sleep 0.5
|
||||
printheader
|
||||
printn "${COLOR_06}000 - SYSTEM at $(date '+%Y/%m/%d %T:')\nError: Server did not accept the message.\nCheck with your instance maintainer or try composing another message. ${COLOR_01}" && sleep 0.5
|
||||
fi
|
||||
|
||||
rm -f $WDIR/iron-editor-message
|
||||
rm -f "$working_dir/iron-editor-message"
|
||||
clear
|
||||
${0} && EXIT 0
|
||||
${0} && exitclient 0
|
||||
}
|
||||
|
||||
# check for new messages by comparing printed messages and downloaded messages
|
||||
CUPDATE()
|
||||
{
|
||||
checkupt() {
|
||||
while true; do
|
||||
[ ! -e "$WDIR/iron-messagedata" ] && break
|
||||
[ "$SEPCOUNT" != "$(tput cols)" ] && UPDATEBORDER
|
||||
[ ! -e "$working_dir/iron-messagedata" ] && break
|
||||
[ "$sc" != "$(tput cols)" ] && updateborder
|
||||
|
||||
CMODE
|
||||
check_mode
|
||||
done
|
||||
|
||||
DAPI; PMSG
|
||||
dl_api; parse_msgs
|
||||
}
|
||||
|
||||
# compose a message
|
||||
INSERT() {
|
||||
insert() {
|
||||
clear
|
||||
DONOTREPARSE=true # don't download new messages and parse the api. this saves time as we don't need it now anyway!
|
||||
HEADER
|
||||
PMSG
|
||||
PRINTN "%s-- INSERT --\n> "
|
||||
read SMSG && MT=normal
|
||||
do_not_reparse=true # don't download new messages and parse the api. this saves time as we don't need it now anyway!
|
||||
printheader
|
||||
parse_msgs
|
||||
printn "%s-- INSERT --\n> "
|
||||
read smsg && ed=normal
|
||||
|
||||
[ -z "$SMSG" ] && ${0} && EXIT 0
|
||||
[ -z "$smsg" ] && ${0} && exitclient 0
|
||||
|
||||
SENDMSG
|
||||
${0} && EXIT 0
|
||||
sendmsg
|
||||
${0} && exitclient 0
|
||||
}
|
||||
|
||||
# run a command and perform its action
|
||||
CMD() {
|
||||
read CMD > /dev/null
|
||||
case "$CMD" in
|
||||
"q") EXIT 0 ;;
|
||||
"l") MAIN ;;
|
||||
"r") rm -f $WDIR/iron-messagedata && ${0} && EXIT 0 ;;
|
||||
"reset") rm -rf $WDIR/ && ${0} && EXIT 0 ;;
|
||||
"e") touch $WDIR/iron-editor-message ; $EDITOR $WDIR/iron-editor-message && MT=editor && SENDMSG ;;
|
||||
cmd() {
|
||||
read -r cmd > /dev/null
|
||||
|
||||
case "$cmd" in
|
||||
"q") exitclient 0 ;;
|
||||
"l") end_session ;;
|
||||
"r") rm -f "$working_dir/iron-messagedata" && ${0} && exitclient 0 ;;
|
||||
"reset") rm -rf "${working_dir:?}/" && ${0} && exitclient 0 ;;
|
||||
"e") touch "$working_dir/iron-editor-message" ; $EDITOR "$working_dir/iron-editor-message" && ed=editor && sendmsg ;;
|
||||
esac
|
||||
|
||||
$0 && EXIT 0
|
||||
$0 && exitclient 0
|
||||
}
|
||||
|
||||
# ZZ/ZQ actions
|
||||
ZCMD() {
|
||||
read -n 1 MODE
|
||||
case "$MODE" in
|
||||
"") MODE="NORMAL" && CUPDATE ;;
|
||||
"Q") EXIT 0 ;;
|
||||
"Z") MAIN ;;
|
||||
zbind() {
|
||||
read -r -n 1 curmode
|
||||
|
||||
# check mode
|
||||
case "$curmode" in
|
||||
"") curmode="NORMAL" && checkupt ;; # check for update, no mode change or keybind
|
||||
"Q") exitclient 0 ;;
|
||||
"Z") end_session ;;
|
||||
esac
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
CMODE() {
|
||||
check_mode() {
|
||||
while true; do
|
||||
read -t 1 -n 1 MODE > /dev/null
|
||||
case "$MODE" in
|
||||
"i") MODE="INSERT" && INSERT ;;
|
||||
"") MODE="NORMAL"; DONOTREPARSE=true; clear; HEADER; PMSG ;;
|
||||
"r") rm -f $WDIR/iron-messagedata $WDIR/iron-message && $0 && EXIT 0 ;;
|
||||
":") CMD ;;
|
||||
"e") touch $WDIR/iron-editor-message ; $EDITOR $WDIR/iron-editor-message && MT=editor && SENDMSG ;;
|
||||
"Z") ZCMD ;;
|
||||
"l") MAIN ;;
|
||||
read -t 1 -n 1 curmode > /dev/null
|
||||
|
||||
case "$curmode" in
|
||||
"i") curmode="INSERT" && insert ;;
|
||||
"") curmode="NORMAL"; do_not_reparse=true; clear; printheader; parse_msgs ;;
|
||||
"r") rm -f "$working_dir/iron-messagedata" "$working_dir/iron-message" && $0 && exitclient 0 ;;
|
||||
":") cmd ;;
|
||||
"e") touch "$working_dir/iron-editor-message" ; $EDITOR "$working_dir/iron-editor-message" && ed=editor && sendmsg ;;
|
||||
"Z") zbind ;;
|
||||
"l") end_session ;;
|
||||
esac
|
||||
|
||||
CUPDATE || break
|
||||
checkupt || break
|
||||
done
|
||||
}
|
||||
|
||||
INIT "$@"
|
||||
main "$@"
|
||||
|
|
Loading…
Reference in a new issue