Skip to content

Commit 72c81da

Browse files
author
Boleslav Březovský
committed
FEAT: DO is now run in separate process
1 parent 124e097 commit 72c81da

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

redbot.red

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Red []
33
do load %redbot-options.red
44

55
do %gitter-api.red
6-
do %github.red
6+
do %github-v3.red
77

88
; --- support funcs
99

@@ -27,6 +27,16 @@ room: none
2727
messages: none
2828
reply: none
2929

30+
help: {
31+
* `/help` - show this help
32+
* `/time` - show current bot's time
33+
* `@botthebot do <code>` - do following code and print last value
34+
}
35+
{
36+
* **/issues** - show five latest issues
37+
* **/commits** - show five latest commits
38+
}
39+
3040
; --- basic commands
3141
;
3242
; TODO: some verbosity switch
@@ -69,15 +79,35 @@ do-rule: [
6979
any space
7080
copy value
7181
to end
72-
(reply: attempt [do load value]) ; TODO: rewrite to be safer
82+
(reply: do-code value)
83+
]
84+
85+
do-code: func [
86+
value
87+
/local id reply
88+
][
89+
replace/all value "load" ""
90+
replace/all value "save" ""
91+
replace/all value "read" ""
92+
replace/all value "write" ""
93+
save/header %temp.red compose/deep [
94+
write %out mold do [(load value)]
95+
] []
96+
id: call "red %temp.red"
97+
wait 0.5
98+
call rejoin ["kill " id]
99+
read %out
73100
]
74101

75102
parse-command: func [
76103
message
104+
/local reply
77105
] [
78-
reply: none
79-
switch message/text [
106+
reply: switch message/text [
80107
"/time" [reply: rejoin ["It is " now/time]]
108+
"/help" [help]
109+
"/issues" [list-issues]
110+
"/commits" [list-commits]
81111
]
82112
print ["=== Reply:" mold reply]
83113
if reply [gitter/send-message room reply]
@@ -95,6 +125,7 @@ parse-message: func [
95125
| commits-rule
96126
| issues-rule
97127
| do-rule
128+
| help-rule
98129
]
99130
]
100131
print ["=== Reply:" mold reply]
@@ -126,11 +157,13 @@ mark-messages: func [] [
126157

127158
; --- format responses
128159

129-
; TODO: make oe function, it is basically the same
160+
; TODO: make one function, it is basically the same
130161

131162
list-commits: function [] [
163+
return "TODO"
164+
; TODO
132165
output: copy {Here are five latest commits for [red](http://github.com/red/red):^/^/}
133-
commits: head remove/part skip github/list-commits 'red/red 5 25
166+
commits: head remove/part skip to block! github/list-commits 'red/red 5 25
134167
foreach commit commits [
135168
append output rejoin [
136169
asterisk space open-block strip-newline commit/commit/message close-block
@@ -141,9 +174,11 @@ list-commits: function [] [
141174
output
142175
]
143176

144-
list-issues: function [] [
177+
list-issues: func [] [
178+
return "TODO"
179+
; TODO
145180
output: copy {Here are five latest issues for [red](http://github.com/red/red):^/^/}
146-
issues: head remove/part skip github/get-issues/repo 'red/red 5 25
181+
issues: head remove/part skip to block! github/get-issues/repo 'red/red 5 25
147182
foreach issue issues [
148183
append output rejoin [
149184
asterisk space open-block issue/number close-block

0 commit comments

Comments
 (0)