mirror of
https://github.com/fumiama/ReiBot.git
synced 2026-06-07 19:40:32 +08:00
add 响应通知主人 & 按顺序打印服务
This commit is contained in:
23
manager.go
23
manager.go
@@ -3,6 +3,7 @@ package rei
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"sync/atomic"
|
||||
"unicode"
|
||||
|
||||
@@ -81,3 +82,25 @@ func Delete(service string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ForEachByPrio iterates through managers by their priority.
|
||||
func ForEachByPrio(iterator func(i int, manager *ctrl.Control[*Ctx]) bool) {
|
||||
for i, v := range cpmp2lstbyprio() {
|
||||
if !iterator(i, v) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func cpmp2lstbyprio() []*ctrl.Control[*Ctx] {
|
||||
m.RLock()
|
||||
defer m.RUnlock()
|
||||
ret := make([]*ctrl.Control[*Ctx], 0, len(m.M))
|
||||
for _, v := range m.M {
|
||||
ret = append(ret, v)
|
||||
}
|
||||
sort.SliceStable(ret, func(i, j int) bool {
|
||||
return enmap[ret[i].Service].prio < enmap[ret[j].Service].prio
|
||||
})
|
||||
return ret
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user