Skip to content

Commit 7092b5d

Browse files
committed
Fixes
1 parent c865c3c commit 7092b5d

File tree

5 files changed

+52
-10
lines changed

5 files changed

+52
-10
lines changed

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = telegrambots-custom
3-
version = 0.0.6rc1
3+
version = 0.0.6rc2
44
author = immmdreza
55
author_email = [email protected]
66
description = A custom extension packages for telegrambots.

src/telegrambots/custom/contexts/_contexts/context_template.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(
3535
self.__update_type = update_type
3636
self.__handler_tag = handler_tag
3737
self.__args = args
38-
self.__kwargs = kwargs
38+
self.__metadata = kwargs
3939

4040
# extensions
4141
self.__propagation: Optional[PropagationExtension] = None
@@ -78,7 +78,7 @@ def args(self):
7878
@final
7979
@property
8080
def kwargs(self):
81-
return self.__kwargs
81+
return self.__metadata
8282

8383
@final
8484
@property
@@ -110,16 +110,18 @@ def __init__(
110110
**kwargs: Any,
111111
) -> None:
112112
super().__init__(dp, update, update_type, handler_tag, *args, **kwargs)
113-
self._metadata: dict[str, Any] = kwargs
114113

115114
def __getitem__(self, name: str):
116-
return self._metadata[name]
115+
return self.kwargs[name]
116+
117+
def __setitem__(self, name: str, value: Any):
118+
self.kwargs[name] = value
117119

118120
def __iter__(self):
119-
return iter(self._metadata)
121+
return iter(self.kwargs)
120122

121123
def __len__(self) -> int:
122-
return len(self._metadata)
124+
return len(self.kwargs)
123125

124126
@final
125127
@property

src/telegrambots/custom/dispatcher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ async def _process_update(self, update: Update):
196196
dispatcher_logger.info(
197197
f"Processing continuously handler {c.update_type.__name__}:{c.target_tag}"
198198
)
199+
c.kwargs.update(continue_with_key=c.keys)
199200
await self._do_handling(
200201
handler,
201202
update,
202203
c.target_tag,
203204
result.metadata,
204205
*c.args,
205206
**c.kwargs,
206-
continue_with_key=c.keys,
207207
)
208208
self._continuously_handlers.remove(batch)
209209
return # Don't process the update anymore

src/telegrambots/custom/handlers/exceptions/exception_handler.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from abc import ABC, abstractmethod
22
from typing import TYPE_CHECKING, Any, Callable, Coroutine
3+
from traceback import print_exception
34

45
if TYPE_CHECKING:
56
from ...dispatcher import Dispatcher
@@ -41,7 +42,7 @@ async def _handle_exception(self, dp: "Dispatcher", e: Exception):
4142

4243

4344
async def __handle_exception(dp: "Dispatcher", e: Exception):
44-
print(e)
45+
print_exception(e)
4546

4647

4748
default_exception_handler = ExceptionHandler(__handle_exception, Exception)

src/telegrambots/custom/helpers/buttons.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,42 @@
66

77

88
class InlineButtonBuilder:
9-
def __init__(self) -> None:
9+
"""An helper class to simplify the creation of InlineKeyboardMarkup"""
10+
11+
def __init__(
12+
self,
13+
create: Optional[
14+
Callable[[type[InlineKeyboardButton]], InlineKeyboardButton]
15+
] = None,
16+
) -> None:
17+
"""Create a new InlineButtonBuilder
18+
19+
An helper class to simplify the creation of InlineKeyboardMarkup
20+
21+
Args:
22+
create: A function that creates a new InlineKeyboardButton.
23+
"""
1024
self._buttons: list[list[InlineKeyboardButton]] = [[]]
25+
if create is not None:
26+
self.append_button(create)
27+
28+
def __call__(self):
29+
"""Return the InlineKeyboardMarkup from builder."""
30+
return self.build()
1131

1232
def append_button(
1333
self,
1434
create: Callable[[type[InlineKeyboardButton]], InlineKeyboardButton],
1535
row_index: Optional[int] = None,
1636
column_index: Optional[int] = None,
1737
):
38+
"""Append a button to the builder.
39+
40+
Args:
41+
create: A function that creates a new InlineKeyboardButton.
42+
row_index: The row index of the button.
43+
column_index: The column index of the button.
44+
"""
1845
if row_index is None:
1946
row_index = -1
2047

@@ -27,6 +54,11 @@ def append_button(
2754
def append_many_buttons(
2855
self, *create: Callable[[type[InlineKeyboardButton]], InlineKeyboardButton]
2956
):
57+
"""Append many buttons to the builder.
58+
59+
Args:
60+
*create: A list of functions that creates a new InlineKeyboardButton.
61+
"""
3062
for c in create:
3163
self.append_button(c)
3264
return self
@@ -38,6 +70,12 @@ def append_row(
3870
] = None,
3971
insert_index: Optional[int] = None,
4072
):
73+
"""Append a row to the builder.
74+
75+
Args:
76+
create: A function that creates a new InlineKeyboardButton.
77+
insert_index: The index of the row.
78+
"""
4179
to_append = [] if create is None else [create(InlineKeyboardButton)]
4280

4381
if insert_index is None:
@@ -47,4 +85,5 @@ def append_row(
4785
return self
4886

4987
def build(self):
88+
"""Return the InlineKeyboardMarkup from builder."""
5089
return InlineKeyboardMarkup(self._buttons)

0 commit comments

Comments
 (0)