Commit 480599d1 authored by user472393's avatar user472393
Browse files

clean up and comment

parent 9db99f20
......@@ -49,6 +49,13 @@ info_dir=/usr/share/nginx/tctv_html/info
info_http=https://tetrisconcept.tv/info/
stream_url=https://twitch.tv/tetrisconcept_tv
# common messages
cmsg=(
[0]="20g: DDDDDDDDCBA <<>> big: LLLLDCBA <<>> rev: DUUDCBA"
[1]="big: LLLLDCBA <<>> item: hold B and C, then press Start while READY is on screen"
[2]="big: LLRRLRLR (master mode only)"
[3]="https://tetrisconcept.tv/info/bot_help.txt"
)
# option variables
buffer=
......@@ -58,27 +65,28 @@ p1=
p2=
tv=
# what does user want the bot to do?
parser () {
while (($#)); do
case $1 in
-a|--abort)
-a|--abort) # cancel match
$abort_match "$p1" "$buffer"
exit
;;
-c|--code)
-c|--code) # print arcade codes
test -n "$game" || \
quit "ERROR --code requres a game. game is $game See help for details."
case "$game" in
!tgm1|tgm1|!tgm|tgm)
printer "20g: DDDDDDDDCBA <<>> big: LLLLDCBA <<>> rev: DUUDCBA"
printer "${cmsg[0]}"
quit "tgm1 codes printed"
;;
!tap|tap|tgm2p)
printer "big: LLLLDCBA <<>> item: hold B and C, then press Start while READY is on screen"
printer "${cmsg[1]}"
quit "tgm2 codes printed"
;;
!tgm3|tgm3)
printer "big: LLRRLRLR (master mode only)"
printer "${cmsg[2]}"
quit "tgm3 codes printed"
;;
esac
......@@ -87,15 +95,15 @@ parser () {
show_help
exit
;;
help|help?*)
printer "https://tetrisconcept.tv/info/bot_help.txt"
help|help?*) # print help
printer "${cmsg[3]}"
quit "chat help routine called"
;;
-v|--version)
show_version
exit
;;
-s|--standings)
-s|--standings) # print standings
$standings "$buffer"
exit
;;
......@@ -157,7 +165,7 @@ parser () {
p2=${p2//[^a-zA-Z0-9-_]}
p2=${p2,,}
;;
-i|--info)
-i|--info) # print history
if test -n "$2"; then
curl -sIL "$info_http" > /dev/null || \
quit "ERROR: --info option requires a valid http link. See help for details."
......@@ -172,11 +180,12 @@ parser () {
fi
;;
-m|--modes)
-m|--modes) # print game modes
if test -n "$2" || test -n "$game"; then
game=$2
which_game
printer "$(printf '%s\t' "${modes[@]}")"
mlister
printer "$mlist"
exit
else
quit "ERROR: --mode requires a non empty option argument or a game."
......@@ -198,7 +207,7 @@ parser () {
shift
done
}
# which game?
# which game are we doing?
which_game () {
game=${game/!/}
......@@ -239,6 +248,7 @@ which_game () {
;;
esac
# add a longform name
case $game in
nullpo)
ask=nullpomino
......@@ -256,6 +266,7 @@ which_game () {
}
# are the resources (players, tv) available?
# allows user to dream of N simultaneous players.
availability () {
test -d "$tmp_dir" || mkdir "$tmp_dir"
lockdir1="$tmp_dir/$p1.lock"
......@@ -390,6 +401,7 @@ elo_import () {
elo_db[$i]=1500
done
}
# list top players for tv emission
elo_tv () {
update_dir="$PWD/elo_db/*"
for i in $update_dir; do
......@@ -425,10 +437,9 @@ remote_control () {
shopt -u nocasematch
}
# ask for a game
player_query () {
# ask for a game
printer "@$p2 (${elo_db[$p2]%.*}) want a $ask race with @$p1 (${elo_db[$p1]%.*})? reply !yes and you got it."
sleep 1
# wait 5 minutes for confirmation
......@@ -479,6 +490,7 @@ tosser () {
fi
}
# coin toss loser bans first
banner () {
for i in $coinlose $coinwin; do
printer "@$i (${elo_db[$i]%.*}) please ban 1 mode >>> $(for j in "${modes[@]}"; do printf '%s\t\t' "$j"; done)"
......@@ -488,9 +500,7 @@ banner () {
done
}
#######
# racer
#######
# pick and race twice. if split, thrice.
racer () {
mlister
printer "<<< the choice is yours @$coinwin (${elo_db[$coinwin]%.*}) >>> $mlist"
......@@ -517,9 +527,8 @@ racer () {
tv_updater
fi
}
##########
# fin
##########
# print and export results.
finisher () {
((game_over++))
printer "すべてのテトリストに捧ぐ神の領域への挑戦権" "$(for i in "${results[@]}"; do printf '%s\t' "$i"; done)" "@$p1 (${elo_db[$p1]%.*}) @$p2 (${elo_db[$p2]%.*})"
......@@ -530,18 +539,20 @@ finisher () {
elo_export
}
#########
# functs
#########
# other functions follow
# list modes
mlister () {
mlist=$(for i in "${modes[@]}"; do printf '%s\t' "$i"; done)
}
# remove modes if mode number greater than 3
# check for results if mode number less than 3
mode_select () {
msg3=">>> @$p1 (${elo_db[$p1]%.*}) vs. @$p2 (${elo_db[$p2]%.*}) in $ask"
msg4=">>> report with !won <<or>> !lost"
msg5=">>> report with $p1 !won <<or>> $p1 !lost"
if [ "$buffer" ]; then
if [ "$buffer" ]; then # remote usage
while inotifywait -qq -e modify "$channel"; do
if tail -n 1 "$channel" | grep -i "$1"; then
check=$(tail -n 1 "$channel" | awk '{print $NF}' )
......@@ -565,7 +576,7 @@ mode_select () {
done
fi
done
else
else # local usage
while read -r check ; do
for i in "${!modes[@]}"; do
if [[ "${modes[i]}" == "$check" ]]; then
......@@ -584,9 +595,10 @@ mode_select () {
done
fi
}
# record winner, comments
result_check () {
elo_priors
if [ "$buffer" ]; then
if [ "$buffer" ]; then # remote usage
while inotifywait -qq -e modify "$channel"; do
if tail -n 1 "$channel" | grep -i "$p1" | grep '!won'; then
elo_case1
......@@ -630,7 +642,7 @@ result_check () {
return 1
fi
done
else
else # local usage
while read -r result ; do
if [[ "$result" =~ $p1 && "$result" =~ !won ]]; then
elo_case1
......@@ -656,6 +668,7 @@ result_check () {
done
fi
}
# print match state for emission viewers
tv_updater () {
if [[ -n "$tv" ]]; then
if [[ -n "$game_over" ]]; then
......@@ -674,9 +687,7 @@ tv_updater () {
fi
}
#########
# info
#########
# print player history
info_routine () {
ascii_draw=$PWD/ascii_draw
ascii_font=$PWD/ascii_font
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment