Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
  • Loading branch information
madawei2699 committed Nov 19, 2023
1 parent d68736a commit b032d24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions app/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b032d24

Please sign in to comment.