/
list.go
41 lines (35 loc) · 1.09 KB
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package command
import (
"github.com/ShotaKitazawa/minecraft-bot/pkg/botplug"
"github.com/ShotaKitazawa/minecraft-bot/pkg/domain/i18n"
"github.com/ShotaKitazawa/minecraft-bot/pkg/sharedmem"
"github.com/sirupsen/logrus"
)
type PluginList struct {
SharedMem sharedmem.SharedMem
Logger *logrus.Logger
}
func (p PluginList) CommandName() string {
return `list`
}
func (p PluginList) ReceiveMessage(input *botplug.MessageInput) *botplug.MessageOutput {
var queue []interface{}
// read data from SharedMem
data, err := p.SharedMem.SyncReadEntity()
if err != nil {
p.Logger.Error(err)
queue = append(queue, i18n.T.Sprintf(i18n.MessageError))
return &botplug.MessageOutput{Queue: queue}
}
// ログイン中のユーザを LINE に送信
var loginUsernames []string
for _, user := range data.LoginUsers {
loginUsernames = append(loginUsernames, user.Name)
}
if loginUsernames == nil {
queue = append(queue, i18n.T.Sprintf(i18n.MessageNoUserExists))
return &botplug.MessageOutput{Queue: queue}
}
queue = append(queue, loginUsernames)
return &botplug.MessageOutput{Queue: queue}
}