mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2026-06-02 09:35:48 +08:00
update plugin management
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
package qiege
|
||||
|
||||
import (
|
||||
"AynaLivePlayer/core/adapter"
|
||||
"AynaLivePlayer/core/model"
|
||||
"AynaLivePlayer/core/events"
|
||||
"AynaLivePlayer/global"
|
||||
"AynaLivePlayer/gui"
|
||||
"AynaLivePlayer/gui/component"
|
||||
"AynaLivePlayer/pkg/config"
|
||||
"AynaLivePlayer/pkg/event"
|
||||
"AynaLivePlayer/pkg/i18n"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/data/binding"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Qiege struct {
|
||||
@@ -19,15 +21,16 @@ type Qiege struct {
|
||||
PrivilegePermission bool
|
||||
AdminPermission bool
|
||||
CustomCMD string
|
||||
currentUid string
|
||||
panel fyne.CanvasObject
|
||||
}
|
||||
|
||||
func NewQiege(ctr adapter.IControlBridge) *Qiege {
|
||||
func NewQiege() *Qiege {
|
||||
return &Qiege{
|
||||
UserPermission: true,
|
||||
PrivilegePermission: true,
|
||||
AdminPermission: true,
|
||||
CustomCMD: "skip",
|
||||
CustomCMD: "切歌",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,8 +40,24 @@ func (d *Qiege) Name() string {
|
||||
|
||||
func (d *Qiege) Enable() error {
|
||||
config.LoadConfig(d)
|
||||
d.ctr.LiveRooms().AddDanmuCommand(d)
|
||||
gui.AddConfigLayout(d)
|
||||
global.EventManager.RegisterA(
|
||||
events.LiveRoomMessageReceive,
|
||||
"plugin.qiege.message",
|
||||
d.handleMessage)
|
||||
global.EventManager.RegisterA(
|
||||
events.PlayerPlayingUpdate,
|
||||
"plugin.qiege.playing",
|
||||
func(event *event.Event) {
|
||||
data := event.Data.(events.PlayerPlayingUpdateEvent)
|
||||
if data.Removed {
|
||||
d.currentUid = ""
|
||||
}
|
||||
if !data.Media.IsLiveRoomUser() {
|
||||
d.currentUid = ""
|
||||
}
|
||||
d.currentUid = data.Media.DanmuUser().Uid
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -46,28 +65,30 @@ func (d *Qiege) Disable() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Qiege) Match(command string) bool {
|
||||
for _, c := range []string{"切歌", d.CustomCMD} {
|
||||
if command == c {
|
||||
return true
|
||||
}
|
||||
func (d *Qiege) handleMessage(event *event.Event) {
|
||||
message := event.Data.(events.LiveRoomMessageReceiveEvent).Message
|
||||
msgs := strings.Split(message.Message, " ")
|
||||
if len(msgs) < 1 || len(msgs[0]) == 0 {
|
||||
return
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (d *Qiege) Execute(command string, args []string, danmu *model.DanmuMessage) {
|
||||
if d.UserPermission && (d.ctr.PlayControl().GetPlaying() != nil) {
|
||||
if d.ctr.PlayControl().GetPlaying().DanmuUser() != nil && d.ctr.PlayControl().GetPlaying().DanmuUser().Uid == danmu.User.Uid {
|
||||
d.ctr.PlayControl().PlayNext()
|
||||
if d.UserPermission {
|
||||
if d.currentUid == message.User.Uid {
|
||||
global.EventManager.CallA(
|
||||
events.PlayerPlayNextCmd,
|
||||
events.PlayerPlayNextCmdEvent{})
|
||||
return
|
||||
}
|
||||
}
|
||||
if d.PrivilegePermission && danmu.User.Privilege > 0 {
|
||||
d.ctr.PlayControl().PlayNext()
|
||||
if d.PrivilegePermission && message.User.Privilege > 0 {
|
||||
global.EventManager.CallA(
|
||||
events.PlayerPlayNextCmd,
|
||||
events.PlayerPlayNextCmdEvent{})
|
||||
return
|
||||
}
|
||||
if d.AdminPermission && danmu.User.Admin {
|
||||
d.ctr.PlayControl().PlayNext()
|
||||
if d.AdminPermission && message.User.Admin {
|
||||
global.EventManager.CallA(
|
||||
events.PlayerPlayNextCmd,
|
||||
events.PlayerPlayNextCmdEvent{})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user