Leech Hook for v3 scheduler

Hey all,

Is there a hook or some way for add-ons to know when a card has leeched with the v3 scheduler? The most I found was card_did_leech, but as documented, this only works on the v1 and v2 scheduler.

You could use reviewer_will_answer_card to inspect _v3.states to see if leeched is set for the chosen ease.

1 Like

This works, thank you! For anyone who’s interested, here’s some (messy) code that works specifically on the v3 scheduler (the assumption is that a leeched card will always be tagged with “leech”):

from typing import Optional, Literal

from aqt import gui_hooks, mw
from aqt.reviewer import Reviewer
from anki.cards import Card


def check_leech(
    ease_tuple: tuple[bool, Literal[1, 2, 3, 4]], reviewer: Reviewer, card: Card
):
    will_leech_if_again: Optional[bool] = None
    has_leech_tag: Optional[bool] = None
    try:
        will_leech_if_again = reviewer._v3.states.again.normal.relearning.review.leeched
    except AttributeError:
        print("cannot get reviewer._v3.states.(...).leeched")

    try:
        has_leech_tag = mw.col.get_note(card.nid).has_tag("leech")
    except AttributeError:
        print("cannot check if reviewed card is already a leech")

    if will_leech_if_again and has_leech_tag == False and ease_tuple[1] == 1:
        print("The card was freshly leeched!")

    return ease_tuple  # do nothing


gui_hooks.reviewer_will_answer_card.append(check_leech)

Warning: The above is probably not the most ideal way of doing this, but it at least works for me.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.