diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0340d03ae3d4340da94c48ca6fc970cef76409c3..3697087dbb4a893a2f1ee5819034cc7e8e45b2d1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,22 +19,18 @@ variables: - poetry config virtualenvs.create false - poetry install -flake8: - extends: - - .test-template - script: - - flake8 --count . - pytest: extends: - .test-template script: - pytest -vv . -black: +linters: extends: - .test-template script: + - isort -c bot_s3rius + - flake8 --count . - black --check . build: diff --git a/bot_s3rius/actions/converters/currency.py b/bot_s3rius/actions/converters/currency.py index 6e190ae16bf1958a03e86b0b491d2372a2367c36..7d1fa48c35cd9df49c446c145cb452fac771317d 100644 --- a/bot_s3rius/actions/converters/currency.py +++ b/bot_s3rius/actions/converters/currency.py @@ -59,6 +59,12 @@ SUPPORTED_CURRENCIES = [ "JPY", ] +MEMES = { + (40, "UAH"): "штанi", + (300, "USD"): "один fisting", + (20, "USD"): "blowjob", +} + CURRENCY_PATTERN = ( rf"\s*((\d+)([\.,]\d+)?)\s+(" rf"{'|'.join(SUPPORTED_CURRENCIES + list(CURRENCY_MAPPING.keys()))})" @@ -82,18 +88,24 @@ async def replace_currency(event): for group in groups: c_info = get_info_from_group(group, CURRENCY_MAPPING) val_id = f"{c_info.val} {c_info.name}" + meme_extra = MEMES.get((int(c_info.val), c_info.name)) new_val = ( c_info.val * Decimal(currencies[c_info.name]["Value"]) / Decimal(currencies[c_info.name]["Nominal"]) ) + meme = "" + if meme_extra: + meme = f"{meme_extra} или " + if val_id not in currency_mapper: if c_info.sci: response += ( - f"`{c_info.val} {c_info.name} = {new_val.to_eng_string()} RUB`\n" + f"`{c_info.val} {c_info.name} = " + f"{meme}{new_val.to_eng_string()} RUB`\n" ) else: - response += f"`{c_info.val} {c_info.name} = {new_val:.2f} RUB`\n" + response += f"`{c_info.val} {c_info.name} = {meme}{new_val:.2f} RUB`\n" currency_mapper.append(val_id) await event.reply(response) diff --git a/bot_s3rius/utils/converters.py b/bot_s3rius/utils/converters.py index a6b2096f289ecd7901d82dc1677faef67331fc1a..eb5d1e6c44bc0e2613a4e8e359873e5fb0156cf9 100644 --- a/bot_s3rius/utils/converters.py +++ b/bot_s3rius/utils/converters.py @@ -5,7 +5,7 @@ from decimal import Decimal CapturedCurrency = namedtuple("CapturedCurrency", ("name", "source_val", "val", "sci")) -def get_info_from_group(capture_group, mapping): +def get_info_from_group(capture_group, mapping) -> CapturedCurrency: logging.debug(f"Parsing group: {capture_group}") name = capture_group[3] if name.lower() in mapping: diff --git a/pyproject.toml b/pyproject.toml index 68a82941176cfa6fc5505d4b3fd03b0560b81bf9..135c8013ed1f5092961daaa92d75c21be82a26c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "bot_s3rius" -version = "0.1.0" +version = "0.1.4" description = "Telegram bot for @s3rius_san" readme = "README.md" authors = ["Pavel Kirilin <win10@list.ru>"]