Skip to content

Commit

Permalink
Merge pull request #109 from handsome0hell/users
Browse files Browse the repository at this point in the history
feat: show users with deep link
  • Loading branch information
F33RNI authored Dec 17, 2023
2 parents 4ceaa0b + d73ec6c commit a54c708
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
31 changes: 19 additions & 12 deletions BotHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ async def query_callback(
reply_message_id = int(data_splitted[2])

# Get user
user = self.users_handler.get_user_by_id(telegram_chat_id)
user = await self._user_check_get(update, context)

# Exit if banned
if user["banned"]:
Expand Down Expand Up @@ -1682,21 +1682,29 @@ async def bot_command_users(
+ " "
)

user_id = user_info["user_id"]
is_private = (
(user_info["user_type"] == "private")
if "user_type" in user_info
else (user_id > 0)
)
# User ID, name, total requests
message += "{0} ({1}) - {2}\n".format(
user_info["user_id"],
message += (
"{0} ([{1}](tg://user?id={0})) - {2}\n"
if is_private
else "{0} ({1}) - {2}\n"
).format(
user_id,
user_info["user_name"],
user_info["requests_total"],
)

# Parse as monospace
message = (
self.messages[lang]["users_admin"]
.format(message)
.replace("\\t", "\t")
.replace("\\n", "\n")
)
message = "```\n" + message + "\n```"

# Send list of users as markdown
await send_reply(
Expand Down Expand Up @@ -2668,23 +2676,22 @@ async def _user_check_get(
self, update: Update, context: ContextTypes.DEFAULT_TYPE
) -> dict:
"""
Gets (or creates) user based on update.effective_chat.id and update.message.from_user.full_name
Gets (or creates) user based on update.effective_chat.id
and checks if they are banned or not
:param update:
:param context:
:return: user as dictionary
"""
# Get user (or create a new one)
telegram_user_name = (
update.message.from_user.full_name if update.message is not None else None
)
telegram_chat_id = update.effective_chat.id
user = self.users_handler.get_user_by_id(telegram_chat_id)

# Update user name
if telegram_user_name is not None:
user["user_name"] = str(telegram_user_name)
self.users_handler.save_user(user)
if update.effective_chat.effective_name is not None:
user["user_name"] = str(update.effective_chat.effective_name)

user["user_type"] = update.effective_chat.type
self.users_handler.save_user(user)

# Send banned info
if user["banned"]:
Expand Down
3 changes: 2 additions & 1 deletion UsersHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ def _create_user(self, user_id: int) -> dict:
user = {
"user_id": user_id,
"user_name": DEFAULT_USER_NAME,
"user_type": "",
"admin": True if user_id in self.config["telegram"]["admin_ids"] else False,
"banned": self.config["telegram"]["ban_by_default"],
"banned": False if user_id in self.config["telegram"]["admin_ids"] else self.config["telegram"]["ban_by_default"],
"ban_reason": self.messages[0]["ban_reason_default"].replace("\\n", "\n"),
"module": self.config["modules"]["default_module"],
"requests_total": 0,
Expand Down

0 comments on commit a54c708

Please sign in to comment.