Alexainc commited on
Commit
a5fbbae
·
1 Parent(s): 52c6822

fix: comprehensive flag filtering for all media and edit methods

Browse files
Files changed (1) hide show
  1. QueenNoxi/modules/notes.py +27 -10
QueenNoxi/modules/notes.py CHANGED
@@ -72,8 +72,14 @@ async def get(client: Client, message: Message, notename: str, show_none=True, n
72
  # unless a different file_id is required.
73
  is_current_media = bool(query.message.photo or query.message.video or query.message.document or query.message.animation or query.message.voice or query.message.audio)
74
 
75
- # Filter out flags that are not compatible with edit_message_text/caption
76
- edit_flags = {k: v for k, v in flags.items() if k not in ["disable_notification", "protect_content", "has_spoiler"]}
 
 
 
 
 
 
77
 
78
  if note.msgtype in (Types.BUTTON_TEXT, Types.TEXT):
79
  if is_current_media:
@@ -90,7 +96,7 @@ async def get(client: Client, message: Message, notename: str, show_none=True, n
90
  text,
91
  parse_mode=parse_mode,
92
  reply_markup=keyboard,
93
- **edit_flags
94
  )
95
  return
96
 
@@ -108,6 +114,9 @@ async def get(client: Client, message: Message, notename: str, show_none=True, n
108
  # Fallback: resend if moving from text to media
109
  pass
110
 
 
 
 
111
  if note.msgtype in (Types.BUTTON_TEXT, Types.TEXT):
112
  flags.pop("has_spoiler", None)
113
  await message.reply_text(
@@ -118,19 +127,27 @@ async def get(client: Client, message: Message, notename: str, show_none=True, n
118
  **flags
119
  )
120
  elif note.msgtype == Types.STICKER:
121
- await client.send_sticker(chat_id, note.file, reply_to_message_id=reply_id, reply_markup=keyboard, **flags)
 
 
122
  elif note.msgtype == Types.DOCUMENT:
123
- await client.send_document(chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parse_mode, reply_markup=keyboard, **flags)
 
124
  elif note.msgtype == Types.PHOTO:
125
- await client.send_photo(chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parse_mode, reply_markup=keyboard, **flags)
126
  elif note.msgtype == Types.AUDIO:
127
- await client.send_audio(chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parse_mode, reply_markup=keyboard, **flags)
 
128
  elif note.msgtype == Types.VOICE:
129
- await client.send_voice(chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parse_mode, reply_markup=keyboard, **flags)
 
130
  elif note.msgtype == Types.VIDEO:
131
- await client.send_video(chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parse_mode, reply_markup=keyboard, **flags)
132
  elif note.msgtype == Types.VIDEO_NOTE:
133
- await client.send_video_note(chat_id, note.file, reply_to_message_id=reply_id, reply_markup=keyboard, **flags)
 
 
 
134
 
135
  except RPCError as e:
136
  if query:
 
72
  # unless a different file_id is required.
73
  is_current_media = bool(query.message.photo or query.message.video or query.message.document or query.message.animation or query.message.voice or query.message.audio)
74
 
75
+ # Filter flags for edit_message_text/caption
76
+ # edit_flags: only formatting/UI flags, NO notification/protective flags
77
+ edit_flags = {k: v for k, v in flags.items() if k not in ["disable_notification", "protect_content", "has_spoiler", "disable_web_page_preview"]}
78
+
79
+ # Text edit supports disable_web_page_preview
80
+ text_edit_flags = edit_flags.copy()
81
+ if "disable_web_page_preview" in flags:
82
+ text_edit_flags["disable_web_page_preview"] = flags["disable_web_page_preview"]
83
 
84
  if note.msgtype in (Types.BUTTON_TEXT, Types.TEXT):
85
  if is_current_media:
 
96
  text,
97
  parse_mode=parse_mode,
98
  reply_markup=keyboard,
99
+ **text_edit_flags
100
  )
101
  return
102
 
 
114
  # Fallback: resend if moving from text to media
115
  pass
116
 
117
+ # Media flags filter (no disable_web_page_preview)
118
+ media_flags = {k: v for k, v in flags.items() if k != "disable_web_page_preview"}
119
+
120
  if note.msgtype in (Types.BUTTON_TEXT, Types.TEXT):
121
  flags.pop("has_spoiler", None)
122
  await message.reply_text(
 
127
  **flags
128
  )
129
  elif note.msgtype == Types.STICKER:
130
+ # Stickers don't support caption or web_page_preview or has_spoiler
131
+ stk_flags = {k: v for k, v in media_flags.items() if k not in ["has_spoiler"]}
132
+ await client.send_sticker(chat_id, note.file, reply_to_message_id=reply_id, reply_markup=keyboard, **stk_flags)
133
  elif note.msgtype == Types.DOCUMENT:
134
+ doc_flags = {k: v for k, v in media_flags.items() if k not in ["has_spoiler"]}
135
+ await client.send_document(chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parse_mode, reply_markup=keyboard, **doc_flags)
136
  elif note.msgtype == Types.PHOTO:
137
+ await client.send_photo(chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parse_mode, reply_markup=keyboard, **media_flags)
138
  elif note.msgtype == Types.AUDIO:
139
+ aud_flags = {k: v for k, v in media_flags.items() if k not in ["has_spoiler"]}
140
+ await client.send_audio(chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parse_mode, reply_markup=keyboard, **aud_flags)
141
  elif note.msgtype == Types.VOICE:
142
+ v_flags = {k: v for k, v in media_flags.items() if k not in ["has_spoiler"]}
143
+ await client.send_voice(chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parse_mode, reply_markup=keyboard, **v_flags)
144
  elif note.msgtype == Types.VIDEO:
145
+ await client.send_video(chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parse_mode, reply_markup=keyboard, **media_flags)
146
  elif note.msgtype == Types.VIDEO_NOTE:
147
+ vn_flags = {k: v for k, v in media_flags.items() if k not in ["has_spoiler"]}
148
+ await client.send_video_note(chat_id, note.file, reply_to_message_id=reply_id, reply_markup=keyboard, **vn_flags)
149
+ elif note.msgtype == Types.ANIMATION:
150
+ await client.send_animation(chat_id, note.file, caption=text, reply_to_message_id=reply_id, parse_mode=parse_mode, reply_markup=keyboard, **media_flags)
151
 
152
  except RPCError as e:
153
  if query: