What's Changed
Batched queries
Some query commands allow you to target multiple actions at once.
This comes handy when for example moving multiple clients at once: `clientmove clid=1|clid=2 cid=3`.
But some commands don't allow you to do this.
`clientpoke` is a good example. You can only target one client at a time.
To poke all clients on the server, you would do something like this:
python
bot.command("poke", raw=True, help_text="pokes all clients with a message")
async def poke(bot: TSBot, ctx: TSCtx, message: str) -> None:
clients_list = await bot.send(query("clientlist"))
poke_query = query("clientpoke").params(msg=message)
await asyncio.gather(
*(bot.send(poke_query.params(clid=client["clid"])) for client in clients_list)
)
This would mean sending each query after another. Those queries would have to wait for a response.
If the bot instance is far away from the actual server from a networking perspective,
this would cause huge delays between each poke.
With `bot.send_batched()` method, you can refactor the poke command:
Poke all the clients on the server with a message with minimal network delay:
python
bot.command("poke", raw=True, help_text="pokes all clients with a message")
async def poke(bot: TSBot, ctx: TSCtx, message: str) -> None:
clients_list = await bot.send(query("clientlist"))
poke_query = query("clientpoke").params(msg=message)
await bot.send_batched(
poke_query.params(clid=client["clid"])
for client in clients_list
if client["client_type"] == "0"
)
PR: 69
---
Remove `ready` event
Completely remove deprecated `ready` event.
To migrate: change `ready` -> `connect`
PR: 71
---
Task object `.cancel()` method
You can now cancel background tasks from the object itself.
python
some_task = bot.register_task(some_task_handler)
Previously you would call bot.remove_task() to cancel
bot.remove_task(some_task)
Now you can cancel the task from the task object
some_task.cancel()
PR: 70
---
Debug query timings
Debug loggers now show how long each query took to execute.
Example log line:
`[DEBUG][20:07:13][tsbot] Query took 0.01268 seconds to execute`
PR: 68
Fixes
* Guarantee `bot.connected` is only set when bot is connected. 7182a7407eccc3a6055bb42009df201fc1bc477e
* Bot closing on connection error without trying to re-establish connection. 28fa501b798f48801a0d741417e7befd67e27385
* `TSEventOnceHandler` could run more than one time if event was emitted multiple times. 2cae0440afe3d661efce5c92b4441b6e616b200b
- This wouldn't run the actual handler, but raise `ValueError` when trying to remove the event.
**Full Changelog**: https://github.com/jykob/TSBot/compare/1.5.1...1.6.0