telegram-bot-bash/bin/bashbot_stats.sh

63 lines
1.6 KiB
Bash
Raw Normal View History

2020-12-23 20:10:17 +00:00
#!/bin/bash
2021-01-21 08:22:14 +00:00
# shellcheck disable=SC1090,SC2034
2020-12-23 20:10:17 +00:00
#===============================================================================
#
2020-12-24 10:41:40 +00:00
# FILE: bin/bashbot_stats.sh
2020-12-23 20:10:17 +00:00
#
2021-01-09 21:14:44 +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
#
2021-01-22 20:22:16 +00:00
#### $$VERSION$$ v1.32-dev-6-g2832801
2020-12-23 20:10:17 +00:00
#===============================================================================
2020-12-25 17:43:36 +00:00
# set bashbot environment
source "${0%/*}/bashbot_env.inc.sh" "$1"
2021-01-22 20:22:16 +00:00
[ -n "$1" ] && print_help "$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 "$@"