-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuserinfo.py
255 lines (221 loc) · 9.12 KB
/
userinfo.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# some text
from .. import loader, utils
import logging
from telethon.tl.functions.users import GetFullUserRequest
from telethon.tl.functions.messages import GetFullChatRequest
from telethon.tl.functions.channels import GetFullChannelRequest
logger = logging.getLogger(__name__)
# https://stackoverflow.com/questions/2466191/set-attributes-from-dictionary-in-python
class E:
def __init__(self, *initial_data, **kwargs):
for dictionary in initial_data:
for key in dictionary:
setattr(self, key, dictionary[key])
for key in kwargs:
setattr(self, key, kwargs[key])
@loader.tds
class userinfoMod(loader.Module):
"""Tells you about people and chats
subscribe @uwun3ss plox"""
common_list = {
"id": "\nID: <code>{}</code>",
"username": "\nUsername: <code>{}</code>",
"scam": "\nScam: <code>{}</code>",
"fake": "\nFake: <code>{}</code>"
}
general_list = {
"first_name": "\nFirst name: <code>{}</code>",
"last_name": "\nLast name: <code>{}</code>",
"dc_id": "\nDC ID: <code>{}</code>",
"bot": "\nBot: <code>{}</code>",
"about": "\nBio: <code>{}</code>",
"deleted": "\nDeleted: <code>{}</code>",
"restricted": "\nRestricted: <code>{}</code>",
"verified": "\nVerified: <code>{}</code>"
}
chat_list = {
"location": "\nLocation: <code>{}</code>",
"linked_chat_id": "\nLinked chat ID: <code>{}</code>",
"title": "\nTitle: <code>{}</code>",
"participants_count": "\nParticipants: <code>{}</code>",
"date": "\nCreation date: <code>{}</code>",
"megagroup": "\nMegagroup: <code>{}</code>",
"gigagroup": "\nGigagroup: <code>{}</code>",
"noforwards": "\nNo forwards: <code>{}</code>",
"restriction_reason": "\nRestriction reason: <code>{}</code>"
}
strings = {
"name": "userinfo",
"find_error": "<b>Couldn't find that user.</b>",
"no_args_or_reply": "<b>No args or reply was provided.</b>",
"provide_user": "<b>Provide a user to locate</b>",
"searching_user": "<code>Searching for user...</code>",
"cannot_find": "<b>Can't find user</b>",
"permalink_txt": "<a href='tg://user?id={uid}'>\
{txt}</a>",
"permalink_uid": "<a href='tg://user?id={uid}'>\
Permalink to {uid}</a>",
"permalink_public_channel":
"<a href='tg://resolve?domain={domain}'>\
Permalink to <code>{title}</code></a>",
"permalink_private_channel":
"<a href=\
'tg://privatepost?channel={channel_id}&post={post}'>\
Permalink1 to <code>{title}</code></a>(desktop)\
\n<a href=\
'tg://openmessage?chat_id={channel_id}'>\
Permalink2</a>(mobile)",
"encode_cfg_doc": "Encode unicode characters"
}
def __init__(self):
self.config = loader.ModuleConfig(
"ENCODE",
False,
lambda m: self.strings("encode_cfg_doc", m)
)
self.replier = ''
async def client_ready(self, client, db):
self.client = client
self.db = db
async def humanize(self, list_, full, replier):
for i in list_:
l = getattr(full, i)
if l not in [None, False, [], {}]:
temp = list_[i].format(self._handle_string(l))
if temp in replier: pass
else: replier += temp
self.replier += replier
return
async def get_user(self, message, args):
m = await message.get_reply_message()
if (m is None):
if args and (args[0] == 'me'):
full = await self.client.get_entity(message.from_id)
elif not args:
full = await self.client.get_entity(message.chat.id)
elif m:
if args:
try:
if l := args[0]:
if '-100' in l: l = l[4:]
if l.isdigit(): entity = int(l)
else: entity = l
full = await self.client.get_entity(entity)
except Exception as e:
logger.error(e)
await utils.answer(
message,
self.strings(
"cannot_find",
message
)
)
return
else:
full = await self.client.get_entity(m.from_id)
return full, m
async def get_m(self, entity):
res = await self.client.get_messages(
await self.client.get_entity(entity), limit=1)
return res
async def get_attributes(self, full):
l = E(full.to_dict())
if l._ == 'User':
full = await self.client(GetFullUserRequest(l.id))
obj = E(full.full_user.to_dict() | full.users[0].to_dict())
elif l._ == 'Chat':
full = await self.client(GetFullChatRequest(l.id))
obj = E(full.full_chat.to_dict() | full.chats[0].to_dict())
elif l._ == 'Channel':
full = await self.client(GetFullChannelRequest(l.id))
temp = {}; [temp.update(i.to_dict()) for i in full.chats]
_ae = E(full.full_chat.to_dict() | temp)
obj = E(full.full_chat.to_dict() | full.chats[0].to_dict())
setattr(obj, 'dc_id', E(obj.photo).dc_id)
return obj._, obj
def _handle_string(self, string):
if self.config["ENCODE"]:
return utils.escape_html(ascii(string))
return utils.escape_html(string)
@loader.unrestricted
@loader.ratelimit
async def uinfocmd(self, message):
"""userinfo [ {username} or {id} or {me} ] [ insecure ]\
(optional flag, type if u want to show ur contact's name to others)"""
args = utils.get_args(message)
try:
full, _m = await self.get_user(message, args)
type_, full = await self.get_attributes(full)
except Exception as e:
logger.debug(e)
return
# a little bit sesuritical
if type_ == 'User'\
and 'insecure' not in args\
and message.chat and full.contact:
full.first_name = None #self._handle_string(full.first_name[0])
try: full.last_name = None#self._handle_string(full.last_name[0])
except: pass
full.phone = None #self._handle_string(full.phone[0])
self.hidden = True
await self.humanize(self.common_list, full, '')
if type_ == 'User':
await self.humanize(self.general_list, full, '')
if type_ == 'Chat':
await self.humanize(self.chat_list, full, '')
if type_ == 'Channel':
await self.humanize(self.chat_list, full, '')
await utils.answer(
message,
f'<u><b>{type_}</u> Info:</b>'+self.replier)
# reset data
self.replier = ''
@loader.unrestricted
@loader.ratelimit
async def permalinkcmd(self, message):
"""Get permalink to user based on ID or username"""
args = utils.get_args(message)
full, _m = await self.get_user(message, args)
l = E(full.to_dict())
if l._ in ['Channel', 'Chat']:
if l.username:
await utils.answer(
message,
self.strings("permalink_public_channel",
message).format(
domain=l.username,
title=l.title))
else:
await utils.answer(
message,
self.strings(
"permalink_private_channel",
message
).format(
channel_id=l.id,
post=2000001,
title=l.title
)
)
else:
if len(args) > 1:
await utils.answer(
message,
self.strings(
"permalink_txt",
message
).format(
uid=l.id,
txt=args[1]
)
)
else:
await utils.answer(
message,
self.strings(
"permalink_uid",
message
).format(
uid=l.id
)
)