new example command /unpin, fix user_is_allowed

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-14 20:23:18 +01:00
parent 5f602a9a14
commit e13b9eb940
4 changed files with 13 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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}"
;;