Skip to content

Commit

Permalink
♻️ while true vs iteration for start
Browse files Browse the repository at this point in the history
  • Loading branch information
mraniki committed Jul 26, 2023
1 parent 7044ace commit d9a852a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 36 deletions.
9 changes: 4 additions & 5 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
29 changes: 0 additions & 29 deletions tt/talky_settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
6 changes: 4 additions & 2 deletions tt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d9a852a

Please sign in to comment.