rakshasa / rtorrent

rTorrent BitTorrent client
https://github.com/rakshasa/rtorrent/wiki
GNU General Public License v2.0
4.15k stars 414 forks source link

How to use logical operators? #1219

Open Phibonacci opened 1 year ago

Phibonacci commented 1 year ago

I see rtorrent scripting language can use logical operators like AND and NOT but the documentation has a "TODO".

If I wanted to stop seeding any torrents after it reaches a ratio of 2 and only if it does not use a specific tracker, should I do it like that:

method.insert = limit_ratio, simple, \
    "(d.multicall.filtered=started,\"greater=d.ratio=,value=2000,and=not=string.equals=(d.tracker_domain),mytracker.com\",d.stop=)"
schedule2 = schedule_ratio,0,60,limit_ratio
kannibalox commented 1 year ago

The basic syntax is and={cond1,cond2,...}, e.g.

rtxmlrpc d.multicall.filtered '' main 'and={true=,true=}' d.hash=

To do what you're looking for, I'd suggest breaking it up into multiple methods for readability and easy trouble shooting:

method.insert=d.ratio_check,simple,"greater=d.ratio=,value=2000"
method.insert=d.tracker_check,simple,"string.equals=$d.tracker_domain=,mytracker.com"
method.insert = limit_ratio, simple, \
    "(d.multicall.filtered=(and={not=$d.tracker_check=,d.ratio_check=}),d.stop=)"
schedule2 = schedule_ratio,0,60,limit_ratio

I didn't 100% test this, and for some reason string.equals isn't working correctly for me, but that should at least give you the basic idea.

You could also create a ratio group and move any desired torrents into it via events or a schedule: https://github.com/rakshasa/rtorrent/wiki/RTorrentRatioHandling