From d9a852a0114364b49e2c38668c7f41a1b341a4c0 Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Wed, 26 Jul 2023 07:20:51 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20while=20true=20vs=20iterat?= =?UTF-8?q?ion=20for=20start?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_unit.py | 9 ++++----- tt/talky_settings.toml | 29 ----------------------------- tt/utils.py | 6 ++++-- 3 files changed, 8 insertions(+), 36 deletions(-) diff --git a/tests/test_unit.py b/tests/test_unit.py index 20c124b14..89eab3450 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -113,14 +113,13 @@ async def test_start_bot(): listener_instance = Listener() listener_instance.handler = AsyncMock(spec=ChatManager) plugin_manager_instance = PluginManager() - async def side_effect(): - yield True - yield False - # with patch('tt.config.settings.BOT_RUNNING', side_effect=side_effect()): with patch('iamlistening.Listener', listener_instance): with patch('tt.plugins.plugin_manager', plugin_manager_instance): task = asyncio.create_task( - await start_bot(listener_instance, plugin_manager_instance)) + await start_bot( + listener_instance, + plugin_manager_instance, + max_iterations=1)) listener_instance.start.assert_awaited() plugin_manager_instance.start_plugins.assert_awaited() listener_instance.handler.get_latest_message.assert_awaited_once() diff --git a/tt/talky_settings.toml b/tt/talky_settings.toml index c501190be..9d50eb76e 100644 --- a/tt/talky_settings.toml +++ b/tt/talky_settings.toml @@ -110,7 +110,6 @@ helper_commands = "πŸ”€ /trading\nπŸ” /restart\nπŸ•ΈοΈ /network" bot_command_trading = "trading" bot_command_network = "network" bot_command_restart = "restart" -bot_running = true ping = "8.8.8.8" @@ -259,7 +258,6 @@ bot_command_bal = "bal" bot_command_pos = "pos" bot_command_pnl_daily = "d" bot_command_quote = "q" -bot_running = true trading_enabled = true trading_risk_amount = 10 plugin_enabled = true @@ -357,7 +355,6 @@ helper_enabled = true helper_commands = "πŸ”€/trading\nπŸ” /restart" bot_command_trading = "trading" bot_command_restart = "restart" -bot_running = true ping = "8.8.8.8" talkytrend_enabled = true talkytrend_commands = "πŸ“Ί /live\nπŸ“° /news\nπŸ“Š /trend" @@ -377,7 +374,6 @@ helper_enabled = true helper_commands = "πŸ”€/trading\nπŸ” /restart" bot_command_trading = "trading" bot_command_restart = "restart" -bot_running = true ping = "8.8.8.8" dxsp_enabled = true dxsp_commands = "🎯 BUY WBTC\n🎯 /q WBTC\n 🏦 /bal\n 🏦 /pos\n" @@ -392,28 +388,3 @@ talkytrend_commands = "πŸ“Ί /live\nπŸ“° /news\nπŸ“Š /trend" bot_command_trend = "trend" bot_command_tv = "live" bot_command_news = "news" - -[botdown] -VALUE = "On Testing CEX_binance" -apprise_url = "json://localhost" -apprise_format = "NotifyFormat.MARKDOWN" -plugin_directory = "tt.plugins.default_plugins" -cex_enabled = true -ccxt_commands = "🎯 BUY BTCUSDT\n🎯 /q BTCUSDT\n🏦 /bal\n🏦 /pos\n" -cex_name = 'binance' -cex_api = 'api_key' -cex_secret = 'secret_key' -cex_password = 'password' -cex_defaulttype = 'spot' -cex_testmode = true -helper_enabled = true -helper_commands = "πŸ”€/trading\nπŸ” /restart" -bot_command_trading = "trading" -bot_command_restart = "restart" -bot_running = false -ping = "8.8.8.8" -talkytrend_enabled = true -talkytrend_commands = "πŸ“Ί /live\nπŸ“° /news\nπŸ“Š /trend" -bot_command_trend = "trend" -bot_command_tv = "live" -bot_command_news = "news" \ No newline at end of file diff --git a/tt/utils.py b/tt/utils.py index bc70dad5d..5b643e73a 100644 --- a/tt/utils.py +++ b/tt/utils.py @@ -43,15 +43,17 @@ async def start_plugins(plugin_manager): loop.create_task(plugin_manager.start_all_plugins()) -async def start_bot(listener, plugin_manager): +async def start_bot(listener, plugin_manager, max_iterations=None): """ πŸ‘‚ Start the chat listener and dispatch to plugins """ await listener.start() await start_plugins(plugin_manager) - while settings.bot_running: + iteration = 0 + while not max_iterations or iteration < max_iterations: msg = await listener.handler.get_latest_message() if msg and settings.plugin_enabled: await plugin_manager.process_message(msg) await asyncio.sleep(1) + iteration += 1 \ No newline at end of file