From 271a2c707e86141e7fc5b46636921d504c838e22 Mon Sep 17 00:00:00 2001 From: Aimerny Date: Wed, 10 Jul 2024 18:00:35 +0800 Subject: [PATCH] docs: :memo: add readme doc --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ README_ZH.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 README.md create mode 100644 README_ZH.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..32ebfd0 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +[简体中文](README_ZH.md) | English +# KookGo + +A kook robot development sdk based on websocket protocol + +## QuickStart + +### Import module + +```shell +go get github.com/aimerny/kook-go +``` + +### Simple Implement +```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) +} +``` + +## [CHANGELOG](./app/CHANGELOG.md) \ No newline at end of file diff --git a/README_ZH.md b/README_ZH.md new file mode 100644 index 0000000..5560f20 --- /dev/null +++ b/README_ZH.md @@ -0,0 +1,51 @@ +简体中文 | [English](README_ZH.md) +# KookGo + + +基于websocket协议的kook机器人开发sdk + +## 快速启动 + +### 导入模块 + +```shell +go get github.com/aimerny/kook-go +``` + +### 简单实现 + +```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) +} +``` + +### [CHANGELOG](./app/CHANGELOG.md)