Skip to content

Commit

Permalink
refactor(notes,custom_filters): use less space in the code (#387)
Browse files Browse the repository at this point in the history
* up

* fix

* fix

* chore: lint & format

---------

Co-authored-by: Alisson Lauffer <[email protected]>
  • Loading branch information
2ei and alissonlauffer committed Jun 21, 2024
1 parent 7221fdf commit 6b9f605
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 145 deletions.
83 changes: 11 additions & 72 deletions eduu/plugins/custom_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,18 @@ async def save_filter(c: Client, m: Message, s: Strings):
await m.reply_text(s("filters_add_empty"), quote=True)
return

if m.reply_to_message and m.reply_to_message.photo:
file_id = m.reply_to_message.photo.file_id
if m.reply_to_message.media and m.reply_to_message.media.value in {
"photo",
"document",
"video",
"audio",
"animation",
}:
file_id = getattr(m.reply_to_message, m.reply_to_message.media.value).file_id
raw_data = (
m.reply_to_message.caption.markdown if m.reply_to_message.caption is not None else None
)
filter_type = "photo"
elif m.reply_to_message and m.reply_to_message.document:
file_id = m.reply_to_message.document.file_id
raw_data = (
m.reply_to_message.caption.markdown if m.reply_to_message.caption is not None else None
)
filter_type = "document"
elif m.reply_to_message and m.reply_to_message.video:
file_id = m.reply_to_message.video.file_id
raw_data = (
m.reply_to_message.caption.markdown if m.reply_to_message.caption is not None else None
)
filter_type = "video"
elif m.reply_to_message and m.reply_to_message.audio:
file_id = m.reply_to_message.audio.file_id
raw_data = (
m.reply_to_message.caption.markdown if m.reply_to_message.caption is not None else None
)
filter_type = "audio"
elif m.reply_to_message and m.reply_to_message.animation:
file_id = m.reply_to_message.animation.file_id
raw_data = (
m.reply_to_message.caption.markdown if m.reply_to_message.caption is not None else None
)
filter_type = "animation"
filter_type = m.reply_to_message.media.value
elif m.reply_to_message and m.reply_to_message.sticker:
file_id = m.reply_to_message.sticker.file_id
raw_data = split_text[1] if len(split_text) > 1 else None
Expand Down Expand Up @@ -145,58 +127,15 @@ async def serve_filter(c: Client, m: Message):
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)
elif filter_[4] == "photo":
await targeted_message.reply_photo(
elif filter_[4] in {"photo", "document", "video", "audio", "animation", "sticker"}:
await targeted_message.reply_cached_media(
filter_[3],
quote=True,
caption=data,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)

elif filter_[4] == "document":
await targeted_message.reply_document(
filter_[3],
quote=True,
caption=data,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)

elif filter_[4] == "video":
await targeted_message.reply_video(
filter_[3],
quote=True,
caption=data,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)

elif filter_[4] == "audio":
await targeted_message.reply_audio(
filter_[3],
quote=True,
caption=data,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)

elif filter_[4] == "animation":
await targeted_message.reply_animation(
filter_[3],
quote=True,
caption=data,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)

elif filter_[4] == "sticker":
await targeted_message.reply_sticker(
filter_[3],
quote=True,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)


commands.add_command("delfilter", "admin")
commands.add_command("filter", "admin")
Expand Down
85 changes: 12 additions & 73 deletions eduu/plugins/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,18 @@ async def save_note(c: Client, m: Message, s: Strings):
await m.reply_text(s("notes_add_empty"), quote=True)
return

if m.reply_to_message and m.reply_to_message.photo:
file_id = m.reply_to_message.photo.file_id
if m.reply_to_message.media and m.reply_to_message.media.value in {
"photo",
"document",
"video",
"audio",
"animation",
}:
file_id = getattr(m.reply_to_message, m.reply_to_message.media.value).file_id
raw_data = (
m.reply_to_message.caption.html if m.reply_to_message.caption is not None else None
m.reply_to_message.caption.markdown if m.reply_to_message.caption is not None else None
)
note_type = "photo"
elif m.reply_to_message and m.reply_to_message.document:
file_id = m.reply_to_message.document.file_id
raw_data = (
m.reply_to_message.caption.html if m.reply_to_message.caption is not None else None
)
note_type = "document"
elif m.reply_to_message and m.reply_to_message.video:
file_id = m.reply_to_message.video.file_id
raw_data = (
m.reply_to_message.caption.html if m.reply_to_message.caption is not None else None
)
note_type = "video"
elif m.reply_to_message and m.reply_to_message.audio:
file_id = m.reply_to_message.audio.file_id
raw_data = (
m.reply_to_message.caption.html if m.reply_to_message.caption is not None else None
)
note_type = "audio"
elif m.reply_to_message and m.reply_to_message.animation:
file_id = m.reply_to_message.animation.file_id
raw_data = (
m.reply_to_message.caption.html if m.reply_to_message.caption is not None else None
)
note_type = "animation"
note_type = m.reply_to_message.media.value
elif m.reply_to_message and m.reply_to_message.sticker:
file_id = m.reply_to_message.sticker.file_id
raw_data = split_text[1] if len(split_text) > 1 else None
Expand Down Expand Up @@ -133,58 +115,15 @@ async def serve_note(c: Client, m: Message, txt):
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)
elif note[4] == "photo":
await m.reply_photo(
elif note[4] in {"photo", "document", "video", "audio", "animation", "sticker"}:
await m.reply_cached_media(
note[3],
quote=True,
caption=data,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)

elif note[4] == "document":
await m.reply_document(
note[3],
quote=True,
caption=data,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)

elif note[4] == "video":
await m.reply_video(
note[3],
quote=True,
caption=data,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)

elif note[4] == "audio":
await m.reply_audio(
note[3],
quote=True,
caption=data,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)

elif note[4] == "animation":
await m.reply_animation(
note[3],
quote=True,
caption=data,
parse_mode=ParseMode.MARKDOWN,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)

elif note[4] == "sticker":
await m.reply_sticker(
note[3],
quote=True,
reply_markup=InlineKeyboardMarkup(button) if len(button) != 0 else None,
)


@Client.on_message(
(filters.group | filters.private)
Expand Down

0 comments on commit 6b9f605

Please sign in to comment.