mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2025-12-15 06:28:18 +08:00
29 lines
619 B
Go
29 lines
619 B
Go
package controller
|
|
|
|
import (
|
|
"AynaLivePlayer/event"
|
|
"AynaLivePlayer/liveclient"
|
|
"strings"
|
|
)
|
|
|
|
var Commands []DanmuCommandExecutor
|
|
|
|
type DanmuCommandExecutor interface {
|
|
Match(command string) bool
|
|
Execute(command string, args []string, danmu *liveclient.DanmuMessage)
|
|
}
|
|
|
|
func AddCommand(executors ...DanmuCommandExecutor) {
|
|
Commands = append(Commands, executors...)
|
|
}
|
|
|
|
func danmuCommandHandler(event *event.Event) {
|
|
danmu := event.Data.(*liveclient.DanmuMessage)
|
|
args := strings.Split(danmu.Message, " ")
|
|
for _, cmd := range Commands {
|
|
if cmd.Match(args[0]) {
|
|
cmd.Execute(args[0], args[1:], danmu)
|
|
}
|
|
}
|
|
}
|