From 8d9163048a147b89fd3787fdd8597be787a94610 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Fri, 20 May 2022 17:00:38 -0400 Subject: [PATCH] Add apiReflect --- plugin/__init__.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/plugin/__init__.py b/plugin/__init__.py index eaad2c4..c43058a 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -1640,6 +1640,36 @@ class AnkiConnect: return False + + @util.api() + def apiReflect(self, scopes=None, actions=None): + if not isinstance(scopes, list): + raise Exception('scopes has invalid value') + if not (actions is None or isinstance(actions, list)): + raise Exception('actions has invalid value') + + cls = type(self) + scopes2 = [] + result = {'scopes': scopes2} + + if 'actions' in scopes: + if actions is None: + actions = dir(cls) + + methodNames = [] + for methodName in actions: + if not isinstance(methodName, str): + pass + method = getattr(cls, methodName, None) + if method is not None and getattr(method, 'api', False): + methodNames.append(methodName) + + scopes2.append('actions') + result['actions'] = methodNames + + return result + + # # Entry #