2019-05-12 15:51:52 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# file: modules/chatMember.sh
|
|
|
|
# do not edit, this file will be overwritten on update
|
|
|
|
|
|
|
|
# This file is public domain in the USA and all free countries.
|
|
|
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
|
|
|
#
|
2020-11-03 11:21:11 +00:00
|
|
|
#### $$VERSION$$ v1.2-dev-14-g6ec00d4
|
2020-06-14 18:56:46 +00:00
|
|
|
|
|
|
|
# will be automatically sourced from bashbot
|
2020-05-14 17:47:37 +00:00
|
|
|
|
|
|
|
# source once magic, function named like file
|
|
|
|
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
|
2019-05-12 15:51:52 +00:00
|
|
|
|
|
|
|
LEAVE_URL=$URL'/leaveChat'
|
|
|
|
KICK_URL=$URL'/kickChatMember'
|
|
|
|
UNBAN_URL=$URL'/unbanChatMember'
|
|
|
|
GETMEMBER_URL=$URL'/getChatMember'
|
|
|
|
|
|
|
|
# usage: status="$(get_chat_member_status "chat" "user")"
|
|
|
|
get_chat_member_status() {
|
2020-05-14 06:04:19 +00:00
|
|
|
sendJson "$1" '"user_id":'"$2"'' "$GETMEMBER_URL"
|
2019-05-12 15:51:52 +00:00
|
|
|
# shellcheck disable=SC2154
|
|
|
|
JsonGetString '"result","status"' <<< "$res"
|
|
|
|
}
|
|
|
|
|
|
|
|
kick_chat_member() {
|
|
|
|
sendJson "$1" 'user_id: '"$2"'' "$KICK_URL"
|
|
|
|
}
|
|
|
|
|
|
|
|
unban_chat_member() {
|
|
|
|
sendJson "$1" 'user_id: '"$2"'' "$UNBAN_URL"
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_chat() {
|
|
|
|
sendJson "$1" "" "$LEAVE_URL"
|
|
|
|
}
|
|
|
|
|
|
|
|
user_is_creator() {
|
2020-06-28 14:40:35 +00:00
|
|
|
# empty is false ...
|
|
|
|
[[ "${1:--}" == "${2:-+}" || "$(get_chat_member_status "$1" "$2")" == "creator" ]] && return 0
|
2019-05-12 15:51:52 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
user_is_admin() {
|
2020-06-28 14:40:35 +00:00
|
|
|
[ "${1:--}" == "${2:-+}" ] && return 0
|
2020-05-16 06:49:36 +00:00
|
|
|
user_is_botadmin "$2" && return 0
|
2020-06-28 14:40:35 +00:00
|
|
|
local me; me="$(get_chat_member_status "$1" "$2")"
|
|
|
|
[[ "${me}" =~ ^creator$|^administrator$ ]] && return 0
|
2019-05-12 15:51:52 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
user_is_botadmin() {
|
2020-06-28 14:40:35 +00:00
|
|
|
local admin; admin="$(getConfigKey "botadmin")"; [ -z "${admin}" ] && return 1
|
|
|
|
[[ "${admin}" == "${1}" || "${admin}" == "${2}" ]] && return 0
|
|
|
|
#[[ "${admin}" = "@*" ]] && [[ "${admin}" = "${2}" ]] && return 0
|
2020-06-27 16:32:50 +00:00
|
|
|
if [ "${admin}" = "?" ]; then setConfigKey "botadmin" "${1:-?}"; return 0; fi
|
2019-05-12 15:51:52 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
user_is_allowed() {
|
2020-05-14 18:33:30 +00:00
|
|
|
[ -z "$1" ] && return 1
|
2020-11-03 11:21:11 +00:00
|
|
|
# user can do everything
|
|
|
|
grep -F -xq "$1:*:*" <"${BOTACL}" && return 0
|
|
|
|
[ -z "$2" ] && return 1
|
|
|
|
# user is allowed todo one action in every chat
|
|
|
|
grep -F -xq "$1:$2:*" <"${BOTACL}" && return 0
|
|
|
|
# all users are allowed to do one action in every chat
|
|
|
|
grep -F -xq "ALL:$2:*" <"${BOTACL}" && return 0
|
|
|
|
[ -z "$3" ] && return 1
|
|
|
|
# user is allowed to do one action in one chat
|
|
|
|
grep -F -xq "$1:$2:$3" <"${BOTACL}" && return 0
|
|
|
|
# all users are allowed to do one action in one chat
|
|
|
|
grep -F -xq "ALL:$2:$3" <"${BOTACL}" && return 0
|
|
|
|
return 1
|
2019-05-12 15:51:52 +00:00
|
|
|
}
|