refactoring userobj bookkeping
This commit is contained in:
parent
8e3d2a204a
commit
cd814e4132
|
@ -12,6 +12,7 @@ ANY_MENTION = [MessageEntity.MENTION, MessageEntity.TEXT_MENTION]
|
|||
PERIODS = ['day','week','month','year','all'] #TODO put in constants, shared with text_commands
|
||||
USERNAME_TO_USEROBJ_MAP = "username_to_userobj_map" #TODO transfer in config or constants
|
||||
USERS = "userobj_set"
|
||||
GET_ADMIN_FROM_API_REQUEST_COUNTDOWN = "get_administrators_countdown" # in context/chat_data[]
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,38 +7,24 @@ import helpers as h
|
|||
|
||||
from telegram.utils.helpers import escape_markdown
|
||||
|
||||
from constants import USERS
|
||||
from constants import USERS, GET_ADMIN_FROM_API_REQUEST_COUNTDOWN
|
||||
|
||||
|
||||
def keep_user_register(update: Update, context: CallbackContext) -> None:
|
||||
"""sync username and user object on any action
|
||||
|
||||
do not use in large chats as there is no deleting from the register"""
|
||||
do not use in very large chats as there is no deleting from the register"""
|
||||
message = update.message
|
||||
users = set()
|
||||
# if hasattr(update, "effective_user"): users |= set(update.effective_user)
|
||||
# if hasattr(message, "new_chat_members"): users |= set(*message.new_chat_members)
|
||||
# if hasattr(message, "left_chat_member"): users |= set(message.left_chat_member)
|
||||
# if hasattr(message, "forward_from"): users |= set(message.forward_from)
|
||||
# if hasattr(update, "edited_message"):
|
||||
# if hasattr(update.edited_message, "from_user"): users |= set(message.edited_message.from_user)
|
||||
# get user from every possible source
|
||||
if hasattr(update, "effective_user"): users |= set(update.effective_user)
|
||||
if hasattr(message, "new_chat_members"): users |= set(*message.new_chat_members)
|
||||
if hasattr(message, "left_chat_member"): users |= set(message.left_chat_member)
|
||||
if hasattr(message, "forward_from"): users |= set(message.forward_from)
|
||||
if hasattr(update, "edited_message"):
|
||||
if hasattr(update.edited_message, "from_user"): users |= set(message.edited_message.from_user)
|
||||
try:
|
||||
users |= {update.effective_user}
|
||||
except Exception as e: pass
|
||||
try:
|
||||
users |= {*message.new_chat_members}
|
||||
except Exception as e: pass
|
||||
try:
|
||||
users |= {message.left_chat_member}
|
||||
except Exception as e: pass
|
||||
try:
|
||||
users |= {message.forward_from}
|
||||
except Exception as e: pass
|
||||
try:
|
||||
users |= {message.edited_message.from_user}
|
||||
except Exception as e: pass
|
||||
try:
|
||||
record = "get_administrators_countdown"
|
||||
record = GET_ADMIN_FROM_API_REQUEST_COUNTDOWN
|
||||
get_administrators_frequency = 10 # request this data with low frequency
|
||||
try:
|
||||
if context.chat_data[record] >= get_administrators_frequency:
|
||||
|
|
Loading…
Reference in New Issue