mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-22 15:35:09 +00:00
optimize update processing, fix LEFTMEMBER
This commit is contained in:
parent
4b18757779
commit
8991cc98f0
37
bashbot.sh
37
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-24-g4990f70
|
#### $$VERSION$$ v0.98-dev-25-g4b18757
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -702,11 +702,13 @@ process_message() {
|
|||||||
USER[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","first_name"]}")"
|
USER[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","first_name"]}")"
|
||||||
USER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","last_name"]}")"
|
USER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","last_name"]}")"
|
||||||
USER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","from","username"]}")"
|
USER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","from","username"]}")"
|
||||||
|
# set real name as username if empty
|
||||||
|
[ -z "${USER[USERNAME]}" ] && USER[USERNAME]="${USER[FIRST_NAME]} ${USER[LAST_NAME]}"
|
||||||
|
|
||||||
# in reply to message from
|
# in reply to message from
|
||||||
REPLYTO=( )
|
REPLYTO=( )
|
||||||
REPLYTO[UID]="${UPD["result",${num},"message","reply_to_message","from","id"]}"
|
if grep -qs -e '\["result",'"${num}"',"message","reply_to_message"' <<<"${UPDATE}"; then
|
||||||
if [ -n "${REPLYTO[UID]}" ]; then
|
REPLYTO[UID]="${UPD["result",${num},"message","reply_to_message","from","id"]}"
|
||||||
REPLYTO[0]="$(JsonDecode "${UPD["result",${num},"message","reply_to_message","text"]}")"
|
REPLYTO[0]="$(JsonDecode "${UPD["result",${num},"message","reply_to_message","text"]}")"
|
||||||
REPLYTO[ID]="${UPD["result",${num},"message","reply_to_message","message_id"]}"
|
REPLYTO[ID]="${UPD["result",${num},"message","reply_to_message","message_id"]}"
|
||||||
REPLYTO[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","reply_to_message","from","first_name"]}")"
|
REPLYTO[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","reply_to_message","from","first_name"]}")"
|
||||||
@ -716,8 +718,8 @@ process_message() {
|
|||||||
|
|
||||||
# forwarded message from
|
# forwarded message from
|
||||||
FORWARD=( )
|
FORWARD=( )
|
||||||
FORWARD[UID]="${UPD["result",${num},"message","forward_from","id"]}"
|
if grep -qs -e '\["result",'"${num}"',"message","forward_from"' <<<"${UPDATE}"; then
|
||||||
if [ -n "${FORWARD[UID]}" ]; then
|
FORWARD[UID]="${UPD["result",${num},"message","forward_from","id"]}"
|
||||||
FORWARD[ID]="${MESSAGE[ID]}" # same as message ID
|
FORWARD[ID]="${MESSAGE[ID]}" # same as message ID
|
||||||
FORWARD[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","forward_from","first_name"]}")"
|
FORWARD[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","forward_from","first_name"]}")"
|
||||||
FORWARD[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","forward_from","last_name"]}")"
|
FORWARD[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","forward_from","last_name"]}")"
|
||||||
@ -725,6 +727,7 @@ process_message() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# get file URL from telegram
|
# get file URL from telegram
|
||||||
|
URLS=()
|
||||||
if grep -qs -e '\["result",'"${num}"',"message",".*,"file_id"\]' <<<"${UPDATE}"; then
|
if grep -qs -e '\["result",'"${num}"',"message",".*,"file_id"\]' <<<"${UPDATE}"; then
|
||||||
URLS[AUDIO]="$(get_file "${UPD["result",${num},"message","audio","file_id"]}")"
|
URLS[AUDIO]="$(get_file "${UPD["result",${num},"message","audio","file_id"]}")"
|
||||||
URLS[DOCUMENT]="$(get_file "${UPD["result",${num},"message","document","file_id"]}")"
|
URLS[DOCUMENT]="$(get_file "${UPD["result",${num},"message","document","file_id"]}")"
|
||||||
@ -735,8 +738,8 @@ process_message() {
|
|||||||
fi
|
fi
|
||||||
# Contact
|
# Contact
|
||||||
CONTACT=( )
|
CONTACT=( )
|
||||||
CONTACT[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","contact","first_name"]}")"
|
if grep -qs -e '\["result",'"${num}"',"message","contact"' <<<"${UPDATE}"; then
|
||||||
if [ -n "${CONTACT[FIRST_NAME]}" ]; then
|
CONTACT[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","contact","first_name"]}")"
|
||||||
CONTACT[USER_ID]="$(JsonDecode "${UPD["result",${num},"message","contact","user_id"]}")"
|
CONTACT[USER_ID]="$(JsonDecode "${UPD["result",${num},"message","contact","user_id"]}")"
|
||||||
CONTACT[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","contact","last_name"]}")"
|
CONTACT[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","contact","last_name"]}")"
|
||||||
CONTACT[NUMBER]="${UPD["result",${num},"message","contact","phone_number"]}"
|
CONTACT[NUMBER]="${UPD["result",${num},"message","contact","phone_number"]}"
|
||||||
@ -745,8 +748,8 @@ process_message() {
|
|||||||
|
|
||||||
# vunue
|
# vunue
|
||||||
VENUE=( )
|
VENUE=( )
|
||||||
VENUE[TITLE]="$(JsonDecode "${UPD["result",${num},"message","venue","title"]}")"
|
if grep -qs -e '\["result",'"${num}"',"message","contact"' <<<"${UPDATE}"; then
|
||||||
if [ -n "${VENUE[TITLE]}" ]; then
|
VENUE[TITLE]="$(JsonDecode "${UPD["result",${num},"message","venue","title"]}")"
|
||||||
VENUE[ADDRESS]="$(JsonDecode "${UPD["result",${num},"message","venue","address"]}")"
|
VENUE[ADDRESS]="$(JsonDecode "${UPD["result",${num},"message","venue","address"]}")"
|
||||||
VENUE[LONGITUDE]="${UPD["result",${num},"message","venue","location","longitude"]}"
|
VENUE[LONGITUDE]="${UPD["result",${num},"message","venue","location","longitude"]}"
|
||||||
VENUE[LATITUDE]="${UPD["result",${num},"message","venue","location","latitude"]}"
|
VENUE[LATITUDE]="${UPD["result",${num},"message","venue","location","latitude"]}"
|
||||||
@ -762,8 +765,8 @@ process_message() {
|
|||||||
|
|
||||||
# service messages
|
# service messages
|
||||||
SERVICE=( ); NEWMEMBER=( )
|
SERVICE=( ); NEWMEMBER=( )
|
||||||
SERVICE[NEWMEMBER]="${UPD["result",${num},"message","new_chat_member","id"]}"
|
if grep -qs -e '\["result",'"${num}"',"message","new_chat_member' <<<"${UPDATE}"; then
|
||||||
if [ -n "${SERVICE[NEWMEMBER]}" ]; then
|
SERVICE[NEWMEMBER]="${UPD["result",${num},"message","new_chat_member","id"]}"
|
||||||
NEWMEMBER[ID]="${SERVICE[NEWMEMBER]}"
|
NEWMEMBER[ID]="${SERVICE[NEWMEMBER]}"
|
||||||
NEWMEMBER[FIRST_NAME]="${UPD["result",${num},"message","new_chat_member","first_name"]}"
|
NEWMEMBER[FIRST_NAME]="${UPD["result",${num},"message","new_chat_member","first_name"]}"
|
||||||
NEWMEMBER[LAST_NAME]="${UPD["result",${num},"message","new_chat_member","last_name"]}"
|
NEWMEMBER[LAST_NAME]="${UPD["result",${num},"message","new_chat_member","last_name"]}"
|
||||||
@ -771,13 +774,13 @@ process_message() {
|
|||||||
NEWMEMBER[ISBOT]="${UPD["result",${num},"message","new_chat_member","is_bot"]}"
|
NEWMEMBER[ISBOT]="${UPD["result",${num},"message","new_chat_member","is_bot"]}"
|
||||||
MESSAGE[0]="/new_chat_member ${NEWMEMBER[USERNAME]:=${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]}}"
|
MESSAGE[0]="/new_chat_member ${NEWMEMBER[USERNAME]:=${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]}}"
|
||||||
fi
|
fi
|
||||||
SERVICE[LEFTMEMBER]="${UPD["result",${num},"message","left_chat_member","id"]}"
|
if grep -qs -e '\["result",'"${num}"',"message","left_chat_member' <<<"${UPDATE}"; then
|
||||||
if [ -n "${SERVICE[LEFTMEMBER]}" ]; then
|
SERVICE[LEFTMEMBER]="${UPD["result",${num},"message","left_chat_member","id"]}"
|
||||||
LEFTMEBER[ID]="${SERVICE[LEFTMEBER]}"
|
LEFTMEMBER[ID]="${SERVICE[LEFTMEBER]}"
|
||||||
LEFTMEBER[FIRST_NAME]="${UPD["result",${num},"message","left_chat_member","first_name"]}"
|
LEFTMEMBER[FIRST_NAME]="${UPD["result",${num},"message","left_chat_member","first_name"]}"
|
||||||
LEFTMEBER[LAST_NAME]="${UPD["result",${num},"message","left_chat_member","last_name"]}"
|
LEFTMEMBER[LAST_NAME]="${UPD["result",${num},"message","left_chat_member","last_name"]}"
|
||||||
LEFTMEBER[USERNAME]="${UPD["result",${num},"message","left_chat_member","username"]}"
|
LEFTMEBER[USERNAME]="${UPD["result",${num},"message","left_chat_member","username"]}"
|
||||||
LEFTMEBER[ISBOT]="${UPD["result",${num},"message","left_chat_member","is_bot"]}"
|
LEFTMEMBER[ISBOT]="${UPD["result",${num},"message","left_chat_member","is_bot"]}"
|
||||||
MESSAGE[0]="/left_chat_member ${LEFTMEMBER[USERNAME]:=${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]}}"
|
MESSAGE[0]="/left_chat_member ${LEFTMEMBER[USERNAME]:=${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]}}"
|
||||||
fi
|
fi
|
||||||
SERVICE[NEWTILE]="${UPD["result",${num},"message","new_chat_title"]}"
|
SERVICE[NEWTILE]="${UPD["result",${num},"message","new_chat_title"]}"
|
||||||
|
@ -160,11 +160,11 @@ Evertime a Message is received, you can read incoming data using the following v
|
|||||||
* ```${NEWMEMBER[USERNAME]```: New user's username
|
* ```${NEWMEMBER[USERNAME]```: New user's username
|
||||||
* ```${NEWMEMBER[ISBOT]```: New user is a bot
|
* ```${NEWMEMBER[ISBOT]```: New user is a bot
|
||||||
* ```${SERVICE[LEFTMEMBER]```: Id of user left
|
* ```${SERVICE[LEFTMEMBER]```: Id of user left
|
||||||
* ```${LEFTMEBER[ID]```: New user's id
|
* ```${LEFTMEMBER[ID]```: New user's id
|
||||||
* ```${LEFTMEBER[FIRST_NAME]```: New user's first name
|
* ```${LEFTMEMBER[FIRST_NAME]```: New user's first name
|
||||||
* ```${LEFTMEBER[LAST_NAME]```: New user's last name
|
* ```${LEFTMEMBER[LAST_NAME]```: New user's last name
|
||||||
* ```${LEFTMEBER[USERNAME]```: New user's username
|
* ```${LEFTMEMBER[USERNAME]```: New user's username
|
||||||
* ```${LEFTMEBER[ISBOT]```: New user is a bot
|
* ```${LEFTMEMBER[ISBOT]```: New user is a bot
|
||||||
* ```${SERVICE[NEWTILE]```: Text of new title
|
* ```${SERVICE[NEWTILE]```: Text of new title
|
||||||
* ```${SERVICE[NEWPHOTO]```: New Chat Picture array
|
* ```${SERVICE[NEWPHOTO]```: New Chat Picture array
|
||||||
* ```${SERVICE[PINNED]```: Pinned Message structure
|
* ```${SERVICE[PINNED]```: Pinned Message structure
|
||||||
@ -261,5 +261,5 @@ send_action "${CHAT[ID]}" "action"
|
|||||||
#### [Prev Create Bot](1_firstbot.md)
|
#### [Prev Create Bot](1_firstbot.md)
|
||||||
#### [Next Advanced Usage](3_advanced.md)
|
#### [Next Advanced Usage](3_advanced.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.98-dev-11-g6563891
|
#### $$VERSION$$ v0.98-dev-25-g4b18757
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user