Skip to content
This repository was archived by the owner on Jul 1, 2021. It is now read-only.

Commit 60d79a4

Browse files
committed
update demo.js
1 parent 0092e59 commit 60d79a4

7 files changed

+220
-134
lines changed

LICENSE

+1-43
Original file line numberDiff line numberDiff line change
@@ -616,46 +616,4 @@ an absolute waiver of all civil liability in connection with the
616616
Program, unless a warranty or assumption of liability accompanies a
617617
copy of the Program in return for a fee.
618618

619-
END OF TERMS AND CONDITIONS
620-
621-
How to Apply These Terms to Your New Programs
622-
623-
If you develop a new program, and you want it to be of the greatest
624-
possible use to the public, the best way to achieve this is to make it
625-
free software which everyone can redistribute and change under these terms.
626-
627-
To do so, attach the following notices to the program. It is safest
628-
to attach them to the start of each source file to most effectively
629-
state the exclusion of warranty; and each file should have at least
630-
the "copyright" line and a pointer to where the full notice is found.
631-
632-
<one line to give the program's name and a brief idea of what it does.>
633-
Copyright (C) <year> <name of author>
634-
635-
This program is free software: you can redistribute it and/or modify
636-
it under the terms of the GNU Affero General Public License as published
637-
by the Free Software Foundation, either version 3 of the License, or
638-
(at your option) any later version.
639-
640-
This program is distributed in the hope that it will be useful,
641-
but WITHOUT ANY WARRANTY; without even the implied warranty of
642-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643-
GNU Affero General Public License for more details.
644-
645-
You should have received a copy of the GNU Affero General Public License
646-
along with this program. If not, see <https://www.gnu.org/licenses/>.
647-
648-
Also add information on how to contact you by electronic and paper mail.
649-
650-
If your software can interact with users remotely through a computer
651-
network, you should also make sure that it provides a way for users to
652-
get its source. For example, if your program is a web application, its
653-
interface could display a "Source" link that leads users to an archive
654-
of the code. There are many ways you could offer source, and different
655-
solutions will be better for different programs; see section 13 for the
656-
specific requirements.
657-
658-
You should also get your employer (if you work as a programmer) or school,
659-
if any, to sign a "copyright disclaimer" for the program, if necessary.
660-
For more information on this, and how to apply and follow the GNU AGPL, see
661-
<https://www.gnu.org/licenses/>.
619+
END OF TERMS AND CONDITIONS

README.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,32 @@ java -jar rhino-1.7.12.jar -f source/demo.js
6161
## To-Do
6262
- [x] 编写SDK文档
6363
- [ ] 支持监听EventMessage
64-
- [ ] 将MozillaRhino整合成mirai插件
64+
- [ ] 将MozillaRhino整合成mirai插件
65+
66+
## Update Log
67+
68+
### 2020.04.05 → 1.1_alpha
69+
* 修复运行30分钟后出现的bug.
70+
* 添加消息撤回方法:Mirai.Session.recall().
71+
* 修复了捕捉消息出现错误时对错误的处理错误
72+
### 2020.04.04 → 1.0_alpha
73+
* Initial release
74+
75+
## License
76+
```
77+
mirai-rhinojs-sdk
78+
Copyright (C) 2020 StageGuard
79+
80+
This program is free software: you can redistribute it and/or modify
81+
it under the terms of the GNU Affero General Public License as published
82+
by the Free Software Foundation, either version 3 of the License, or
83+
(at your option) any later version.
84+
85+
This program is distributed in the hope that it will be useful,
86+
but WITHOUT ANY WARRANTY; without even the implied warranty of
87+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88+
GNU Affero General Public License for more details.
89+
90+
You should have received a copy of the GNU Affero General Public License
91+
along with this program. If not, see <https://www.gnu.org/licenses/>.
92+
```

README_en.md

+31-3
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ java -jar rhino-1.7.12.jar -f source/demo.js
3636
```
3737
Simple meeesage catcher script is running.
3838

39-
![运行成功](https://cdn.jsdelivr.net/gh/StageGuard/mirai-rhinojs-sdk/static/status.png)
39+
![Success](https://cdn.jsdelivr.net/gh/StageGuard/mirai-rhinojs-sdk/static/status.png)
4040

4141
Now try to send a poke message(SIXSIXSIX) to your bot.
4242

43-
![Poke消息](https://cdn.jsdelivr.net/gh/StageGuard/mirai-rhinojs-sdk/static/poke.png)
43+
![Poke message](https://cdn.jsdelivr.net/gh/StageGuard/mirai-rhinojs-sdk/static/poke.png)
4444

4545
----
4646

@@ -57,4 +57,32 @@ All methods and usage can be found in [SDK Documentation](https://stageguard.top
5757
## To-Do
5858
- [x] 编写SDK文档
5959
- [ ] 支持监听EventMessage
60-
- [ ] 将MozillaRhino整合成mirai插件
60+
- [ ] 将MozillaRhino整合成mirai插件
61+
62+
## Update Log
63+
64+
### Apr 5th, 2020 → 1.1_alpha
65+
* Fix a bug which causes an error after running 30 minutes.
66+
* Add Mirai.Session.recall(). Now you can recall message.
67+
* Fix an error while error occurred when hooking meeeages.
68+
### Apr 4th, 2020 → 1.0_alpha
69+
* Initial release
70+
71+
## License
72+
```
73+
mirai-rhinojs-sdk
74+
Copyright (C) 2020 StageGuard
75+
76+
This program is free software: you can redistribute it and/or modify
77+
it under the terms of the GNU Affero General Public License as published
78+
by the Free Software Foundation, either version 3 of the License, or
79+
(at your option) any later version.
80+
81+
This program is distributed in the hope that it will be useful,
82+
but WITHOUT ANY WARRANTY; without even the implied warranty of
83+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84+
GNU Affero General Public License for more details.
85+
86+
You should have received a copy of the GNU Affero General Public License
87+
along with this program. If not, see <https://www.gnu.org/licenses/>.
88+
```

source/FileIO.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
mirai-rhinojs-sdk
3+
Copyright (C) 2020 StageGuard
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
119
{
220
module: "FileIO",
321
STRING: 1,

source/LinuxShell.js

+105-87
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,106 @@
1-
{
2-
module: "Shell",
3-
4-
BASH: "bash",
5-
SH: "sh",
6-
COMMAND_EXIT: "exit",
7-
COMMAND_LINE_RND: "\n",
8-
9-
gThreadGroup: new java.lang.ThreadGroup("ShellGroups"),
10-
11-
Executor: (function() {
12-
var r = function(shell) {
13-
this.shell = shell;
14-
this.thread = null;
15-
this.timeout_limit = 300000;
16-
};
17-
r.prototype = {
18-
setLoginShell: function(s) {
19-
if (s) this.shell = s;
20-
},
21-
getLoginShell: function() {
22-
return this.shell;
23-
},
24-
setTimeoutLimit: function(time) {
25-
if (time) this.timeout_limit = time;
26-
},
27-
getTimeoutLimit: function(time) {
28-
return this.timeout_limit;
29-
},
30-
execute: function(command) {
31-
var process, processBuilder, os;
32-
var successResult = null,
33-
errorResult = null;
34-
var shell = this.shell;
35-
var rResult = null;
36-
var timeout_limit = this.timeout_limit;
37-
try {
38-
processBuilder = new java.lang.ProcessBuilder(shell, "-c", command);
39-
processBuilder.directory(new java.io.File(java.lang.System.getProperty("user.home")));
40-
process = processBuilder.start(); (new java.lang.Thread(new java.lang.Runnable({
41-
run: function() {
42-
java.lang.Thread.sleep(timeout_limit);
43-
if (process != null) process.destroy();
44-
}
45-
}))).start();
46-
rResult = process.waitFor();
47-
successMsg = new java.lang.StringBuilder();
48-
errorMsg = new java.lang.StringBuilder();
49-
successResult = new java.io.BufferedReader(new java.io.InputStreamReader(process.getInputStream()));
50-
errorResult = new java.io.BufferedReader(new java.io.InputStreamReader(process.getErrorStream()));
51-
var s;
52-
while ((s = successResult.readLine()) != null) {
53-
successMsg.append(s);
54-
successMsg.append(Shell.COMMAND_LINE_RND);
55-
}
56-
while ((s = errorResult.readLine()) != null) {
57-
errorMsg.append(s);;
58-
errorMsg.append(Shell.COMMAND_LINE_RND);
59-
}
60-
if (successResult != null) successResult.close();
61-
if (errorResult != null) errorResult.close();
62-
if (process != null) process.destroy();
63-
process = null;
64-
return {
65-
code: rResult,
66-
success: successMsg.toString(),
67-
error: errorMsg.toString()
68-
};
69-
} catch(error) {
70-
Log.i("Timeout: " + command);
71-
if (successResult != null) successResult.close();
72-
if (errorResult != null) errorResult.close();
73-
if (process != null) process.destroy();
74-
process = null;
75-
return {
76-
code: 1,
77-
success: "",
78-
error: "Timeout after " + (timeout_limit / 1000) + " seconds."
79-
};
80-
}
81-
82-
},
83-
terminate: function() {},
84-
};
85-
return r;
86-
} ()),
87-
1+
/*
2+
mirai-rhinojs-sdk
3+
Copyright (C) 2020 StageGuard
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
{
20+
module: "Shell",
21+
22+
BASH: "bash",
23+
SH: "sh",
24+
COMMAND_EXIT: "exit",
25+
COMMAND_LINE_RND: "\n",
26+
27+
gThreadGroup: new java.lang.ThreadGroup("ShellGroups"),
28+
29+
Executor: (function() {
30+
var r = function(shell) {
31+
this.shell = shell;
32+
this.thread = null;
33+
this.timeout_limit = 300000;
34+
};
35+
r.prototype = {
36+
setLoginShell: function(s) {
37+
if (s) this.shell = s;
38+
},
39+
getLoginShell: function() {
40+
return this.shell;
41+
},
42+
setTimeoutLimit: function(time) {
43+
if (time) this.timeout_limit = time;
44+
},
45+
getTimeoutLimit: function(time) {
46+
return this.timeout_limit;
47+
},
48+
execute: function(command) {
49+
var process, processBuilder, os;
50+
var successResult = null,
51+
errorResult = null;
52+
var shell = this.shell;
53+
var rResult = null;
54+
var timeout_limit = this.timeout_limit;
55+
try {
56+
processBuilder = new java.lang.ProcessBuilder(shell, "-c", command);
57+
processBuilder.directory(new java.io.File(java.lang.System.getProperty("user.home")));
58+
process = processBuilder.start(); (new java.lang.Thread(new java.lang.Runnable({
59+
run: function() {
60+
java.lang.Thread.sleep(timeout_limit);
61+
if (process != null) process.destroy();
62+
}
63+
}))).start();
64+
rResult = process.waitFor();
65+
successMsg = new java.lang.StringBuilder();
66+
errorMsg = new java.lang.StringBuilder();
67+
successResult = new java.io.BufferedReader(new java.io.InputStreamReader(process.getInputStream()));
68+
errorResult = new java.io.BufferedReader(new java.io.InputStreamReader(process.getErrorStream()));
69+
var s;
70+
while ((s = successResult.readLine()) != null) {
71+
successMsg.append(s);
72+
successMsg.append(Shell.COMMAND_LINE_RND);
73+
}
74+
while ((s = errorResult.readLine()) != null) {
75+
errorMsg.append(s);;
76+
errorMsg.append(Shell.COMMAND_LINE_RND);
77+
}
78+
if (successResult != null) successResult.close();
79+
if (errorResult != null) errorResult.close();
80+
if (process != null) process.destroy();
81+
process = null;
82+
return {
83+
code: rResult,
84+
success: successMsg.toString(),
85+
error: errorMsg.toString()
86+
};
87+
} catch(error) {
88+
Log.i("Timeout: " + command);
89+
if (successResult != null) successResult.close();
90+
if (errorResult != null) errorResult.close();
91+
if (process != null) process.destroy();
92+
process = null;
93+
return {
94+
code: 1,
95+
success: "",
96+
error: "Timeout after " + (timeout_limit / 1000) + " seconds."
97+
};
98+
}
99+
100+
},
101+
terminate: function() {},
102+
};
103+
return r;
104+
} ()),
105+
88106
}

source/MiraiBot_HTTP.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
mirai-rhinojs-sdk
3+
Copyright (C) 2020 StageGuard
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
119
function() {
220
if (__g_modules.indexOf("NetworkUtils") == -1) {
321
throw "Couldn't find module \"NetworkUtils\" in module list.";

source/NetworkUtils.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
mirai-rhinojs-sdk
3+
Copyright (C) 2020 StageGuard
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
119
{
220
module: "NetworkUtils",
321
getInputStream: function(url, headers) {

0 commit comments

Comments
 (0)