From 15c9821195a2fbe037cc5ee9d749187243c0ee21 Mon Sep 17 00:00:00 2001 From: waza! Date: Thu, 20 Jul 2017 06:33:18 +0700 Subject: [PATCH] refactor: Use modular DRY on version --- tests/test_commands.py | 5 ++++- tululbot/__init__.py | 3 +++ tululbot/commands.py | 5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_commands.py b/tests/test_commands.py index f856c4c..f74f514 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -2,6 +2,8 @@ from tululbot.commands import leli, quote, who, slang, hotline, hbd, kbbi, eid, xmas, kawin +from tululbot import VERSION + class TestLeliCommand: @@ -110,11 +112,12 @@ def test_who(fake_message, mocker): who(fake_message) expected_text = ( - 'TululBot v1.11.2\n\n' + 'TululBot v{}\n\n' 'Enhancing your tulul experience since 2015\n\n' 'Contribute on https://github.com/tulul/tululbot\n\n' "We're hiring! Contact @iqbalmineraltown for details" ) + expected_text = expected_text.format(VERSION) mock_reply_to.assert_called_once_with(fake_message, expected_text, disable_web_page_preview=True) diff --git a/tululbot/__init__.py b/tululbot/__init__.py index 350c98d..badc66c 100644 --- a/tululbot/__init__.py +++ b/tululbot/__init__.py @@ -12,6 +12,9 @@ from tululbot import commands # noqa +VERSION = '1.11.2' + + # Why do this? See https://core.telegram.org/bots/api#setwebhook webhook_url_path = '/{}'.format(app.config['TELEGRAM_BOT_TOKEN']) webhook_url_base = app.config['WEBHOOK_HOST'] diff --git a/tululbot/commands.py b/tululbot/commands.py index e2c2f86..dccdc7f 100644 --- a/tululbot/commands.py +++ b/tululbot/commands.py @@ -5,7 +5,7 @@ from tululbot.utils.quote import QuoteEngine from tululbot.utils.slang import lookup_slang from tululbot.utils.leli import search_on_google, search_on_wikipedia - +from tululbot import VERSION quote_engine = QuoteEngine() HOTLINE_MESSAGE_ID = app.config['HOTLINE_MESSAGE_ID'] @@ -55,11 +55,12 @@ def quote(message): def who(message): app.logger.debug('Detected who command {!r}'.format(message.text)) about_text = ( - 'TululBot v1.11.2\n\n' + 'TululBot v{}\n\n' 'Enhancing your tulul experience since 2015\n\n' 'Contribute on https://github.com/tulul/tululbot\n\n' "We're hiring! Contact @iqbalmineraltown for details" ) + about_text = about_text.format(VERSION) return bot.reply_to(message, about_text, disable_web_page_preview=True)