Skip to content

Commit 22e58d6

Browse files
authored
Add logging for command execution in ultroid_cmd with user ID and chat ID (#480)
1 parent 1b2209e commit 22e58d6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pyUltroid/_misc/_decorators.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ def ultroid_cmd(
7878

7979
def decor(dec):
8080
async def wrapp(ult):
81+
if udB.get_key("COMMAND_LOGGER"):
82+
user_id = ult.sender_id
83+
chat_id = ult.chat_id
84+
command_name = pattern if pattern else ult.text.split()[0].lstrip(HNDLR)
85+
chat_name = get_display_name(ult.chat)
86+
LOGS.info(f"Command '{command_name}' executed by user ID {user_id} in chat {chat_id} ({chat_name})")
87+
log_channel = udB.get_key("LOG_CHANNEL")
88+
if log_channel:
89+
try:
90+
await asst.send_message(
91+
log_channel,
92+
f"Command '{command_name}' executed by user ID {user_id} in chat {chat_id} ({chat_name})"
93+
)
94+
except Exception as e:
95+
LOGS.warning(f"Failed to send command log to log channel {log_channel}: {e}")
8196
if not ult.out:
8297
if owner_only:
8398
return

0 commit comments

Comments
 (0)