5
5
"fmt"
6
6
"strconv"
7
7
"strings"
8
+ "sync"
8
9
"time"
9
10
10
11
ctrl "github.com/FloatTech/zbpctrl"
@@ -15,7 +16,14 @@ import (
15
16
"github.com/wdvxdr1123/ZeroBot/message"
16
17
)
17
18
18
- var wmitems , itemNames = newwm ()
19
+ var wmdr sync.RWMutex
20
+
21
+ type wmdata struct {
22
+ wmitems map [string ]items
23
+ itemNames []string
24
+ }
25
+
26
+ var wd , _ = newwm ()
19
27
20
28
func init () {
21
29
eng := control .Register ("warframeapi" , & ctrl.Options [* zero.Ctx ]{
@@ -234,10 +242,12 @@ func init() {
234
242
ctx .SendChain (message .Text ("已拉取服务器时间并同步到本地模拟" ))
235
243
})
236
244
// 根据名称从Warframe市场查询物品售价
237
- eng .OnPrefix (".wm " ).SetBlock (true ).
245
+ eng .OnPrefix (".wm " , checknwm ).SetBlock (true ).
238
246
Handle (func (ctx * zero.Ctx ) {
239
247
// 根据输入的名称, 从游戏物品名称列表中进行模糊搜索
240
- sol := fuzzy .FindNormalizedFold (ctx .State ["args" ].(string ), itemNames )
248
+ wmdr .RLock ()
249
+ sol := fuzzy .FindNormalizedFold (ctx .State ["args" ].(string ), wd .itemNames )
250
+ wmdr .RUnlock ()
241
251
// 物品名称
242
252
var name string
243
253
@@ -282,17 +292,20 @@ func init() {
282
292
if onlymaxrank {
283
293
msgs = msgs [:0 ]
284
294
}
285
- sells , iteminfo , txt , err := getitemsorder (wmitems [name ].URLName , onlymaxrank )
295
+
296
+ sells , iteminfo , txt , err := getitemsorder (wd .wmitems [name ].URLName , onlymaxrank )
286
297
if ! onlymaxrank {
298
+ wmdr .RLock ()
287
299
if iteminfo .ZhHans .WikiLink == "" {
288
300
msgs = append (msgs , ctxext .FakeSenderForwardNode (ctx ,
289
- message .Image ("https://warframe.market/static/assets/" + wmitems [name ].Thumb ),
290
- message .Text ("\n " , wmitems [name ].ItemName )))
301
+ message .Image ("https://warframe.market/static/assets/" + wd . wmitems [name ].Thumb ),
302
+ message .Text ("\n " , wd . wmitems [name ].ItemName )))
291
303
} else {
292
304
msgs = append (msgs , ctxext .FakeSenderForwardNode (ctx ,
293
- message .Image ("https://warframe.market/static/assets/" + wmitems [name ].Thumb ),
294
- message .Text ("\n " , wmitems [name ].ItemName , "\n wiki: " , iteminfo .ZhHans .WikiLink )))
305
+ message .Image ("https://warframe.market/static/assets/" + wd . wmitems [name ].Thumb ),
306
+ message .Text ("\n " , wd . wmitems [name ].ItemName , "\n wiki: " , iteminfo .ZhHans .WikiLink )))
295
307
}
308
+ wmdr .RUnlock ()
296
309
}
297
310
298
311
if err != nil {
0 commit comments