mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2026-05-05 06:45:47 +08:00
add diange source command & fix bilibili video
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"AynaLivePlayer/i18n"
|
||||
"AynaLivePlayer/liveclient"
|
||||
"AynaLivePlayer/logger"
|
||||
"fmt"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/data/binding"
|
||||
@@ -29,6 +30,7 @@ type Diange struct {
|
||||
QueueMax int
|
||||
UserCoolDown int
|
||||
CustomCMD string
|
||||
SourceCMD []string
|
||||
cooldowns map[string]int
|
||||
panel fyne.CanvasObject
|
||||
}
|
||||
@@ -41,6 +43,7 @@ func NewDiange() *Diange {
|
||||
QueueMax: 128,
|
||||
UserCoolDown: -1,
|
||||
CustomCMD: "add",
|
||||
SourceCMD: make([]string, 0),
|
||||
cooldowns: make(map[string]int),
|
||||
}
|
||||
}
|
||||
@@ -51,18 +54,42 @@ func (d *Diange) Name() string {
|
||||
|
||||
func (d *Diange) Enable() error {
|
||||
config.LoadConfig(d)
|
||||
d.initCMD()
|
||||
controller.AddCommand(d)
|
||||
gui.AddConfigLayout(d)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Diange) Match(command string) bool {
|
||||
for _, c := range []string{"点歌", d.CustomCMD} {
|
||||
if command == c {
|
||||
return true
|
||||
func (d *Diange) initCMD() {
|
||||
if len(d.SourceCMD) == len(config.Provider.Priority) {
|
||||
return
|
||||
}
|
||||
if len(d.SourceCMD) > len(config.Provider.Priority) {
|
||||
d.SourceCMD = d.SourceCMD[:len(config.Provider.Priority)]
|
||||
return
|
||||
}
|
||||
for i := len(d.SourceCMD); i < len(config.Provider.Priority); i++ {
|
||||
d.SourceCMD = append(d.SourceCMD, "点歌"+config.Provider.Priority[i])
|
||||
}
|
||||
}
|
||||
|
||||
// isCMD return int if the commmand name matches our command
|
||||
// -1 = not match, 0 = normal command, 1+ = source command
|
||||
func (d *Diange) isCMD(cmd string) int {
|
||||
if cmd == "点歌" || cmd == d.CustomCMD {
|
||||
return 0
|
||||
}
|
||||
fmt.Println(d.SourceCMD)
|
||||
for index, c := range d.SourceCMD {
|
||||
if cmd == c {
|
||||
return index + 1
|
||||
}
|
||||
}
|
||||
return false
|
||||
return -1
|
||||
}
|
||||
|
||||
func (d *Diange) Match(command string) bool {
|
||||
return d.isCMD(command) >= 0
|
||||
}
|
||||
|
||||
func (d *Diange) Execute(command string, args []string, danmu *liveclient.DanmuMessage) {
|
||||
@@ -78,6 +105,7 @@ func (d *Diange) Execute(command string, args []string, danmu *liveclient.DanmuM
|
||||
l().Infof("User %s(%s) still in cool down period, diange failed", danmu.User.Username, danmu.User.Uid)
|
||||
return
|
||||
}
|
||||
cmdType := d.isCMD(command)
|
||||
keyword := strings.Join(args, " ")
|
||||
perm := d.UserPermission
|
||||
l().Trace("user permission check: ", perm)
|
||||
@@ -85,10 +113,15 @@ func (d *Diange) Execute(command string, args []string, danmu *liveclient.DanmuM
|
||||
l().Trace("privilege permission check: ", perm)
|
||||
perm = perm || (d.AdminPermission && (danmu.User.Admin))
|
||||
l().Trace("admin permission check: ", perm)
|
||||
if perm {
|
||||
// reset cool down
|
||||
d.cooldowns[danmu.User.Uid] = ct
|
||||
if !perm {
|
||||
return
|
||||
}
|
||||
// reset cool down
|
||||
d.cooldowns[danmu.User.Uid] = ct
|
||||
if cmdType == 0 {
|
||||
controller.Add(keyword, &danmu.User)
|
||||
} else {
|
||||
controller.AddWithProvider(keyword, config.Provider.Priority[cmdType-1], &danmu.User)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +155,17 @@ func (d *Diange) CreatePanel() fyne.CanvasObject {
|
||||
widget.NewLabel(i18n.T("plugin.diange.custom_cmd")), nil,
|
||||
widget.NewEntryWithData(binding.BindString(&d.CustomCMD)),
|
||||
)
|
||||
d.panel = container.NewVBox(dgPerm, dgQueue, dgCoolDown, dgShortCut)
|
||||
sourceCmds := []fyne.CanvasObject{}
|
||||
for i, _ := range d.SourceCMD {
|
||||
sourceCmds = append(
|
||||
sourceCmds,
|
||||
container.NewBorder(
|
||||
nil, nil, widget.NewLabel(config.Provider.Priority[i]), nil,
|
||||
widget.NewEntryWithData(binding.BindString(&d.SourceCMD[i]))))
|
||||
}
|
||||
dgSourceCMD := container.NewBorder(
|
||||
nil, nil, widget.NewLabel(i18n.T("plugin.diange.source_cmd")), nil,
|
||||
container.NewVBox(sourceCmds...))
|
||||
d.panel = container.NewVBox(dgPerm, dgQueue, dgCoolDown, dgShortCut, dgSourceCMD)
|
||||
return d.panel
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user