Browse Source

feat(lib/ga): 新增 API ga.Wait/ClassWait/Ignore

dzp 1 năm trước cách đây
mục cha
commit
cf2c0286c5
1 tập tin đã thay đổi với 48 bổ sung0 xóa
  1. 48 0
      plugins/lib/ga.tin

+ 48 - 0
plugins/lib/ga.tin

@@ -88,6 +88,54 @@ event.Define {GA} {有参} {$MODULE} {接收到 IAC GA 时发射本事件,参
     };
 };
 
+///=== {
+// ## ga.Wait <回调代码> <钩子名称>
+//    等待下一个 GA 的到来,并在那时执行回调代码。
+// };
+#alias {ga.Wait} {
+    #local code     {%21};
+    #local hook     {%2};
+
+    #if { "$code" == "" || "$hook" == "" } {
+        xtt.Usage ga.Wait;
+        #return;
+    };
+
+    #line sub {escapes} event.HandleOnce GA {ga/$hook} {GA} {%21;#0};
+};
+
+///=== {
+// ## ga.ClassWait <回调代码> [<钩子名称>]
+//    类似于 ga.Wait,但是会在当前 #class 消亡时自动注销。
+//    因为可以自动注销,因此钩子名称可以省略。
+// };
+#alias {ga.ClassWait} {
+    #local code     {%21};
+    #local hook     {@default{{%2};@uuid{}}};
+
+    #if { "$code" == "" } {
+        xtt.Usage ga.ClassWait;
+        #return;
+    };
+
+    #line sub {escapes} event.ClassHandleOnce GA {ga/$hook} {GA} {%21;#0};
+};
+
+///=== {
+// ## ga.Ignore <钩子名称>
+//    忽略之前用 ga.Wait 或者 ga.ClassWait 注册的钩子。
+// };
+#alias {ga.Ignore} {
+    #local hook {%1};
+
+    #if { "$hook" == "" } {
+        xtt.Usage ga.Ignore;
+        #return;
+    };
+
+    event.UnHandle GA {ga/$hook} {GA};
+};
+
 #func {ga.ThisCmd} {
     #return {$gXttPipeLine[1]};
 };