Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.3.0 #449

Merged
merged 39 commits into from
Dec 16, 2024
Merged

2.3.0 #449

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
05148e2
add copy text widget
KurosawaAngel Nov 4, 2024
6d2d847
edit text to media
KurosawaAngel Nov 4, 2024
fbacbf9
fix flake
KurosawaAngel Nov 4, 2024
8f48142
add widget to __init__
KurosawaAngel Nov 4, 2024
e5c4510
better format
KurosawaAngel Nov 4, 2024
c36ea7c
BETTER CODE FORMAT
KurosawaAngel Nov 5, 2024
a727f87
drop support python 3.8
chirizxc Nov 5, 2024
a5b3734
hotfix: add accidentally deleted requirements
chirizxc Nov 5, 2024
2667b20
fix for flake 8
chirizxc Nov 5, 2024
3d8d3cf
fix imports
chirizxc Nov 5, 2024
c150675
drop flake8, add ruff, add uv for workflows
chirizxc Nov 6, 2024
8f0070d
fix workflow
chirizxc Nov 6, 2024
06c911c
fix code for python 3.9
chirizxc Nov 6, 2024
9c2a593
fix tests for python 3.9
chirizxc Nov 6, 2024
33dacdf
Merge pull request #435 from KurosawaAngel/feature/edit_media
Tishka17 Nov 6, 2024
6897cc6
fix: improve code readability
chirizxc Nov 6, 2024
e3598bf
Merge pull request #436 from chirizxc/develop
Tishka17 Nov 6, 2024
c8cfd0a
fix: enable ignored ruff rules: PT001, PT023, PLW2901, B904, RUF012, …
chirizxc Nov 6, 2024
90475d9
Update to restart pipeline
Tishka17 Nov 6, 2024
2ed7d6b
fix trailing comma
Tishka17 Nov 6, 2024
447da89
Merge pull request #434 from KurosawaAngel/develop
Tishka17 Nov 6, 2024
d951f7e
Merge pull request #437 from chirizxc/develop
Tishka17 Nov 6, 2024
fc7e852
drop python 3.8 from docs examples
chirizxc Nov 6, 2024
508a133
Merge pull request #438 from chirizxc/develop
Tishka17 Nov 6, 2024
a60844d
Update message_manager.py
Latand Nov 7, 2024
32170e1
Merge pull request #440 from Latand/patch-2
Tishka17 Nov 7, 2024
f72f379
fix edit voice
KurosawaAngel Nov 7, 2024
5552ee2
add voice added check
KurosawaAngel Nov 7, 2024
f0e4c61
Merge pull request #441 from KurosawaAngel/develop
Tishka17 Nov 10, 2024
460a04f
add tests for python 3.13
chirizxc Nov 11, 2024
b785633
fix pyproject
chirizxc Nov 11, 2024
a572eba
Merge pull request #443 from chirizxc/develop
Tishka17 Nov 11, 2024
d1b2e5c
link preview prototype
Tishka17 Dec 11, 2024
bd56910
make `url` optional and add example for `LinkPreview` widget
chirizxc Dec 15, 2024
22dd47b
add docs to LinkPreview widget
chirizxc Dec 15, 2024
71b3088
Merge pull request #448 from chirizxc/feature/link_preview
Tishka17 Dec 16, 2024
74d0d6e
remove disable_web_page_preview usage, move example to mega bot
Tishka17 Dec 16, 2024
eacc7bc
Fix linter
Tishka17 Dec 16, 2024
8a30174
Merge pull request #447 from Tishka17/feature/link_preview
Tishka17 Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions .flake8

This file was deleted.

15 changes: 8 additions & 7 deletions .github/workflows/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
os:
- ubuntu-latest
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"

steps:
- uses: actions/checkout@v2
Expand All @@ -34,15 +34,16 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install . -r requirements_dev.txt
pip install diagrams
uv pip install . -r requirements_dev.txt --system
uv pip install diagrams --system

- name: Run flake8
run: |
python -m flake8 src/aiogram_dialog tests example
- name: Run Ruff
run: ruff check src/aiogram_dialog tests example

- name: Run tests
run: |
Expand Down
68 changes: 68 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
line-length = 79
target-version="py39"
src = ["src"]

include = ["src/**.py", "tests/**.py", "example/**.py"]
exclude = ["docs"]

lint.select = ["ALL"]
lint.ignore = [
"ANN",
"ARG",
"D",
"DTZ",
"TD",
"A002",
"ASYNC230",
"BLE001",
"EM101",
"EM102",
"FA100",
"FBT001",
"FBT002",
"FIX002",
"ISC002",
"ISC003",
"N818",
"PLR0913",
"PLW2901",
"PYI034",
"RET505",
"S311",
"SIM103",
"SIM108",
"SIM114",
"TCH001",
"TCH002",
"TCH003",
"TRY003",
"TRY201",
"TRY400",
"UP007",
"UP038",
]


[lint.per-file-ignores]
"src/aiogram_dialog/tools/**" = [
"S101",
"SLF001",
"PTH",
]
"src/aiogram_dialog/test_tools/**"= [
"S101",
"PTH"
]
"tests/**" = [
"TID252",
"PLR2004",
"S101",
"INP001",
"FBT003",
]
"example/**" = [
"INP001",
"ERA001",
"RUF001",
"PTH",
]
27 changes: 12 additions & 15 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,29 @@
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))

import datetime

# sys.path.insert(0, os.path.abspath("."))
# -- Project information -----------------------------------------------------

project = 'aiogram-dialog'
copyright = f'{datetime.date.today().year}, Tishka17'
author = 'Tishka17'
master_doc = 'index'
project = "aiogram-dialog"
copyright = "%Y, Tishka17"
author = "Tishka17"
master_doc = "index"

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# extensions coming with Sphinx (named "sphinx.ext.*") or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx_copybutton',
"sphinx.ext.autodoc",
"sphinx_copybutton",
]
autodoc_type_aliases = {
}
autodoc_typehints = 'description'
autodoc_typehints = "description"

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -49,9 +46,9 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'furo'
html_theme = "furo"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from typing import Dict, List

from aiogram.filters.state import StatesGroup, State
from aiogram.filters.state import State, StatesGroup
from aiogram.types import InlineKeyboardButton
from aiogram_dialog import Dialog, Window
from aiogram_dialog import DialogManager

from aiogram_dialog import Dialog, DialogManager, Window
from aiogram_dialog.widgets.kbd import SwitchInlineQuery
from aiogram_dialog.widgets.text import Const


class SwitchInlineQueryCurrentChat(SwitchInlineQuery):
async def _render_keyboard(
self,
data: Dict,
data: dict,
manager: DialogManager,
) -> List[List[InlineKeyboardButton]]:
) -> list[list[InlineKeyboardButton]]:
return [
[
InlineKeyboardButton(
Expand All @@ -34,8 +32,8 @@ class MySG(StatesGroup):
Window(
SwitchInlineQueryCurrentChat(
Const("Some search"), # Button text
Const("query") # additional query. Optional
Const("query"), # additional query. Optional
),
state=MySG.main
)
state=MySG.main,
),
)
12 changes: 5 additions & 7 deletions docs/widgets/hiding/example.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from typing import Dict

from aiogram.filters.state import StatesGroup, State
from aiogram.filters.state import State, StatesGroup
from magic_filter import F

from aiogram_dialog import Window, DialogManager
from aiogram_dialog import DialogManager, Window
from aiogram_dialog.widgets.common import Whenable
from aiogram_dialog.widgets.kbd import Button, Row, Group
from aiogram_dialog.widgets.kbd import Button, Group, Row
from aiogram_dialog.widgets.text import Const, Format, Multi


Expand All @@ -20,15 +18,15 @@ async def get_data(**kwargs):
}


def is_tishka17(data: Dict, widget: Whenable, manager: DialogManager):
def is_tishka17(data: dict, widget: Whenable, manager: DialogManager):
return data.get("name") == "Tishka17"


window = Window(
Multi(
Const("Hello"),
Format("{name}", when="extended"),
sep=" "
sep=" ",
),
Group(
Row(
Expand Down
8 changes: 5 additions & 3 deletions docs/widgets/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ Widgets and Rendering
Base information
********************

Currently there are 4 kinds of widgets: :ref:`texts <text_widgets>`, :ref:`keyboards <keyboard_widgets>`,
:ref:`input <input_widgets>`, :ref:`media<media_widgets>` and you can create your own :ref:`widgets<custom_widgets>`.
Currently there are 5 kinds of widgets: :ref:`texts <text_widgets>`, :ref:`keyboards <keyboard_widgets>`,
:ref:`input <input_widgets>`, :ref:`media<media_widgets>`, :ref:`link preview<link_preview>` and you can create your own :ref:`widgets<custom_widgets>`.

* **Texts** used to render text anywhere in dialog. It can be message text, button title and so on.
* **Keyboards** represent parts of ``InlineKeyboard``
* **Media** represent media attachment to message
* **Input** allows to process incoming messages from user. Is has no representation.
* **Link Preview** used to manage link previews in messages.

Widgets can display static (e.g. ``Const``) and dynamic (e.g. ``Format``) content. To use dynamic data you have to set it. See :ref:`passing data <passing_data>`.

Expand All @@ -37,5 +38,6 @@ Also there are 2 general types:
keyboard/index
input/index
media/index
link_preview/index
hiding/index
custom_widgets/index
custom_widgets/index
15 changes: 9 additions & 6 deletions docs/widgets/keyboard/calendar/custom.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from typing import Dict

from aiogram_dialog import DialogManager
from aiogram_dialog.widgets.kbd import (
Calendar, CalendarScope, CalendarUserConfig,
Calendar,
CalendarScope,
CalendarUserConfig,
)
from aiogram_dialog.widgets.kbd.calendar_kbd import (
CalendarDaysView, CalendarMonthView, CalendarScopeView, CalendarYearsView,
CalendarDaysView,
CalendarMonthView,
CalendarScopeView,
CalendarYearsView,
)
from aiogram_dialog.widgets.text import Const, Format


class CustomCalendar(Calendar):
def _init_views(self) -> Dict[CalendarScope, CalendarScopeView]:
def _init_views(self) -> dict[CalendarScope, CalendarScopeView]:
return {
CalendarScope.DAYS: CalendarDaysView(
self._item_callback_data, self.config,
Expand All @@ -28,7 +31,7 @@ def _init_views(self) -> Dict[CalendarScope, CalendarScopeView]:

async def _get_user_config(
self,
data: Dict,
data: dict,
manager: DialogManager,
) -> CalendarUserConfig:
return CalendarUserConfig(
Expand Down
27 changes: 27 additions & 0 deletions docs/widgets/link_preview/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from aiogram.filters.state import State, StatesGroup

from aiogram_dialog import Window
from aiogram_dialog.widgets.link_preview import LinkPreview
from aiogram_dialog.widgets.text import Const


class SG(StatesGroup):
MAIN = State()
SECOND = State()


window = Window(
Const("https://nplus1.ru/news/2024/05/23/voyager-1-science-data"),
LinkPreview(is_disabled=True),
state=SG.MAIN,
)

second_window = Window(
Const("some text"),
LinkPreview(
url=Const("https://nplus1.ru/news/2024/05/23/voyager-1-science-data"),
prefer_small_media=True,
show_above_text=True,
),
state=SG.MAIN,
)
23 changes: 23 additions & 0 deletions docs/widgets/link_preview/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. _link_preview:

LinkPreview
*************

The **LinkPreview** widget is used to manage link previews in messages.

Parameters:

* ``url``: A ``TextWidget`` with URL to be used in the link preview. If not provided, the first URL found in the message will be used.
* ``is_disabled``: that controls whether the link preview is displayed. If ``True``, the preview will be disabled.
* ``prefer_small_media``: that controls if the media in the link preview should be displayed in a smaller size. Ignored if media size change is not supported.
* ``prefer_large_media``: that controls if the media in the link preview should be enlarged. Ignored if media size change is not supported.
* ``show_above_text``: that specifies whether the link preview should be displayed above the message text. If ``True``, link preview be displayed above the message text.


Code example:

.. literalinclude:: ./example.py

.. autoclass:: aiogram_dialog.widgets.link_preview.LinkPreview
:special-members: __init__
:members: render_link_preview, _render_link_preview
Loading
Loading