From b032d2407b765de971fda4855743643b31e37d39 Mon Sep 17 00:00:00 2001 From: madawei2699 Date: Sun, 19 Nov 2023 10:03:59 +0800 Subject: [PATCH] u --- app/server.py | 6 +++++- app/user.py | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/server.py b/app/server.py index 5f630805..eaf413af 100644 --- a/app/server.py +++ b/app/server.py @@ -13,7 +13,7 @@ from app.daily_hot_news import build_all_news_block from app.gpt import get_answer_from_chatGPT, get_answer_from_llama_file, get_answer_from_llama_web, get_text_from_whisper, get_voice_file_from_text, index_cache_file_dir from app.rate_limiter import RateLimiter -from app.user import get_user, is_premium_user, update_message_token_usage +from app.user import get_user, is_premium_user, is_active_user, update_message_token_usage from app.util import md5 class Config: @@ -253,6 +253,10 @@ def handle_mentions(event, say, logger): user = event["user"] thread_ts = event["ts"] + if not is_active_user(user): + say(f'<@{user}>, 你的账户未激活,请添加微信 improve365_cn 联系管理员激活你的账户后再试用。', thread_ts=thread_ts) + return + if not limiter.allow_request(user): if not is_premium_user(user): say(f'<@{user}>, you have reached the limit of {limiter_message_per_user} messages {limiter_time_period / 3600} hour, please subscribe to our Premium plan to support our service. You can find the payment link by clicking on the bot and selecting the Home tab.', thread_ts=thread_ts) diff --git a/app/user.py b/app/user.py index 054f037f..e1c6aeda 100644 --- a/app/user.py +++ b/app/user.py @@ -55,6 +55,15 @@ def get_user(user_id): return "Error: Unable to parse JSON response" else: return f"Error: {response.status_code} - {response.reason}" + +def is_active_user(user_id): + try: + user = get_user(user_id) + if user and user['is_active']: + return True + except Exception as e: + logging.error(f"Error while checking if user {user_id} is active: {e}") + return False def is_premium_user(user_id): try: