Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyBozhko committed Dec 1, 2023
1 parent 36a883d commit a155050
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
21 changes: 15 additions & 6 deletions reqs/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ botocore==1.23.32
# boto3
# expense-bot (pyproject.toml)
# s3transfer
build==1.0.3
# via pip-tools
cachetools==5.2.0
# via google-auth
certifi==2023.7.22
Expand Down Expand Up @@ -84,6 +86,8 @@ idna==3.3
# via
# requests
# yarl
importlib-metadata==6.8.0
# via build
iniconfig==1.1.1
# via pytest
isort==5.10.1
Expand All @@ -104,19 +108,19 @@ multidict==6.0.2
# via
# aiohttp
# yarl
mypy==0.961
mypy==1.0.1
# via expense-bot (pyproject.toml)
mypy-extensions==0.4.3
# via
# black
# mypy
packaging==21.3
# via pytest
# via
# build
# pytest
pathspec==0.9.0
# via black
pep517==0.12.0
# via pip-tools
pip-tools==6.6.2
pip-tools==6.12.1
# via expense-bot (pyproject.toml)
platformdirs==2.5.2
# via
Expand Down Expand Up @@ -148,6 +152,8 @@ pyparsing==3.0.9
# via
# httplib2
# packaging
pyproject-hooks==1.0.0
# via build
pytest==7.2.0
# via expense-bot (pyproject.toml)
python-dateutil==2.8.2
Expand All @@ -168,10 +174,11 @@ six==1.16.0
tomli==2.0.1
# via
# black
# build
# flake8-pyproject
# mypy
# pep517
# pylint
# pyproject-hooks
# pytest
tomlkit==0.11.0
# via pylint
Expand Down Expand Up @@ -199,6 +206,8 @@ wrapt==1.14.1
# via astroid
yarl==1.7.2
# via aiohttp
zipp==3.17.0
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# pip
Expand Down
3 changes: 2 additions & 1 deletion src/expense_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ async def handle_lambda_event(event: dict):
Note: this function is NOT stateless - but for now
it's OK to assume that AWS Lambda would reuse the same
runtime for handling a few requests back-to-back."""
update = Update.model_construct(json.loads(event["body"]))
values = json.loads(event["body"])
update = Update.model_construct(**values)
await dp.feed_update(bot, update)
6 changes: 4 additions & 2 deletions src/expense_bot/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def cmd_add_state0(
@dp.message(auth_required, StateFilter(Add.amount))
@default_message_logging
async def cmd_add_state1(message: Message, state: FSMContext):
await state.update_data(amount=float(message.text))
await state.update_data(amount=float(message.text or ""))
await state.set_state(Add.vendor)
await message.answer(
"Description?",
Expand All @@ -66,7 +66,7 @@ async def cmd_add_state1(message: Message, state: FSMContext):
async def cmd_add_state2(message: Message, state: FSMContext):
data = await state.get_data()

amt, dt, vnd = data["amount"], data["dt"], message.text
amt, dt, vnd = data["amount"], data["dt"], message.text or ""
item = ExpenseItem(
amt,
vnd,
Expand All @@ -81,6 +81,8 @@ async def cmd_add_state2(message: Message, state: FSMContext):
@dp.callback_query(auth_required, StateFilter(Add.vendor))
async def cb_add_state2(callback: CallbackQuery, state: FSMContext):
msg = callback.message
assert msg, "must not be None"

text = Text("👉 ", Italic(callback.data))
await msg.answer(**text.as_kwargs())

Expand Down
5 changes: 4 additions & 1 deletion src/expense_bot/commands/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class AccessDenied(Exception):

def auth_required(msg: Union[CallbackQuery, Message]) -> bool:
"""Allow messages from a single user only."""
if msg.from_user.id != 288450274:
user = msg.from_user
if not user or user.id != 288450274:
raise AccessDenied("Unauthorized!")
return True

Expand Down Expand Up @@ -100,6 +101,8 @@ def configure_start_command(dp: Dispatcher):
async def cmd_start(message: Message):
"""Handler for `start` command."""
user = message.from_user
assert user, "must not be None"

text = Text(
"Hi ",
TextMention(user.full_name, user=user),
Expand Down
4 changes: 3 additions & 1 deletion src/expense_bot/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ async def cmd_show_state0(
@dp.message(auth_required, StateFilter(Show.selected_date))
@default_message_logging
async def cmd_show_state1(message: Message, state: FSMContext):
await _do_show(message, message.text)
await _do_show(message, message.text or "")
await state.clear()

@dp.callback_query(auth_required, StateFilter(Show.selected_date))
async def cb_show_state1(callback: CallbackQuery, state: FSMContext):
msg = callback.message
assert msg, "must not be None"

text = Text("👉 ", Italic(callback.data))
await msg.answer(**text.as_kwargs())

Expand Down

0 comments on commit a155050

Please sign in to comment.