Skip to content

Latest commit

 

History

History
55 lines (44 loc) · 1.57 KB

README_ZH.md

File metadata and controls

55 lines (44 loc) · 1.57 KB

简体中文 | English

KookGo

Issues Pull Requests Release Github Release Downloads

基于websocket协议的kook机器人开发sdk

快速启动

导入模块

go get github.com/aimerny/kook-go

简单实现

func main() {

	common.InitLogger()
	globalSession, err := session.CreateSession("你的KookToken", true)
	if err != nil {
		log.Errorf("%s", err)
	}
	globalSession.RegisterEventHandler(&MyEventHandler{})
	globalSession.Start()
}

type MyEventHandler struct {
	event.BaseEventHandler
}

// DoKMarkDown 一个简单的Kook机器人实现,接受到新消息时会发送回对应频道/私聊
func (h *MyEventHandler) DoKMarkDown(event *model.Event) {
	content := event.Content
	log.Infof("event:%v", event)
	extra := event.GetUserExtra()
	if extra.Author.Bot {
		log.Warnf("Bot message, skip")
		return
	}
	req := &model.MessageCreateReq{
		Type:     9,
		Content:  "Repeat by kook bot:" + content,
		TargetId: event.TargetId,
	}
	action.MessageSend(req)
}