@@ -23,7 +23,6 @@ import io.github.samarium150.mirai.plugin.config.PluginConfig
23
23
import io.github.samarium150.mirai.plugin.config.ReplyConfig
24
24
import io.github.samarium150.mirai.plugin.data.PluginData
25
25
import io.github.samarium150.mirai.plugin.data.RequestBody
26
- import io.github.samarium150.mirai.plugin.data.ResponseBody
27
26
import io.github.samarium150.mirai.plugin.util.CooldownUtil
28
27
import io.github.samarium150.mirai.plugin.util.ThrottleUtil
29
28
import io.github.samarium150.mirai.plugin.util.GeneralUtil
@@ -97,14 +96,22 @@ object Lolicon : CompositeCommand(
97
96
)
98
97
else RequestBody (r18, 1 , listOf (), tags, listOf (), listOf (PluginConfig .size), PluginConfig .proxy)
99
98
logger.info(" request body: $body " )
100
- val response = GeneralUtil .processRequest(this , body) ? : return
99
+ val response = GeneralUtil .processRequest(this , body)
100
+ if (response == null ) {
101
+ ThrottleUtil .unlock(subject)
102
+ return
103
+ }
101
104
try {
102
105
val imageData = response.data[0 ]
103
106
if (! GeneralUtil .areTagsAllowed(imageData.tags)) {
104
107
sendMessage(ReplyConfig .filteredTag)
105
108
return
106
109
}
107
- val url = imageData.urls[PluginConfig .size] ? : return
110
+ val url = imageData.urls[PluginConfig .size]
111
+ if (url == null ) {
112
+ ThrottleUtil .unlock(subject)
113
+ return
114
+ }
108
115
val imgInfoReceipt =
109
116
if (PluginConfig .verbose || subject == null ) sendMessage(imageData.toReadable())
110
117
else null
@@ -113,10 +120,11 @@ object Lolicon : CompositeCommand(
113
120
stream = GeneralUtil .getImageInputStream(url)
114
121
val img = subject?.uploadImage(stream)
115
122
if (img != null ) {
116
- val imgReceipt = (
117
- if (PluginConfig .flash) sendMessage(FlashImage (img)) else sendMessage(img)
118
- ) ? : return
119
- if (recall > 0 && PluginConfig .recallImg)
123
+ val imgReceipt = if (PluginConfig .flash) sendMessage(FlashImage (img)) else sendMessage(img)
124
+ if (imgReceipt == null ) {
125
+ ThrottleUtil .unlock(subject)
126
+ return
127
+ } else if (recall > 0 && PluginConfig .recallImg)
120
128
GeneralUtil .recall(GeneralUtil .RecallType .IMAGE , imgReceipt, recall)
121
129
if (cooldown > 0 )
122
130
CooldownUtil .cooldown(subject, cooldown)
@@ -158,6 +166,7 @@ object Lolicon : CompositeCommand(
158
166
try {
159
167
body = Json .decodeFromString<RequestBody >(json)
160
168
} catch (e: Exception ) {
169
+ ThrottleUtil .unlock(subject)
161
170
sendMessage(ReplyConfig .invalidJson)
162
171
logger.warning(e)
163
172
return
@@ -166,14 +175,20 @@ object Lolicon : CompositeCommand(
166
175
if (body.r18 != r18) {
167
176
if (subject is Group && ! GeneralUtil .checkMemberPerm(user)) {
168
177
sendMessage(ReplyConfig .nonAdminPermissionDenied)
178
+ ThrottleUtil .unlock(subject)
169
179
return
170
180
}
171
181
if (subject is User && ! GeneralUtil .checkUserPerm(user)) {
172
182
sendMessage(ReplyConfig .untrusted)
183
+ ThrottleUtil .unlock(subject)
173
184
return
174
185
}
175
186
}
176
- val response: ResponseBody = GeneralUtil .processRequest(this , body) ? : return
187
+ val response = GeneralUtil .processRequest(this , body)
188
+ if (response == null ) {
189
+ ThrottleUtil .unlock(subject)
190
+ return
191
+ }
177
192
try {
178
193
val imageInfoMsgBuilder = MessageChainBuilder ()
179
194
val imageMsgBuilder = MessageChainBuilder ()
@@ -202,8 +217,11 @@ object Lolicon : CompositeCommand(
202
217
val imgInfoReceipt =
203
218
if (PluginConfig .verbose || subject == null ) sendMessage(imageInfoMsgBuilder.asMessageChain())
204
219
else null
205
- val imgReceipt = sendMessage(imageMsgBuilder.asMessageChain()) ? : return
206
- if (recall > 0 && PluginConfig .recallImg)
220
+ val imgReceipt = sendMessage(imageMsgBuilder.asMessageChain())
221
+ if (imgReceipt == null ) {
222
+ ThrottleUtil .unlock(subject)
223
+ return
224
+ } else if (recall > 0 && PluginConfig .recallImg)
207
225
GeneralUtil .recall(GeneralUtil .RecallType .IMAGE , imgReceipt, recall)
208
226
if (cooldown > 0 )
209
227
CooldownUtil .cooldown(subject, cooldown)
0 commit comments