mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-22 23:45:10 +00:00
first working version with jssh botconfig database
This commit is contained in:
parent
eb4fa6840b
commit
a901cc78d4
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# description: Start or stop telegram-bash-bot
|
# description: Start or stop telegram-bash-bot
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
#### $$VERSION$$ v0.98-dev-2-geb4fa68
|
||||||
# shellcheck disable=SC2009
|
# shellcheck disable=SC2009
|
||||||
# shellcheck disable=SC2181
|
# shellcheck disable=SC2181
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ case "$1" in
|
|||||||
RETVAL=$?
|
RETVAL=$?
|
||||||
;;
|
;;
|
||||||
'stop')
|
'stop')
|
||||||
$runcmd "$start kill"
|
$runcmd "$start stop"
|
||||||
RETVAL=$?
|
RETVAL=$?
|
||||||
;;
|
;;
|
||||||
'status')
|
'status')
|
||||||
|
20
bashbot.sh
20
bashbot.sh
@ -11,7 +11,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.98-dev-0-ga8fe178
|
#### $$VERSION$$ v0.98-dev-2-geb4fa68
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -534,7 +534,8 @@ process_client() {
|
|||||||
if [ -z "${iQUERY[ID]}" ]; then
|
if [ -z "${iQUERY[ID]}" ]; then
|
||||||
process_message "${num}" "${debug}"
|
process_message "${num}" "${debug}"
|
||||||
printf "%s: update received FROM=%s CHAT=%s CMD=%s\n" "$(date)" "${USER[USERNAME]:0:20} (${USER[ID]})"\
|
printf "%s: update received FROM=%s CHAT=%s CMD=%s\n" "$(date)" "${USER[USERNAME]:0:20} (${USER[ID]})"\
|
||||||
"${CHAT[USERNAME]:0:20}${CHAT[TITLE]:0:30} (${CHAT[ID]})" "${MESSAGE:0:30}" >>"${UPDATELOG}"
|
"${CHAT[USERNAME]:0:20}${CHAT[TITLE]:0:30} (${CHAT[ID]})"\
|
||||||
|
"${MESSAGE:0:30}${CAPTION:0:30}${URLS[*]:0:30}" >>"${UPDATELOG}"
|
||||||
else
|
else
|
||||||
process_inline "${num}" "${debug}"
|
process_inline "${num}" "${debug}"
|
||||||
printf "%s: iQuery received FROM=%s iQUERY=%s\n" "$(date)"\
|
printf "%s: iQuery received FROM=%s iQUERY=%s\n" "$(date)"\
|
||||||
@ -934,7 +935,7 @@ if [ "${SOURCE}" != "yes" ]; then
|
|||||||
# internal options only for use from bashbot and developers
|
# internal options only for use from bashbot and developers
|
||||||
case "$1" in
|
case "$1" in
|
||||||
# all these commands need the botname and a working connection
|
# all these commands need the botname and a working connection
|
||||||
"botname"|"outproc"|"start"*|"stop"*|"kill"*|"resume"*|"suspend"*)
|
"botname"|"outproc"|"start"*|"stop"*|"kill"*|"resume"*|"suspend"*|"status")
|
||||||
ME="$(getBotName)"
|
ME="$(getBotName)"
|
||||||
if [ -n "${ME}" ]; then
|
if [ -n "${ME}" ]; then
|
||||||
# ok we have a connection an got botname, save it
|
# ok we have a connection an got botname, save it
|
||||||
@ -949,12 +950,11 @@ if [ "${SOURCE}" != "yes" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
set +x
|
|
||||||
printf "Bot Name: %s\n" "${ME}"
|
printf "Bot Name: %s\n" "${ME}"
|
||||||
SESSION="${ME:-_bot}-startbot"
|
SESSION="${ME:-_bot}-startbot"
|
||||||
BOTPID="$(proclist "${SESSION}")"
|
BOTPID="$(proclist "${SESSION}")"
|
||||||
[ "$1" = "botname" ] && exit
|
[ "$1" = "botname" ] && exit
|
||||||
;&
|
;;&
|
||||||
# used to send output of backgrond and interactive to chats
|
# used to send output of backgrond and interactive to chats
|
||||||
"outproc") # $2 chat_id $3 identifier of job, internal use only!
|
"outproc") # $2 chat_id $3 identifier of job, internal use only!
|
||||||
[ -z "$3" ] && echo "No job identifier" && exit 3
|
[ -z "$3" ] && echo "No job identifier" && exit 3
|
||||||
@ -979,7 +979,8 @@ set +x
|
|||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
# print usage sats
|
# print usage sats
|
||||||
"stats"|'count')
|
"count") echo -e "${RED}Command ${GREY}count${RED} is deprecated, use ${GREY}stats{$RED}instead.${NC}";&
|
||||||
|
"stats")
|
||||||
declare -A STATS
|
declare -A STATS
|
||||||
jssh_readDB_async "STATS" "${COUNTFILE}"
|
jssh_readDB_async "STATS" "${COUNTFILE}"
|
||||||
for MSG in ${!STATS[*]}
|
for MSG in ${!STATS[*]}
|
||||||
@ -1016,10 +1017,10 @@ set +x
|
|||||||
# does what is says
|
# does what is says
|
||||||
"status")
|
"status")
|
||||||
if [ -n "${BOTPID}" ]; then
|
if [ -n "${BOTPID}" ]; then
|
||||||
echo -e "${GREEN}Bot is running.${NC}"
|
echo -e "${GREEN}Bot is running with UID ${RUNUSER}.${NC}"
|
||||||
exit
|
exit
|
||||||
else
|
else
|
||||||
echo -e "${ORANGE}Bot not running.${NC}"
|
echo -e "${ORANGE}Bot not running with UID ${RUNUSER}.${NC}"
|
||||||
exit 5
|
exit 5
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@ -1039,6 +1040,7 @@ set +x
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
# does what it says
|
# does what it says
|
||||||
|
"kill") echo -e "${RED}Command ${GREY}kill${RED} is deprecated, use ${GREY}stop{$RED}instead.${NC}";&
|
||||||
"stop")
|
"stop")
|
||||||
if [ -n "${BOTPID}" ]; then
|
if [ -n "${BOTPID}" ]; then
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
@ -1048,6 +1050,8 @@ set +x
|
|||||||
echo -e "${RED}An error occured while stopping bot.${NC}"
|
echo -e "${RED}An error occured while stopping bot.${NC}"
|
||||||
exit 5
|
exit 5
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo -e "${ORANGE}Bot not running with UID ${RUNUSER}.${NC}"
|
||||||
fi
|
fi
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
|
Loading…
Reference in New Issue
Block a user