mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-06 18:32:50 +08:00
update single user max diange count
This commit is contained in:
@@ -384,6 +384,10 @@
|
||||
"en": "User",
|
||||
"zh-CN": "普通用户"
|
||||
},
|
||||
"plugin.diange.user_max": {
|
||||
"en": "User Maximum queue",
|
||||
"zh-CN": "单个用户最大点歌数"
|
||||
},
|
||||
"plugin.maxduration.description": {
|
||||
"en": "Set the maximum duration of a song",
|
||||
"zh-CN": "设置歌曲最长能播多久"
|
||||
|
||||
1
go.mod
1
go.mod
@@ -62,6 +62,7 @@ require (
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/sahilm/fuzzy v0.1.0 // indirect
|
||||
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
|
||||
github.com/spf13/cast v1.5.1 // indirect
|
||||
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
|
||||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
|
||||
|
||||
Submodule pkg/miaosic updated: ceabb3009f...10ba44e33a
@@ -18,6 +18,7 @@ import (
|
||||
"golang.org/x/exp/slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -35,6 +36,7 @@ type Diange struct {
|
||||
MedalName string
|
||||
MedalPermission int
|
||||
QueueMax int
|
||||
UserMax int
|
||||
UserCoolDown int
|
||||
CustomCMD string
|
||||
SourceConfigPath string
|
||||
@@ -46,6 +48,7 @@ type Diange struct {
|
||||
sourceConfigs map[string]*sourceConfig
|
||||
blacklist []blacklistItem
|
||||
cooldowns map[string]int
|
||||
userCount sync.Map
|
||||
panel fyne.CanvasObject
|
||||
log logger.ILogger
|
||||
}
|
||||
@@ -59,6 +62,7 @@ func NewDiange() *Diange {
|
||||
AdminPermission: true,
|
||||
QueueMax: 128,
|
||||
UserCoolDown: -1,
|
||||
UserMax: 128,
|
||||
CustomCMD: "点歌",
|
||||
SourceConfigPath: "./config/diange.json",
|
||||
BlackListItemPath: "./config/diange_blacklist.json",
|
||||
@@ -92,6 +96,7 @@ func NewDiange() *Diange {
|
||||
},
|
||||
},
|
||||
cooldowns: make(map[string]int),
|
||||
userCount: sync.Map{},
|
||||
log: global.Logger.WithPrefix("Plugin.Diange"),
|
||||
}
|
||||
return diange
|
||||
@@ -124,6 +129,18 @@ func (d *Diange) Enable() error {
|
||||
"plugin.diange.queue.update",
|
||||
func(event *event.Event) {
|
||||
d.currentQueueLength = len(event.Data.(events.PlaylistDetailUpdateEvent).Medias)
|
||||
medias := event.Data.(events.PlaylistDetailUpdateEvent).Medias
|
||||
tmpUserCount := make(map[string]int)
|
||||
for _, media := range medias {
|
||||
_, ok := tmpUserCount[media.ToUser().Name]
|
||||
if !ok {
|
||||
tmpUserCount[media.ToUser().Name] = 0
|
||||
}
|
||||
tmpUserCount[media.ToUser().Name]++
|
||||
}
|
||||
for user, count := range tmpUserCount {
|
||||
d.userCount.Store(user, count)
|
||||
}
|
||||
})
|
||||
global.EventManager.RegisterA(
|
||||
events.PlayerPlayingUpdate,
|
||||
@@ -186,6 +203,18 @@ func (d *Diange) handleMessage(event *event.Event) {
|
||||
return
|
||||
}
|
||||
|
||||
//check user max
|
||||
if d.UserMax > 0 {
|
||||
userCount, ok := d.userCount.Load(message.User.Username)
|
||||
if !ok {
|
||||
userCount = 0
|
||||
}
|
||||
if userCount.(int) >= d.UserMax {
|
||||
d.log.Infof("User %s(%s) exceed max diange count, ignore", message.User.Username, message.User.Uid)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// if in user cool down, return
|
||||
ct := int(time.Now().Unix())
|
||||
if (ct - d.cooldowns[message.User.Uid]) <= d.UserCoolDown {
|
||||
@@ -326,6 +355,10 @@ func (d *Diange) CreatePanel() fyne.CanvasObject {
|
||||
widget.NewLabel(i18n.T("plugin.diange.queue_max")), nil,
|
||||
widget.NewEntryWithData(binding.IntToString(binding.BindInt(&d.QueueMax))),
|
||||
)
|
||||
dgUserMax := container.NewBorder(nil, nil,
|
||||
widget.NewLabel(i18n.T("plugin.diange.user_max")), nil,
|
||||
widget.NewEntryWithData(binding.IntToString(binding.BindInt(&d.UserMax))),
|
||||
)
|
||||
dgCoolDown := container.NewBorder(nil, nil,
|
||||
widget.NewLabel(i18n.T("plugin.diange.cooldown")), nil,
|
||||
widget.NewEntryWithData(binding.IntToString(binding.BindInt(&d.UserCoolDown))),
|
||||
@@ -355,6 +388,6 @@ func (d *Diange) CreatePanel() fyne.CanvasObject {
|
||||
dgSourceCMD := container.NewBorder(
|
||||
nil, nil, widget.NewLabel(i18n.T("plugin.diange.source_cmd")), nil,
|
||||
container.NewVBox(sourceCfgs...))
|
||||
d.panel = container.NewVBox(dgPerm, dgMdPerm, dgQueue, dgCoolDown, dgShortCut, skipPlaylist, dgSourceCMD)
|
||||
d.panel = container.NewVBox(dgPerm, dgMdPerm, dgQueue, dgUserMax, dgCoolDown, dgShortCut, skipPlaylist, dgSourceCMD)
|
||||
return d.panel
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user