onebot

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2024 License: MIT Imports: 9 Imported by: 0

README

OneBot Golang SDK

安装 💡

go get -u github.com/ThinkerWen/glib-onebot@latest

使用方法

package main

import (
	"context"
	"github.com/ThinkerWen/glib-onebot"
	"github.com/ThinkerWen/glib-onebot/api"
	"github.com/ThinkerWen/glib-onebot/events"
	"github.com/ThinkerWen/glib-onebot/messages"
)

func main() {
	bot, err := onebot.NewBot("ws://127.0.0.1:3001")
	if err != nil {
		panic(err)
	}
	bot.On(events.OnGroupMessageEvent, func(ctx context.Context, event events.IEvent) {
		message := events.EventParser(event).AsGroupMessage()
		msg := messages.NewTextMsg("Hello OneBot")
		go api.Build(bot.API).SendGroupMsg(message.GroupId, false, msg).Do(ctx)
	})
	err = bot.ListenAndWait(context.Background())
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogLevel added in v0.1.2

func SetLogLevel(level string)

Types

type Bot

type Bot struct {
	API string
	// contains filtered or unexported fields
}

func NewBot

func NewBot(api string) (*Bot, error)

NewBot 使用指定的 API URL 创建新的 Bot 实例。

func (*Bot) ListenAndWait

func (bot *Bot) ListenAndWait(ctx context.Context) error

ListenAndWait 连接到 WebSocket 服务器并侦听事件。

func (*Bot) On

func (bot *Bot) On(event events.EventName, callback events.EventCallbackFunc)

On 为特定事件注册回调函数。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL