From 43bb7618c39560fae6b045e6c07cccf8a3613ed9 Mon Sep 17 00:00:00 2001 From: Pavel Kirilin <win10@list.ru> Date: Fri, 15 Oct 2021 21:36:46 +0400 Subject: [PATCH] Added memes. Signed-off-by: Pavel Kirilin <win10@list.ru> --- .gitlab-ci.yml | 10 +++------- bot_s3rius/actions/converters/currency.py | 16 ++++++++++++++-- bot_s3rius/utils/converters.py | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0340d03..3697087 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 6e190ae..7d1fa48 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 a6b2096..eb5d1e6 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: -- GitLab