-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcommands_logger.py
135 lines (120 loc) · 5.51 KB
/
commands_logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#
# @@@@@@ @@@@@@ @@@@@@@ @@@@@@@ @@@@@@ @@@@@@@@@@ @@@@@@ @@@@@@@ @@@ @@@ @@@ @@@@@@@@ @@@@@@
# @@@@@@@@ @@@@@@@ @@@@@@@ @@@@@@@@ @@@@@@@@ @@@@@@@@@@@ @@@@@@@@ @@@@@@@@ @@@ @@@ @@@ @@@@@@@@ @@@@@@@
# @@! @@@ !@@ @@! @@! @@@ @@! @@@ @@! @@! @@! @@! @@@ @@! @@@ @@! @@@ @@! @@! !@@
# !@! @!@ !@! !@! !@! @!@ !@! @!@ !@! !@! !@! !@! @!@ !@! @!@ !@! @!@ !@! !@! !@!
# @!@!@!@! !!@@!! @!! @!@!!@! @!@ !@! @!! !!@ @!@ @!@ !@! @!@ !@! @!@ !@! @!! @!!!:! !!@@!!
# !!!@!!!! !!@!!! !!! !!@!@! !@! !!! !@! ! !@! !@! !!! !@! !!! !@! !!! !!! !!!!!: !!@!!!
# !!: !!! !:! !!: !!: :!! !!: !!! !!: !!: !!: !!! !!: !!! !!: !!! !!: !!: !:!
# :!: !:! !:! :!: :!: !:! :!: !:! :!: :!: :!: !:! :!: !:! :!: !:! :!: :!: !:!
# :: ::: :::: :: :: :: ::: ::::: :: ::: :: ::::: :: :::: :: ::::: :: :: :::: :: :::: :::: ::
# : : : :: : : : : : : : : : : : : : : :: : : : : : : :: : : : :: :: :: : :
#
# © Copyright 2024
#
# https://t.me/Den4ikSuperOstryyPer4ik
# and
# https://t.me/ToXicUse
#
# 🔒 Licensed under the GNU AGPLv3
# https://www.gnu.org/licenses/agpl-3.0.html
#
# meta developer: @AstroModules
# meta banner: https://raw.githubusercontent.com/Den4ikSuperOstryyPer4ik/Astro-modules/main/Banners/HikkaCommandsLogger.jpg
import logging
from telethon.tl.functions.channels import InviteToChannelRequest
from hikkatl.tl.types import PeerUser, PeerChannel, PeerChat, Channel, User
from .. import loader
from .. import utils
logger = logging.getLogger(__name__)
@loader.tds
class HikkaCommandsLoggerMod(loader.Module):
'''Hikka Commands Logger'''
strings = {
"name": "HikkaCommandsLogger",
"log-groups": (
"<b>#GROUP\n\n"
"┌ Command:\n├ « <code>{}</code> »\n"
"├ From --> {}\n"
"├ Chat --> {}\n"
"└ Message Link --> <a href='https://t.me/c/{}/{}'>CLICK</a></b>"
),
"log-pm": (
"<b>#PM\n\n"
"┌ Command:\n├ « <code>{}</code> »\n"
"├ From --> {}\n"
"├ Chat with --> {}\n"
"└ Message Link --> <a href='tg://openmessage?user_id={}&message_id={}'>CLICK</a></b>"
),
"log-channels": (
"<b>#CHANNEL\n\n"
"┌ Command:\n├ « <code>{}</code> »\n"
"├ From --> {}\n"
"├ Channel --> {}\n"
"└ Message Link --> <a href='https://t.me/c/{}/{}'>CLICK</a></b>"
),
}
async def client_ready(self, client, _):
self.chat_l, _ = await utils.asset_channel(
client,
"hikka-commands-logs",
"💬 Chat for Hikka commands logger",
silent=True,
avatar="https://raw.githubusercontent.com/Den4ikSuperOstryyPer4ik/Astro-modules/main/Banners/HikkaCommandsLoggerAvatar.png",
)
self.chat_logs = f"-100{self.chat_l.id}"
logger.warning("[AstroModules::HikkaCommandsLogger] Commands logger started.")
@loader.watcher(only_commands=True)
async def watcher(self, message):
is_pm = isinstance(message.peer_id, PeerUser)
sender = await message.get_sender()
is_channel = message.post or isinstance(sender, Channel)
chat_id = (
message.peer_id.user_id
if is_pm
else message.peer_id.chat_id
if isinstance(message.peer_id, PeerChat)
else message.peer_id.channel_id
if isinstance(message.peer_id, PeerChannel)
else self.hikka_me.id
)
chat = await self._client.get_entity(chat_id)
chat_username = getattr(chat, "username", None)
user_link = (
f"<a href='https://t.me/{sender.username}'>{sender.first_name if not is_channel else sender.title}</a>"
if sender.username
else f"<a href=tg://user?id={sender.id}>{sender.first_name if not is_channel else sender.title}</a>"
)
chat_link = (
f"<a href='https://t.me/{chat_username}'>{chat.title}</a>"
if chat_username
else chat.title
) if not is_pm else (
f"<a href='https://t.me/{chat.username}'>{chat.first_name}</a>"
if chat.username
else f"<a href='tg://user?id={chat.id}'>{chat.first_name}</a>"
)
async def send():
await self.inline.bot.send_message(
self.chat_logs,
self.strings(
"log-pm"
if is_pm
else "log-channels"
if message.post
else "log-groups"
).format(
utils.escape_html(message.raw_text),
user_link,
chat_link,
chat.id,
message.id,
),
disable_web_page_preview=True,
parse_mode="HTML",
)
try:
await send()
except Exception:
await utils.invite_inline_bot(self.client, self.chat_l)
await send()