3
3
do load %redbot-options.red
4
4
5
5
do %gitter-api.red
6
- do %github.red
6
+ do %github-v3 .red
7
7
8
8
; --- support funcs
9
9
@@ -27,6 +27,16 @@ room: none
27
27
messages: none
28
28
reply: none
29
29
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
+
30
40
; --- basic commands
31
41
;
32
42
; TODO: some verbosity switch
@@ -69,15 +79,35 @@ do-rule: [
69
79
any space
70
80
copy value
71
81
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
73
100
]
74
101
75
102
parse-command : func [
76
103
message
104
+ /local reply
77
105
] [
78
- reply: none
79
- switch message/text [
106
+ reply: switch message/text [
80
107
"/time" [reply: rejoin ["It is " now /time ]]
108
+ "/help" [help]
109
+ "/issues" [list-issues]
110
+ "/commits" [list-commits]
81
111
]
82
112
print ["=== Reply:" mold reply]
83
113
if reply [gitter/send-message room reply]
@@ -95,6 +125,7 @@ parse-message: func [
95
125
| commits-rule
96
126
| issues-rule
97
127
| do-rule
128
+ | help-rule
98
129
]
99
130
]
100
131
print ["=== Reply:" mold reply]
@@ -126,11 +157,13 @@ mark-messages: func [] [
126
157
127
158
; --- format responses
128
159
129
- ; TODO: make oe function, it is basically the same
160
+ ; TODO: make one function, it is basically the same
130
161
131
162
list-commits : function [] [
163
+ return "TODO"
164
+ ; TODO
132
165
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
134
167
foreach commit commits [
135
168
append output rejoin [
136
169
asterisk space open-block strip-newline commit/commit/message close-block
@@ -141,9 +174,11 @@ list-commits: function [] [
141
174
output
142
175
]
143
176
144
- list-issues : function [] [
177
+ list-issues : func [] [
178
+ return "TODO"
179
+ ; TODO
145
180
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
147
182
foreach issue issues [
148
183
append output rejoin [
149
184
asterisk space open-block issue /number close-block
0 commit comments