taslim19 commited on
Commit
93ddaf5
·
1 Parent(s): 4ce659d

Add debug print for packname and bot_username in kang.py to diagnose sticker pack errors

Browse files
DragMusic/plugins/management/kang.py CHANGED
@@ -128,7 +128,7 @@ async def kang(client, message: Message):
128
  e = format_exc()
129
  return print(e)
130
  #-------
131
- bot_username = BOT_USERNAME.lstrip("@")
132
  packnum = 0
133
  packname = f"f{message.from_user.id}_by_{bot_username}"
134
  limit = 0
@@ -136,6 +136,9 @@ async def kang(client, message: Message):
136
  while True:
137
  if limit >= 50:
138
  return await msg.delete()
 
 
 
139
  stickerset = await get_sticker_set_by_name(client, packname)
140
  if not stickerset:
141
  stickerset = await create_sticker_set(
 
128
  e = format_exc()
129
  return print(e)
130
  #-------
131
+ bot_username = BOT_USERNAME.lstrip("@").strip("_")
132
  packnum = 0
133
  packname = f"f{message.from_user.id}_by_{bot_username}"
134
  limit = 0
 
136
  while True:
137
  if limit >= 50:
138
  return await msg.delete()
139
+ # Debug print for packname and bot_username
140
+ print(f"[DEBUG] packname: {packname}")
141
+ print(f"[DEBUG] bot_username: {bot_username}")
142
  stickerset = await get_sticker_set_by_name(client, packname)
143
  if not stickerset:
144
  stickerset = await create_sticker_set(
DragMusic/plugins/management/quotly.py ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from io import BytesIO
2
+ from pyrogram import filters
3
+ from pyrogram.types import Message
4
+ from DragMusic import app
5
+ import httpx
6
+
7
+ # -----------------------------------------------------------------
8
+ fetch = httpx.AsyncClient(
9
+ http2=True,
10
+ verify=False,
11
+ headers={
12
+ "Accept-Language": "id-ID",
13
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edge/107.0.1418.42",
14
+ },
15
+ timeout=httpx.Timeout(20),
16
+ )
17
+ # ------------------------------------------------------------------------
18
+ class QuotlyException(Exception):
19
+ pass
20
+ # --------------------------------------------------------------------------
21
+ async def get_message_sender_id(ctx: Message):
22
+ if ctx.forward_date:
23
+ if ctx.forward_sender_name:
24
+ return 1
25
+ elif ctx.forward_from:
26
+ return ctx.forward_from.id
27
+ elif ctx.forward_from_chat:
28
+ return ctx.forward_from_chat.id
29
+ else:
30
+ return 1
31
+ elif ctx.from_user:
32
+ return ctx.from_user.id
33
+ elif ctx.sender_chat:
34
+ return ctx.sender_chat.id
35
+ else:
36
+ return 1
37
+ # -----------------------------------------------------------------------------------------
38
+ async def get_message_sender_name(ctx: Message):
39
+ if ctx.forward_date:
40
+ if ctx.forward_sender_name:
41
+ return ctx.forward_sender_name
42
+ elif ctx.forward_from:
43
+ return (
44
+ f"{ctx.forward_from.first_name} {ctx.forward_from.last_name}"
45
+ if ctx.forward_from.last_name
46
+ else ctx.forward_from.first_name
47
+ )
48
+ elif ctx.forward_from_chat:
49
+ return ctx.forward_from_chat.title
50
+ else:
51
+ return ""
52
+ elif ctx.from_user:
53
+ if ctx.from_user.last_name:
54
+ return f"{ctx.from_user.first_name} {ctx.from_user.last_name}"
55
+ else:
56
+ return ctx.from_user.first_name
57
+ elif ctx.sender_chat:
58
+ return ctx.sender_chat.title
59
+ else:
60
+ return ""
61
+ # ---------------------------------------------------------------------------------------------------
62
+ async def get_message_sender_username(ctx: Message):
63
+ if ctx.forward_date:
64
+ if (
65
+ not ctx.forward_sender_name
66
+ and not ctx.forward_from
67
+ and ctx.forward_from_chat
68
+ and ctx.forward_from_chat.username
69
+ ):
70
+ return ctx.forward_from_chat.username
71
+ elif (
72
+ not ctx.forward_sender_name
73
+ and not ctx.forward_from
74
+ and ctx.forward_from_chat
75
+ or ctx.forward_sender_name
76
+ or not ctx.forward_from
77
+ ):
78
+ return ""
79
+ else:
80
+ return ctx.forward_from.username or ""
81
+ elif ctx.from_user and ctx.from_user.username:
82
+ return ctx.from_user.username
83
+ elif (
84
+ ctx.from_user
85
+ or ctx.sender_chat
86
+ and not ctx.sender_chat.username
87
+ or not ctx.sender_chat
88
+ ):
89
+ return ""
90
+ else:
91
+ return ctx.sender_chat.username
92
+ # ------------------------------------------------------------------------
93
+ async def get_message_sender_photo(ctx: Message):
94
+ if ctx.forward_date:
95
+ if (
96
+ not ctx.forward_sender_name
97
+ and not ctx.forward_from
98
+ and ctx.forward_from_chat
99
+ and ctx.forward_from_chat.photo
100
+ ):
101
+ return {
102
+ "small_file_id": ctx.forward_from_chat.photo.small_file_id,
103
+ "small_photo_unique_id": ctx.forward_from_chat.photo.small_photo_unique_id,
104
+ "big_file_id": ctx.forward_from_chat.photo.big_file_id,
105
+ "big_photo_unique_id": ctx.forward_from_chat.photo.big_photo_unique_id,
106
+ }
107
+ elif (
108
+ not ctx.forward_sender_name
109
+ and not ctx.forward_from
110
+ and ctx.forward_from_chat
111
+ or ctx.forward_sender_name
112
+ or not ctx.forward_from
113
+ ):
114
+ return ""
115
+ else:
116
+ return (
117
+ {
118
+ "small_file_id": ctx.forward_from.photo.small_file_id,
119
+ "small_photo_unique_id": ctx.forward_from.photo.small_photo_unique_id,
120
+ "big_file_id": ctx.forward_from.photo.big_file_id,
121
+ "big_photo_unique_id": ctx.forward_from.photo.big_photo_unique_id,
122
+ }
123
+ if ctx.forward_from.photo
124
+ else ""
125
+ )
126
+ elif ctx.from_user and ctx.from_user.photo:
127
+ return {
128
+ "small_file_id": ctx.from_user.photo.small_file_id,
129
+ "small_photo_unique_id": ctx.from_user.photo.small_photo_unique_id,
130
+ "big_file_id": ctx.from_user.photo.big_file_id,
131
+ "big_photo_unique_id": ctx.from_user.photo.big_photo_unique_id,
132
+ }
133
+ elif (
134
+ ctx.from_user
135
+ or ctx.sender_chat
136
+ and not ctx.sender_chat.photo
137
+ or not ctx.sender_chat
138
+ ):
139
+ return ""
140
+ else:
141
+ return {
142
+ "small_file_id": ctx.sender_chat.photo.small_file_id,
143
+ "small_photo_unique_id": ctx.sender_chat.photo.small_photo_unique_id,
144
+ "big_file_id": ctx.sender_chat.photo.big_file_id,
145
+ "big_photo_unique_id": ctx.sender_chat.photo.big_photo_unique_id,
146
+ }
147
+ # ---------------------------------------------------------------------------------------------------
148
+ async def get_text_or_caption(ctx: Message):
149
+ if ctx.text:
150
+ return ctx.text
151
+ elif ctx.caption:
152
+ return ctx.caption
153
+ else:
154
+ return ""
155
+ # ---------------------------------------------------------------------------------------------------
156
+ async def pyrogram_to_quotly(messages, is_reply):
157
+ if not isinstance(messages, list):
158
+ messages = [messages]
159
+ payload = {
160
+ "type": "quote",
161
+ "format": "png",
162
+ "backgroundColor": "#1b1429",
163
+ "messages": [],
164
+ }
165
+ for message in messages:
166
+ the_message_dict_to_append = {}
167
+ if message.entities:
168
+ the_message_dict_to_append["entities"] = [
169
+ {
170
+ "type": entity.type.name.lower(),
171
+ "offset": entity.offset,
172
+ "length": entity.length,
173
+ }
174
+ for entity in message.entities
175
+ ]
176
+ elif message.caption_entities:
177
+ the_message_dict_to_append["entities"] = [
178
+ {
179
+ "type": entity.type.name.lower(),
180
+ "offset": entity.offset,
181
+ "length": entity.length,
182
+ }
183
+ for entity in message.caption_entities
184
+ ]
185
+ else:
186
+ the_message_dict_to_append["entities"] = []
187
+ the_message_dict_to_append["chatId"] = await get_message_sender_id(message)
188
+ the_message_dict_to_append["text"] = await get_text_or_caption(message)
189
+ the_message_dict_to_append["avatar"] = True
190
+ the_message_dict_to_append["from"] = {}
191
+ the_message_dict_to_append["from"]["id"] = await get_message_sender_id(message)
192
+ the_message_dict_to_append["from"]["name"] = await get_message_sender_name(message)
193
+ the_message_dict_to_append["from"]["username"] = await get_message_sender_username(message)
194
+ the_message_dict_to_append["from"]["type"] = message.chat.type.name.lower()
195
+ the_message_dict_to_append["from"]["photo"] = await get_message_sender_photo(message)
196
+ if message.reply_to_message and is_reply:
197
+ the_message_dict_to_append["replyMessage"] = {
198
+ "name": await get_message_sender_name(message.reply_to_message),
199
+ "text": await get_text_or_caption(message.reply_to_message),
200
+ "chatId": await get_message_sender_id(message.reply_to_message),
201
+ }
202
+ else:
203
+ the_message_dict_to_append["replyMessage"] = {}
204
+ payload["messages"].append(the_message_dict_to_append)
205
+ r = await fetch.post("https://bot.lyo.su/quote/generate.png", json=payload)
206
+ if not r.is_error:
207
+ return r.read()
208
+ else:
209
+ raise QuotlyException(await r.aread())
210
+ # ------------------------------------------------------------------------------------------
211
+ def isArgInt(txt) -> list:
212
+ count = txt
213
+ try:
214
+ count = int(count)
215
+ return [True, count]
216
+ except ValueError:
217
+ return [False, 0]
218
+ # ---------------------------------------------------------------------------------------------------
219
+ @app.on_message(filters.command(["q"]) & filters.reply)
220
+ async def msg_quotly_cmd(client, ctx: Message):
221
+ args = ctx.text.split()
222
+ is_reply = False
223
+ quote_range = 1
224
+ # /q r or /q <number>
225
+ if len(args) > 1:
226
+ if args[1].lower() == "r":
227
+ is_reply = True
228
+ else:
229
+ try:
230
+ quote_range = int(args[1])
231
+ if quote_range < 2 or quote_range > 10:
232
+ return await ctx.reply("Invalid range (2-10)")
233
+ except ValueError:
234
+ return await ctx.reply("Invalid argument. Use /q r or /q <number> (2-10)")
235
+ if quote_range > 1:
236
+ try:
237
+ messages = [
238
+ i
239
+ for i in await client.get_messages(
240
+ chat_id=ctx.chat.id,
241
+ message_ids=range(
242
+ ctx.reply_to_message.id,
243
+ ctx.reply_to_message.id + quote_range
244
+ ),
245
+ replies=-1,
246
+ )
247
+ if not i.empty and not i.media
248
+ ]
249
+ except Exception:
250
+ return await ctx.reply_text("🤷🏻‍♂️")
251
+ try:
252
+ make_quotly = await pyrogram_to_quotly(messages, is_reply=is_reply)
253
+ bio_sticker = BytesIO(await make_quotly)
254
+ bio_sticker.name = "misskatyquote_sticker.webp"
255
+ return await ctx.reply_sticker(bio_sticker)
256
+ except Exception:
257
+ return await ctx.reply("🤷🏻‍♂️")
258
+ else:
259
+ try:
260
+ messages_one = await client.get_messages(
261
+ chat_id=ctx.chat.id, message_ids=ctx.reply_to_message.id, replies=-1
262
+ )
263
+ messages = [messages_one]
264
+ except Exception:
265
+ return await ctx.reply("🤷🏻‍♂️")
266
+ try:
267
+ make_quotly = await pyrogram_to_quotly(messages, is_reply=is_reply)
268
+ bio_sticker = BytesIO(await make_quotly)
269
+ bio_sticker.name = "misskatyquote_sticker.webp"
270
+ return await ctx.reply_sticker(bio_sticker)
271
+ except Exception as e:
272
+ return await ctx.reply(f"ERROR: {e}")