From e13b9eb9407c85ea4bfe971f1da1ee62d0599b80 Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Thu, 14 Jan 2021 20:23:18 +0100 Subject: [PATCH] new example command /unpin, fix user_is_allowed --- doc/3_advanced.md | 3 ++- doc/6_reference.md | 7 ++++--- modules/chatMember.sh | 3 ++- mycommands.sh | 6 +++++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/doc/3_advanced.md b/doc/3_advanced.md index e16359f..6189159 100644 --- a/doc/3_advanced.md +++ b/doc/3_advanced.md @@ -62,6 +62,7 @@ You must use the function `user_is_allowed` to check if a user has the capabilit # GLOBAL commands start here, only edit messages '/start'*) user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*." + # true if: user is botadmin, user is group admin, user is allowed if user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then bot_help "${CHAT[ID]}" else @@ -301,5 +302,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob #### [Prev Getting started](2_usage.md) #### [Next Expert Use](4_expert.md) -#### $$VERSION$$ v1.25-dev-23-g8be95a3 +#### $$VERSION$$ v1.30-dev-9-g5f602a9 diff --git a/doc/6_reference.md b/doc/6_reference.md index 129fcf3..46876c7 100644 --- a/doc/6_reference.md +++ b/doc/6_reference.md @@ -422,9 +422,10 @@ fi *See also [Chat Member](https://core.telegram.org/bots/api/#chatmember)* ##### user_is_allowed -Bashbot supports User Access Control, see [Advanced Usage](3_advanced.md) +`uers_is_allowed` checks if: user id botadmin, user is group admin or user is allowed to execute action.. +Allowed actions are configured as User Access Control rules, see [Advanced Usage](3_advanced.md) -*usage:* user_is_allowed "${USER[ID]}" "what" "${CHAT[ID]}" +*usage:* user_is_allowed "${USER[ID]}" "action" "${CHAT[ID]}" *example:* ```bash @@ -1219,5 +1220,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca #### [Prev Best Practice](5_practice.md) #### [Next Notes for Developers](7_develop.md) -#### $$VERSION$$ v1.30-dev-1-ge1f2097 +#### $$VERSION$$ v1.30-dev-9-g5f602a9 diff --git a/modules/chatMember.sh b/modules/chatMember.sh index e175c80..879bc85 100644 --- a/modules/chatMember.sh +++ b/modules/chatMember.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v1.30-dev-4-gf573d63 +#### $$VERSION$$ v1.30-dev-9-g5f602a9 # will be automatically sourced from bashbot @@ -112,6 +112,7 @@ user_is_botadmin() { # $1 user # $2 key # $3 chat user_is_allowed() { [ -z "$1" ] && return 1 + user_is_admin "$1" && return 0 # user can do everything grep -F -xq "$1:*:*" <"${BOTACL}" && return 0 [ -z "$2" ] && return 1 diff --git a/mycommands.sh b/mycommands.sh index a3ac750..b1bf008 100644 --- a/mycommands.sh +++ b/mycommands.sh @@ -13,7 +13,7 @@ # License: WTFPLv2 http://www.wtfpl.net/txt/copying/ # Author: KayM (gnadelwartz), kay@rrr.de # -#### $$VERSION$$ v1.25-dev-41-g37e4539 +#### $$VERSION$$ v1.30-dev-9-g5f602a9 ####################################################### # shellcheck disable=SC1117 @@ -124,6 +124,10 @@ else case "${MESSAGE}" in ################## # example commands, replace thm by your own + '/unpin'*) # unpin all messages if (bot)admin or allowed for user + user_is_allowed "${USER[ID]}" "unpin" "${CHAT[ID]}" &&\ + unpinall_chat_messages "${CHAT[ID]}" + ;; '/echo'*) # example echo command send_normal_message "${CHAT[ID]}" "${MESSAGE}" ;;