mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
add schedv2_did_answer_review_card hook
This commit is contained in:
parent
083e4a0b66
commit
8752b050ce
3 changed files with 30 additions and 1 deletions
|
@ -307,6 +307,30 @@ class _NotesWillBeDeletedHook:
|
|||
notes_will_be_deleted = _NotesWillBeDeletedHook()
|
||||
|
||||
|
||||
class _Schedv2DidAnswerReviewCardHook:
|
||||
_hooks: List[Callable[["anki.cards.Card", int, bool], None]] = []
|
||||
|
||||
def append(self, cb: Callable[["anki.cards.Card", int, bool], None]) -> None:
|
||||
"""(card: anki.cards.Card, ease: int, early: bool)"""
|
||||
self._hooks.append(cb)
|
||||
|
||||
def remove(self, cb: Callable[["anki.cards.Card", int, bool], None]) -> None:
|
||||
if cb in self._hooks:
|
||||
self._hooks.remove(cb)
|
||||
|
||||
def __call__(self, card: anki.cards.Card, ease: int, early: bool) -> None:
|
||||
for hook in self._hooks:
|
||||
try:
|
||||
hook(card, ease, early)
|
||||
except:
|
||||
# if the hook fails, remove it
|
||||
self._hooks.remove(hook)
|
||||
raise
|
||||
|
||||
|
||||
schedv2_did_answer_review_card = _Schedv2DidAnswerReviewCardHook()
|
||||
|
||||
|
||||
class _SchemaWillChangeFilter:
|
||||
_hooks: List[Callable[[bool], bool]] = []
|
||||
|
||||
|
|
|
@ -959,7 +959,7 @@ select id from cards where did in %s and queue = 2 and due <= ? limit ?)"""
|
|||
|
||||
def _answerRevCard(self, card: Card, ease: int) -> None:
|
||||
delay = 0
|
||||
early = card.odid and (card.odue > self.today)
|
||||
early = bool(card.odid and (card.odue > self.today))
|
||||
type = early and 3 or 1
|
||||
|
||||
if ease == 1:
|
||||
|
@ -967,6 +967,7 @@ select id from cards where did in %s and queue = 2 and due <= ? limit ?)"""
|
|||
else:
|
||||
self._rescheduleRev(card, ease, early)
|
||||
|
||||
hooks.schedv2_did_answer_review_card(card, ease, early)
|
||||
self._logRev(card, ease, delay, type)
|
||||
|
||||
def _rescheduleLapse(self, card: Card) -> Any:
|
||||
|
|
|
@ -75,6 +75,10 @@ hooks = [
|
|||
],
|
||||
doc="Can modify the resulting text after rendering completes.",
|
||||
),
|
||||
Hook(
|
||||
name="schedv2_did_answer_review_card",
|
||||
args=["card: anki.cards.Card", "ease: int", "early: bool"],
|
||||
),
|
||||
]
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in a new issue