modules: new functions set_chat_title set_chat_description

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-10 20:30:56 +01:00
parent d521d35815
commit e1f209783f

View File

@ -5,26 +5,31 @@
# 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$$ v1.25-dev-14-g2fe6d4b #### $$VERSION$$ v1.30-dev-0-gd521d35
# will be automatically sourced from bashbot # will be automatically sourced from bashbot
# source once magic, function named like file # source once magic, function named like file
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }" eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
LEAVE_URL=${URL}'/leaveChat' LEAVE_URL="${URL}"'/leaveChat'
KICK_URL=${URL}'/kickChatMember' KICK_URL="${URL}"'/kickChatMember'
UNBAN_URL=${URL}'/unbanChatMember' UNBAN_URL="${URL}"'/unbanChatMember'
GETMEMBER_URL=${URL}'/getChatMember' GETMEMBER_URL=${URL}'/getChatMember'
# usage: status="$(get_chat_member_status "chat" "user")" # manage chat functions -------
# $1 chat # $2 user # $1 chat, $2 title
get_chat_member_status() { set_chat_title() {
sendJson "$1" '"user_id":'"$2"'' "${GETMEMBER_URL}" sendJson "$1" '"title": "'"$2"'"' "${URL}/setChatTitle"
# shellcheck disable=SC2154
JsonGetString '"result","status"' <<< "${res}"
} }
# $1 chat, $2 title
set_chat_description() {
sendJson "$1" '"description": "'"$2"'"' "${URL}/setChatDescription"
}
# manage chat member functions -------
kick_chat_member() { kick_chat_member() {
sendJson "$1" 'user_id: '"$2"'' "${KICK_URL}" sendJson "$1" 'user_id: '"$2"'' "${KICK_URL}"
} }
@ -37,6 +42,17 @@ leave_chat() {
sendJson "$1" "" "${LEAVE_URL}" sendJson "$1" "" "${LEAVE_URL}"
} }
# bashbot specific functions ---------
# usage: status="$(get_chat_member_status "chat" "user")"
# $1 chat # $2 user
get_chat_member_status() {
sendJson "$1" '"user_id":'"$2"'' "${GETMEMBER_URL}"
# shellcheck disable=SC2154
JsonGetString '"result","status"' <<< "${res}"
}
user_is_creator() { user_is_creator() {
# empty is false ... # empty is false ...
[[ "${1:--}" == "${2:-+}" || "$(get_chat_member_status "$1" "$2")" == "creator" ]] && return 0 [[ "${1:--}" == "${2:-+}" || "$(get_chat_member_status "$1" "$2")" == "creator" ]] && return 0