1
+ package com.sungbin.gitkakaobot.bot
2
+
3
+ import android.content.Context
4
+ import com.sungbin.androidutils.util.StorageUtil
5
+ import com.sungbin.gitkakaobot.util.manager.StackManager
6
+ import org.mozilla.javascript.ScriptableObject
7
+ import org.mozilla.javascript.annotations.JSStaticFunction
8
+ import java.text.SimpleDateFormat
9
+ import java.util.*
10
+
11
+ object ApiClass {
12
+
13
+ private lateinit var context: Context
14
+ fun init (context : Context ) {
15
+ ApiClass .context = context
16
+ }
17
+
18
+ class Log : ScriptableObject () {
19
+ override fun getClassName () = " Log"
20
+
21
+ companion object {
22
+ @JvmStatic
23
+ @JSStaticFunction
24
+ fun e (name : String , content : String ) {
25
+ val now = System .currentTimeMillis()
26
+ val date = Date (now)
27
+ val sdf = SimpleDateFormat (" hh:mm:ss" , Locale .getDefault())
28
+ val time = sdf.format(date)
29
+
30
+ // LogUtils.save(name, content, time, LogUtils.Type.ERROR)
31
+ }
32
+
33
+ @JvmStatic
34
+ @JSStaticFunction
35
+ fun i (name : String , content : String ) {
36
+ val now = System .currentTimeMillis()
37
+ val date = Date (now)
38
+ val sdf = SimpleDateFormat (" hh:mm:ss" , Locale .getDefault())
39
+ val time = sdf.format(date)
40
+
41
+ // LogUtils.save(name, content, time, LogUtils.Type.INFO)
42
+ }
43
+
44
+ @JvmStatic
45
+ @JSStaticFunction
46
+ fun s (name : String , content : String ) {
47
+ val now = System .currentTimeMillis()
48
+ val date = Date (now)
49
+ val sdf = SimpleDateFormat (" hh:mm:ss" , Locale .getDefault())
50
+ val time = sdf.format(date)
51
+
52
+ // LogUtils.save(name, content, time, LogUtils.Type.SUCCESS)
53
+ }
54
+
55
+ }
56
+ }
57
+
58
+ class Api : ScriptableObject () {
59
+ override fun getClassName () = " Api"
60
+
61
+ companion object {
62
+ @JvmStatic
63
+ @JSStaticFunction
64
+ fun getContext (): Context {
65
+ return context
66
+ }
67
+
68
+ /* @JvmStatic
69
+ @JSStaticFunction
70
+ fun replyRoom(room: String, msg: String): Boolean {
71
+ return com.sungbin.autoreply.bot.three.api.Api.replyRoom(room, msg)
72
+ }
73
+
74
+ @JvmStatic
75
+ @JSStaticFunction
76
+ fun replyRoomShowAll(room: String, msg1: String, msg2: String): Boolean {
77
+ return com.sungbin.autoreply.bot.three.api.Api.replyRoomShowAll(room, msg1, msg2)
78
+ }*/
79
+ }
80
+ }
81
+
82
+ class Scope : ScriptableObject () {
83
+ override fun getClassName () = " Scope"
84
+
85
+ companion object {
86
+ @JvmStatic
87
+ @JSStaticFunction
88
+ fun get (name : String ) = StackManager .scopes[name]
89
+ }
90
+ }
91
+
92
+ class File : ScriptableObject () {
93
+ override fun getClassName () = " File"
94
+
95
+ companion object {
96
+ @JvmStatic
97
+ @JSStaticFunction
98
+ fun read (path : String , _null : String? ) = StorageUtil .read(path, _null )
99
+
100
+ @JvmStatic
101
+ @JSStaticFunction
102
+ fun save (path : String , content : String ) = StorageUtil .save(path, content)
103
+
104
+ @JvmStatic
105
+ @JSStaticFunction
106
+ fun append (path : String , content : String ): Boolean {
107
+ val string = " ${StorageUtil .read(path, " " )}$content "
108
+ return save(path, string)
109
+ }
110
+
111
+ @JvmStatic
112
+ @JSStaticFunction
113
+ fun delete (path : String ) = StorageUtil .delete(path)
114
+
115
+ @JvmStatic
116
+ @JSStaticFunction
117
+ fun deleteAll (path : String ) = StorageUtil .deleteAll(path)
118
+ }
119
+ }
120
+
121
+ // todo: Api, UiUtil
122
+ }
0 commit comments