-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresponse.js
96 lines (93 loc) · 1.58 KB
/
response.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
var modules = [];
var shared = {};
function readAll(inputStream)
{
let len = inputStream.available();
let buf = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, len);
if(inputStream.read(buf) != len)
{
throw "Failed to read all";
}
return new java.lang.String(buf);
}
function loadModule(path)
{
try
{
let e = "Invalid v1g module or I/O exception occurred";
var zf = new java.util.zip.ZipFile(path);
var module_json = zf.getEntry("module.json");
if(module_json == null || module_json.isDirectory())
{
throw e;
}
var zis = zf.getInputStream(module_json);
var module = JSON.parse(readAll(zis));
zis.close();
zis = undefined;
if(module.type !== "v1g")
{
throw e;
}
if(typeof module.name == "string")
{
var name = module.name;
}
else
{
throw e;
}
if(typeof module.version == "string")
{
var version = module.version;
}
else
{
throw e;
}
if(typeof module.filename != "string")
{
throw e;
}
var script = zf.getEntry(module.filename);
var func = new Function("shared", readAll(zis = zf.getInputStream(script)));
zis.close();
zis = undefined;
if(func = func(shared))
{
if(typeof func != "function")
{
throw e;
}
modules.push(func);
}
else
{
throw "Failed to load module";
}
}
catch(e)
{
if(zis)
{
try
{
zis.close();
}
catch(e)
{
}
}
throw e;
}
}
function response(room, msg, sender, isGroupChat, replier, imageDB)
{
for(let i = 0; i < modules.length; i++)
{
if(modules[i](room, msg, sender, isGroupChat, replier, imageDB))
{
return;
}
}
}