telegram-bot-bash/bin/bashbot_stats.sh

75 lines
1.8 KiB
Bash
Raw Normal View History

2020-12-23 20:10:17 +00:00
#!/bin/bash
#===============================================================================
#
2020-12-24 10:41:40 +00:00
# FILE: bin/bashbot_stats.sh
2020-12-23 20:10:17 +00:00
#
2020-12-25 17:43:36 +00:00
# USAGE: bashbot_stats.sh [-h|--help] [debug]
2020-12-23 20:10:17 +00:00
#
# DESCRIPTION: output bashbot user stats
#
# OPTIONS: -h - display short help
# --help - this help
#
# Set BASHBOT_HOME to your installation directory
#
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
# CREATED: 23.12.2020 20:34
#
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
2020-12-23 20:10:17 +00:00
#===============================================================================
####
# parse args
case "$1" in
"-h"*)
2020-12-23 20:20:35 +00:00
echo "usage: send_message [-h|--help] [debug]"
2020-12-23 20:10:17 +00:00
exit 1
;;
'--h'*)
sed -n '3,/###/p' <"$0"
exit 1
;;
esac
2020-12-25 17:43:36 +00:00
# set bashbot environment
2020-12-23 20:10:17 +00:00
# shellcheck disable=SC1090
2020-12-25 17:43:36 +00:00
source "${0%/*}/bashbot_env.inc.sh" "$1"
2020-12-23 20:10:17 +00:00
####
# ready, do stuff here -----
echo -e "${GREEN}Hi I'm ${BOT_NAME}.${NC}"
2020-12-23 20:10:17 +00:00
declare -A STATS
jssh_readDB_async "STATS" "${COUNTFILE}"
for MSG in ${!STATS[*]}
do
[[ ! "${MSG}" =~ ^[0-9-]*$ ]] && continue
(( USERS++ ))
done
for MSG in ${STATS[*]}
do
(( MESSAGES+=MSG ))
done
if [ "${USERS}" != "" ]; then
echo -e "${GREY}A total of ${NC}${MESSAGES}${GREY} messages from ${NC}${USERS}${GREY} users are processed.${NC}"
else
echo -e "${ORANGE}No one used your bot so far ...${NC}"
fi
jssh_readDB_async "STATS" "${BLOCKEDFILE}"
for MSG in ${!STATS[*]}
do
[[ ! "${MSG}" =~ ^[0-9-]*$ ]] && continue
(( BLOCKS++ ))
done
if [ "${BLOCKS}" != "" ]; then
echo -e "${ORANGE}${BLOCKS} user(s) are blocked:${NC}${GREY}"
sort -r "${BLOCKEDFILE}.jssh"
echo -e "${NC}\c"
else
echo -e "${GREEN}No user is blocked currently ...${NC}"
fi
# show user created bot stats
_exec_if_function my_bashbot_stats "$@"