membership check #198

This commit is contained in:
Benny 2023-04-08 12:02:04 +02:00
parent 218b1d5ec9
commit 7bf4331274
No known key found for this signature in database
GPG key ID: 6CD0DBDA5235D481
2 changed files with 9 additions and 3 deletions

View file

@ -33,8 +33,9 @@ OWNER = os.getenv("OWNER", "BennyThink")
# limitation settings
AUTHORIZED_USER: "str" = os.getenv("AUTHORIZED_USER", "")
# membership requires: the format could be username/chat_id of channel or group
REQUIRED_MEMBERSHIP: "str" = os.getenv("REQUIRED_MEMBERSHIP", "")
# membership requires: the format could be username(without @ sign)/chat_id of channel or group.
# You need to add the bot to this group/channel as admin
REQUIRED_MEMBERSHIP: "str" = os.getenv("REQUIRED_MEMBERSHIP", "mikuri520")
# celery related
ENABLE_CELERY = os.getenv("ENABLE_CELERY", False)

View file

@ -84,7 +84,12 @@ def private_use(func):
# TODO bug fix # 198 membership check
if REQUIRED_MEMBERSHIP:
try:
if app.get_chat_member(REQUIRED_MEMBERSHIP, chat_id).status != "member":
if app.get_chat_member(REQUIRED_MEMBERSHIP, chat_id).status not in [
"creator",
"administrator",
"member",
"owner",
]:
raise UserNotParticipant()
else:
logging.info("user %s check passed for group/channel %s.", chat_id, REQUIRED_MEMBERSHIP)