onebot

package
v0.0.0-...-8277a9f Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package onebot defines onebot protocol struct and some spec info.

Index

Constants

This section is empty.

Variables

View Source
var V11 = &Spec{
	Version:          11,
	SupportedActions: supportedV11,
}

V11 OneBot V11

View Source
var V12 = &Spec{
	Version:          12,
	SupportedActions: supportedV12,
}

V12 OneBot V12

Functions

This section is empty.

Types

type Attr

type Attr struct {
	Key   string
	Value Value
}

An Attr is a key-value pair.

func Any

func Any(key string, value any) Attr

Any returns an Attr for the supplied value. See [Value.AnyValue] for how values are treated.

func Bool

func Bool(key string, v bool) Attr

Bool returns an Attr for a bool.

func Duration

func Duration(key string, v time.Duration) Attr

Duration returns an Attr for a time.Duration.

func Float64

func Float64(key string, v float64) Attr

Float64 returns an Attr for a floating-point number.

func Group

func Group(key string, as ...Attr) Attr

Group returns an Attr for a Group Value. The caller must not subsequently mutate the argument slice.

Use Group to collect several Attrs under a single key on a log line, or as the result of LogValue in order to log a single value as multiple Attrs.

func Int

func Int(key string, value int) Attr

Int converts an int to an int64 and returns an Attr with that value.

func Int64

func Int64(key string, value int64) Attr

Int64 returns an Attr for an int64.

func String

func String(key, value string) Attr

String returns an Attr for a string value.

func Time

func Time(key string, v time.Time) Attr

Time returns an Attr for a time.Time. It discards the monotonic portion.

func Uint64

func Uint64(key string, v uint64) Attr

Uint64 returns an Attr for a uint64.

func (Attr) String

func (a Attr) String() string

type Event

type Event struct {
	ID         string
	Time       int64
	Type       string
	DetailType string
	SubType    string
	Self       *Self
}

Event 事件

https://12.onebot.dev/connect/data-protocol/event/

type Kind

type Kind int

Kind is the kind of Value.

const (
	KindAny Kind = iota
	KindBool
	KindDuration
	KindFloat64
	KindInt64
	KindString
	KindTime
	KindUint64
	KindGroup
)

Kind

func (Kind) String

func (i Kind) String() string

type Request

type Request struct {
	Action string // 动作名称
	Params any    // 动作参数
	Echo   any    // 每次请求的唯一标识
}

Request 动作请求是应用端为了主动向 OneBot 实现请求服务而发送的数据

https://12.onebot.dev/connect/data-protocol/action-request/

type Response

type Response struct {
	Status  string `json:"status"`  // 执行状态,必须是 ok、failed 中的一个
	Code    int64  `json:"retcode"` // 返回码
	Data    any    `json:"data"`    // 响应数据
	Message string `json:"message"` // 错误信息
	Echo    any    `json:"echo"`    // 动作请求中的 echo 字段值
}

Response 动作响应是 OneBot 实现收到应用端的动作请求并处理完毕后,发回应用端的数据

https://12.onebot.dev/connect/data-protocol/action-response/

type Self

type Self struct {
	Platform string `json:"platform"`
	UserID   string `json:"user_id"`
}

Self 机器人自身标识

https://12.onebot.dev/connect/data-protocol/basic-types/#_10

type Spec

type Spec struct {
	Version          int // must be 11 or 12
	SupportedActions []string
}

Spec OneBot Specification

func (*Spec) ConvertID

func (s *Spec) ConvertID(id any) any

ConvertID 根据版本转换ID

type Value

type Value struct {
	// contains filtered or unexported fields
}

A Value can represent any Go value, but unlike type any, it can represent most small values without an allocation. The zero Value corresponds to nil.

func AnyValue

func AnyValue(v any) Value

AnyValue returns a Value for the supplied value.

If the supplied value is of type Value, it is returned unmodified.

Given a value of one of Go's predeclared string, bool, or (non-complex) numeric types, AnyValue returns a Value of kind String, Bool, Uint64, Int64, or Float64. The width of the original numeric type is not preserved.

Given a time.Time or time.Duration value, AnyValue returns a Value of kind KindTime or KindDuration. The monotonic time is not preserved.

For nil, or values of all other types, including named types whose underlying type is numeric, AnyValue returns a value of kind KindAny.

func BoolValue

func BoolValue(v bool) Value

BoolValue returns a Value for a bool.

func DurationValue

func DurationValue(v time.Duration) Value

DurationValue returns a Value for a time.Duration.

func Float64Value

func Float64Value(v float64) Value

Float64Value returns a Value for a floating-point number.

func GroupValue

func GroupValue(as ...Attr) Value

GroupValue returns a new Value for a list of Attrs. The caller must not subsequently mutate the argument slice.

func Int64Value

func Int64Value(v int64) Value

Int64Value returns a Value for an int64.

func IntValue

func IntValue(v int) Value

IntValue returns a Value for an int.

func StringValue

func StringValue(value string) Value

StringValue returns a new Value for a string.

func TimeValue

func TimeValue(v time.Time) Value

TimeValue returns a Value for a time.Time. It discards the monotonic portion.

func Uint64Value

func Uint64Value(v uint64) Value

Uint64Value returns a Value for a uint64.

func (Value) Any

func (v Value) Any() any

Any returns v's value as an any.

func (Value) Bool

func (v Value) Bool() bool

Bool returns v's value as a bool. It panics if v is not a bool.

func (Value) Duration

func (v Value) Duration() time.Duration

Duration returns v's value as a time.Duration. It panics if v is not a time.Duration.

func (Value) Float64

func (v Value) Float64() float64

Float64 returns v's value as a float64. It panics if v is not a float64.

func (Value) Group

func (v Value) Group() []Attr

Group returns v's value as a []Attr. It panics if v's Kind is not KindGroup.

func (Value) Int64

func (v Value) Int64() int64

Int64 returns v's value as an int64. It panics if v is not a signed integer.

func (Value) Kind

func (v Value) Kind() Kind

Kind returns v's Kind.

func (Value) String

func (v Value) String() string

String returns Value's value as a string, formatted like fmt.Sprint. Unlike the methods Int64, Float64, and so on, which panic if v is of the wrong kind, String never panics.

func (Value) Time

func (v Value) Time() time.Time

Time returns v's value as a time.Time. It panics if v is not a time.Time.

func (Value) Uint64

func (v Value) Uint64() uint64

Uint64 returns v's value as a uint64. It panics if v is not an unsigned integer.

Jump to

Keyboard shortcuts

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