1
0
mirror of https://github.com/fumiama/ReiBot.git synced 2026-06-07 19:40:32 +08:00

add 响应通知主人 & 按顺序打印服务

This commit is contained in:
源文雨
2022-10-06 21:13:47 +08:00
parent 3d4c3d447f
commit 4bf573933b
7 changed files with 175 additions and 51 deletions

View File

@@ -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
}