Ajout nouveaux modules CALCEND et LEMO

This commit is contained in:
Echolib 2021-09-03 08:39:28 +02:00 committed by Adrien Bourmault
parent 41b1c03ef7
commit ffbc11c74c
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
1 changed files with 62 additions and 12 deletions

View File

@ -34,7 +34,7 @@ DIGIT=(zéro un deux trois quatre cinq six sept huit neuf dix)
# **************************************************************************** # ****************************************************************************
# Loops 10 times (should be enough) to check if a TARGET number is in INPUT # Generate a number that is not in INPUT. Loop 10 times (should be enough)
GENERATE__NOTIN() { GENERATE__NOTIN() {
for i in {1..10} for i in {1..10}
do do
@ -61,8 +61,8 @@ TARGET=`echo "$INPUT" | head -c $PLACE | tail -c 1`
GENERATE__NOTIN GENERATE__NOTIN
NAME+="-$FALSENBR-$TARGET" NAME+="-$FALSENBR-$TARGET"
NEWINPUT=${INPUT//$TARGET/$FALSENBR} NEWINPUT=${INPUT//$TARGET/$FALSENBR}
INSTRUCTIONS1="Recopiez ce nombre"
INSTRUCTIONS2="en changeant les ${DIGITS[FALSENBR]} en ${DIGITS[TARGET]}" INSTRUCTIONS2="en changeant les ${DIGITS[FALSENBR]} en ${DIGITS[TARGET]}"
INSTRUCTIONS1="Recopiez"
} }
@ -81,14 +81,14 @@ if (( $RFL == 1 ));then
ADDNBR="${INPUT:0:1}" ADDNBR="${INPUT:0:1}"
NAME+="_FIRST" NAME+="_FIRST"
NEWINPUT=${NEWINPUT:0:$LENINPUT-1} # Do not show first INPUT NBR NEWINPUT=${NEWINPUT:0:$LENINPUT-1} # Do not show first INPUT NBR
INSTRUCTIONS1="Écrivez le chiffre ${DIGIT[$ADDNBR]} puis" INSTRUCTIONS1="Écrivez le chiffre ${DIGIT[$ADDNBR]}"
INSTRUCTIONS2="Recopiez de DROITE à GAUCHE ←" INSTRUCTIONS2="et recopiez de DROITE à GAUCHE ←"
else else
ADDNBR="${INPUT:$LENINPUT-1:1}" ADDNBR="${INPUT:$LENINPUT-1:1}"
NAME+="_LAST" NAME+="_LAST"
NEWINPUT=${NEWINPUT:1:$LENINPUT-1} # Do not show last INPUT NBR NEWINPUT=${NEWINPUT:1:$LENINPUT-1} # Do not show last INPUT NBR
INSTRUCTIONS1="Recopiez de DROITE à GAUCHE ←" INSTRUCTIONS1="Recopiez de DROITE à GAUCHE ←"
INSTRUCTIONS2="Terminez par le chiffre ${DIGIT[$ADDNBR]}" INSTRUCTIONS2="et terminez par le chiffre ${DIGIT[$ADDNBR]}"
fi fi
NAME+="-$ADDNBR" NAME+="-$ADDNBR"
} }
@ -110,7 +110,7 @@ do
NEWINPUT="$NEWINPUT${INPUT:$i:1}" NEWINPUT="$NEWINPUT${INPUT:$i:1}"
done done
NAME+="-$FALSENBR" NAME+="-$FALSENBR"
INSTRUCTIONS1="Recopiez sans les ${DIGITS[FALSENBR]}" INSTRUCTIONS1="Recopiez ce nombre sans les ${DIGITS[FALSENBR]}"
} }
@ -124,25 +124,74 @@ RC=`seq 1 2 | sort -R | head -n 1` # 1 = - | 2 = +
if (( $RC == 1 ));then if (( $RC == 1 ));then
FALSENBR=`seq $TARGET 10 | sort -R | head -n 1` FALSENBR=`seq $TARGET 10 | sort -R | head -n 1`
RESUME=$(( FALSENBR - TARGET )) RESUME=$(( FALSENBR - TARGET ))
INSTRUCTIONS1="Calculez: $FALSENBR moins $RESUME. Copiez..." INSTRUCTIONS1="Calculez: ${DIGIT[FALSENBR]} moins ${DIGIT[RESUME]} et copiez"
NAME="CALCULM-$FALSENBR-$RESUME" NAME="CALCULM-$FALSENBR-$RESUME"
else else
FALSENBR=`seq 1 4 | sort -R | head -n 1` FALSENBR=`seq 1 4 | sort -R | head -n 1`
if (( $FALSENBR <= $TARGET ));then if (( $FALSENBR <= $TARGET ));then
RESULT=$(( TARGET + FALSENBR )) RESULT=$(( TARGET + FALSENBR ))
RESUME=$(( TARGET - FALSENBR )) RESUME=$(( TARGET - FALSENBR ))
INSTRUCTIONS1="Calculez: ${DIGIT[FALSENBR]} + ${DIGIT[RESUME]}. Copiez..." INSTRUCTIONS1="Calculez: ${DIGIT[FALSENBR]} plus ${DIGIT[RESUME]} et copiez"
NAME="CALCULP-$FALSENBR-$RESUME" NAME="CALCULP-$FALSENBR-$RESUME"
else else
RESULT=$(( FALSENBR - TARGET )) RESULT=$(( FALSENBR - TARGET ))
RESUME=$(( TARGET - RESULT )) RESUME=$(( TARGET - RESULT ))
INSTRUCTIONS1="Calculez: ${DIGIT[RESULT]} + ${DIGIT[RESUME]}. Copiez..." INSTRUCTIONS1="Calculez: ${DIGIT[RESULT]} plus ${DIGIT[RESUME]} et copiez"
NAME="CALCULP-$RESULT-$RESUME" NAME="CALCULP-$RESULT-$RESUME"
fi fi
fi fi
INSTRUCTIONS2="...en remplaçant chaque X par la somme" INSTRUCTIONS2="en remplaçant chaque X par la somme"
} }
# Sum 2 LAST numbers. Hide LAST or BEFORE LAST
CALCEND() {
END1=${INPUT:$LENINPUT-2:1}
END2=${INPUT:$LENINPUT-1:1}
ENDS=$(( END1 + END2 ))
REND=`seq 1 2 | sort -R | head -n 1`
if (( $REND == 1 ));then
# Hide LAST
NEWINPUT=${INPUT:0:LENINPUT-1}X
NAME="END-${END1}X"
else
# Hide BEFORE LAST
NEWINPUT=${INPUT:0:LENINPUT-2}X$END2
NAME="END-X$END2"
fi
INSTRUCTIONS1="La somme des 2 derniers chiffres est $ENDS"
INSTRUCTIONS2="Copiez en remplaçant X par sa valeur"
}
# Replace 2 X (smaller > bigger | bigger > smaller)
LEMO() {
MAXNBR=${INPUT:0:1}
MINNBR=${INPUT:0:1}
for i in `seq 1 $((LENINPUT-1))`
do
(( ${INPUT:$i:1} > $MAXNBR )) \
&& MAXNBR=${INPUT:$i:1}
(( ${INPUT:$i:1} < $MINNBR )) \
&& MINNBR=${INPUT:$i:1}
done
for i in `seq 0 $((LENINPUT-1))`
do
if (( ${INPUT:$i:1} == $MINNBR ));then
INSTRUCTIONS1="Remplacez les X par ${DIGIT[MAXNBR]} et ${DIGIT[MINNBR]}"
INSTRUCTIONS2="! le plus PETIT en premier"
NAME="LEMO-$MINNBR-$MAXNBR"
break
elif (( ${INPUT:$i:1} == $MAXNBR ));then
INSTRUCTIONS1="Remplacez les X par ${DIGIT[MINNBR]} et ${DIGIT[MAXNBR]}"
INSTRUCTIONS2="! Le plus GRAND en premier"
NAME="LEMO-$MAXNBR-$MINNBR"
break
fi
done
NEWINPUT=`echo $INPUT | sed "s/$MINNBR/X/"`
NEWINPUT=`echo $NEWINPUT | sed "s/$MAXNBR/X/"`
}
# **************************************************************************** # ****************************************************************************
# #
@ -150,12 +199,13 @@ INSTRUCTIONS2="...en remplaçant chaque X par la somme"
# #
# **************************************************************************** # ****************************************************************************
MODULES=(CALCUL NOTIN REPLACE REVERSE) MODULES=(CALCUL CALCEND LEMO NOTIN REPLACE REVERSE)
RMODULE=`seq 0 $(( ${#MODULES[@]} - 1)) | sort -R | head -n 1` RMODULE=`seq 0 $(( ${#MODULES[@]} - 1)) | sort -R | head -n 1`
eval "${MODULES[RMODULE]}" eval "${MODULES[RMODULE]}"
TEXT="$NEWINPUT" TEXT="$NEWINPUT"
CHAPRILURI="/var/lib/ejabberd/chapril_captchas_experimental/$(date "+%Y-%m-%d-%H%M%S")_${NAME}_${INPUT}.png" DATE="$(date "+%Y-%m-%d-%H%M%S")"
CHAPRILURI=/var/lib/ejabberd/chapril_captchas/${DATE}_${NAME}_${INPUT}.png
convert -size 300x70 xc:none -pointsize 20 \ convert -size 300x70 xc:none -pointsize 20 \
\( -clone 0 -fill black \ \( -clone 0 -fill black \