mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2025-01-16 02:42:19 +00:00
functions user_is_creator user_is_admin
This commit is contained in:
parent
aeb9a6a749
commit
307363a4cc
21
bashbot.sh
21
bashbot.sh
@ -10,7 +10,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.6-dev2-8-g649fe44
|
#### $$VERSION$$ v0.6-dev2-10-gdb64978
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -99,7 +99,8 @@ FORWARD_URL=$URL'/forwardMessage'
|
|||||||
INLINE_QUERY=$URL'/answerInlineQuery'
|
INLINE_QUERY=$URL'/answerInlineQuery'
|
||||||
ME_URL=$URL'/getMe'
|
ME_URL=$URL'/getMe'
|
||||||
DELETE_URL=$URL'/deleteMessage'
|
DELETE_URL=$URL'/deleteMessage'
|
||||||
ME=$(curl -s "$ME_URL" | ./JSON.sh/JSON.sh -s | grep '\["result","username"\]' | cut -f 2 | cut -d '"' -f 2)
|
GETMEMBER_URL=$URL'/getChatMember'
|
||||||
|
ME="$(curl -s "$ME_URL" | ./JSON.sh/JSON.sh -s | grep '\["result","username"\]' | cut -f 2 | cut -d '"' -f 2)"
|
||||||
|
|
||||||
|
|
||||||
FILE_URL='https://api.telegram.org/file/bot'$TOKEN'/'
|
FILE_URL='https://api.telegram.org/file/bot'$TOKEN'/'
|
||||||
@ -205,6 +206,11 @@ delete_message() {
|
|||||||
res="$(curl -s "$DELETE_URL" -F "chat_id=$1" -F "message_id=$2")"
|
res="$(curl -s "$DELETE_URL" -F "chat_id=$1" -F "message_id=$2")"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# usage: status="$(get_chat_member_status "chat" "user")"
|
||||||
|
get_chat_member_status() {
|
||||||
|
curl -s "$GETMEMBER_URL" -F "chat_id=$1" -F "user_id=$2" | ./JSON.sh/JSON.sh -s | sed -n -e '/\["result","status"\]/ s/.*\][ \t]"\(.*\)"$/\1/p'
|
||||||
|
}
|
||||||
|
|
||||||
kick_chat_member() {
|
kick_chat_member() {
|
||||||
res="$(curl -s "$KICK_URL" -F "chat_id=$1" -F "user_id=$2")"
|
res="$(curl -s "$KICK_URL" -F "chat_id=$1" -F "user_id=$2")"
|
||||||
}
|
}
|
||||||
@ -217,6 +223,17 @@ leave_chat() {
|
|||||||
res="$(curl -s "$LEAVE_URL" -F "chat_id=$1")"
|
res="$(curl -s "$LEAVE_URL" -F "chat_id=$1")"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user_is_creator() {
|
||||||
|
if [ "$1" == "$2" ] || [ "$(get_chat_member_status "$1" "$2")" == "creator" ]; then return 0; fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
user_is_admin() {
|
||||||
|
local me; me="$(get_chat_member_status "$1" "$2")"
|
||||||
|
if [ "${me}" == "creator" ] || [ "${me}" == "administrator" ]; then return 0; fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
answer_inline_query() {
|
answer_inline_query() {
|
||||||
case "$2" in
|
case "$2" in
|
||||||
"article")
|
"article")
|
||||||
|
@ -4,7 +4,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.6-dev2-9-gf4e277b
|
#### $$VERSION$$ v0.6-dev2-11-gaeb9a6a
|
||||||
#
|
#
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
@ -121,9 +121,11 @@ else
|
|||||||
bashbot_help "${CHAT[ID]}"
|
bashbot_help "${CHAT[ID]}"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
'/leavechat')
|
'/leavechat') # bot leave chat if user is admin in chat
|
||||||
|
if user_is_admin "${CHAT[ID]}" "${USER[ID]}"; then
|
||||||
send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
|
send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
|
||||||
leave_chat "${CHAT[ID]}"
|
leave_chat "${CHAT[ID]}"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
'/kickme')
|
'/kickme')
|
||||||
|
Loading…
Reference in New Issue
Block a user