gomirai

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2020 License: AGPL-3.0 Imports: 10 Imported by: 0

README

Go-Mirai

Go ReportGitHub top languageGitHubGitHub go.mod Go versionGitHub contributors

适配MiraiHttpApiMirai的Go SDK

目前仍处于开发阶段,部分功能仍未测试,暂未发布Go Module

如何使用

请参照example

所有导出函数、变量、结构均有详细注释


package main

import (
    "github.com/Logiase/gomirai"
)

func main() {
    //...
}
    
不了解Go?

(安利狂魔) Go急速入门

目前问题

暂无

功能

HTTP Api的所有基础功能

Websocket支持目前还在计划中

仍需改进的部分
  1. InEvent的更详细分类及自动归类,现在仍需手动调用OperatorDetail()与SenderDetail()

维护者

Logiase

许可证

AGPL-3.0 © Logiase

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthResponse

type AuthResponse struct {
	Code    int    `json:"code"`
	Session string `json:"session"`
}

AuthResponse 认证响应

type Bot

type Bot struct {
	Client *Client

	QQ int64

	MessageChan chan InEvent

	Session string
	// contains filtered or unexported fields
}

Bot qq机器人

func (*Bot) FetchMessage

func (bot *Bot) FetchMessage() error

FetchMessage 获取消息,会阻塞当前线程,消息保存在bot中的MessageChan 使用前请使用InitChannel初始化Channel

func (*Bot) FriendList

func (bot *Bot) FriendList() ([]*Friend, error)

FriendList 获取Bot的好友列表 会获取本地缓存的好友列表,如需刷新请使用RefreshFriendList 没有缓存时会自动刷新

func (*Bot) GetGroupConfig

func (bot *Bot) GetGroupConfig(group int64) (*GroupConfig, error)

GetGroupConfig 获取群设置

func (*Bot) GetGroupMemberInfo

func (bot *Bot) GetGroupMemberInfo(group, member int64) (*GroupMemberInfo, error)

GetGroupMemberInfo 获取群成员信息

func (*Bot) GroupList

func (bot *Bot) GroupList() ([]*Group, error)

GroupList 获取Bot的群列表 会获取本地缓存的群列表,如需刷新请使用RefreshGroupList 没有缓存时会自动刷新

func (*Bot) InitChannel

func (bot *Bot) InitChannel(size int, t time.Duration)

InitChannel 初始化消息管道 size 缓存数量 t 每次Fetch的时间间隔

func (*Bot) Kick

func (bot *Bot) Kick(group int64, member int64, msg string) error

Kick 踢出群聊

func (*Bot) MemberList

func (bot *Bot) MemberList(group int64) ([]*GroupMember, error)

MemberList 指定群内的群成员

func (*Bot) MessageFromID

func (bot *Bot) MessageFromID(id int64) (*InEvent, error)

MessageFromID 通过ID获取一条缓存的消息

func (*Bot) Mute

func (bot *Bot) Mute(group int64, member int64, second int64) error

Mute 禁言 second为0 解除禁言

func (*Bot) MuteAll

func (bot *Bot) MuteAll(group int64) error

MuteAll 全体禁言

func (*Bot) Recall

func (bot *Bot) Recall(target int64) error

Recall 撤回一条消息

func (*Bot) RefreshFriendList

func (bot *Bot) RefreshFriendList() ([]*Friend, error)

RefreshFriendList 刷新好友列表

func (*Bot) RefreshGroupList

func (bot *Bot) RefreshGroupList() ([]*Group, error)

RefreshGroupList 刷新群列表s

func (*Bot) Release

func (bot *Bot) Release() error

Release 使用此方式释放session及其相关资源(Bot不会被释放) 不使用的Session应当被释放,长时间(30分钟)未使用的Session将自动释放,否则Session持续保存Bot收到的消息,将会导致内存泄露

func (*Bot) SendFriendMessage

func (bot *Bot) SendFriendMessage(target, quote int64, msg []Message) (int64, error)

SendFriendMessage 使用此方法向指定好友发送消息 如果不需要引用回复,quote设0

func (*Bot) SendGroupMessage

func (bot *Bot) SendGroupMessage(target, quote int64, msg []Message) (int64, error)

SendGroupMessage 使用此方法向指定群发送消息

func (*Bot) SendImageMessage

func (bot *Bot) SendImageMessage(target int64, targetType string, urls []string) ([]string, error)

SendImageMessage 使用此方法向指定对象(群或好友)发送图片消息 除非需要通过此手段获取imageId,否则不推荐使用该接口

func (*Bot) SetGroupConfig

func (bot *Bot) SetGroupConfig(config GroupConfig, group int64) error

SetGroupConfig 设置群设置

func (*Bot) SetGroupMemberInfo

func (bot *Bot) SetGroupMemberInfo(info *GroupMemberInfo, group, member int64) error

SetGroupMemberInfo 设置群成员信息

func (*Bot) UnmuteAll

func (bot *Bot) UnmuteAll(group int64) error

UnmuteAll 接触全体禁言

type Client

type Client struct {
	Address string
	// 可以对HTTPClient进行自定义配置
	HTTPClient http.Client

	Bots map[int64]*Bot
	// contains filtered or unexported fields
}

Client 用于服务的Client

func NewMiraiClient

func NewMiraiClient(address, authKey string) (client *Client)

NewMiraiClient 创建一个新的Client

func (*Client) Auth

func (client *Client) Auth() (session string, err error)

Auth 使用此方法验证你的身份,并返回一个Session

func (*Client) GetManagers

func (client *Client) GetManagers(qq int64) (*[]int64, error)

GetManagers 获取指定bot的Managers

func (*Client) GetSessionConfig

func (client *Client) GetSessionConfig(session string) (*SessionConfig, error)

GetSessionConfig 获取Session的设置

func (*Client) ReleaseAllSession

func (client *Client) ReleaseAllSession()

ReleaseAllSession 释放所有会话

func (*Client) SendCommand

func (client *Client) SendCommand(commandName string, args []string) string

SendCommand 发送指令

func (*Client) SetSessionConfig

func (client *Client) SetSessionConfig(config *SessionConfig) error

SetSessionConfig 设置Session

func (*Client) Verify

func (client *Client) Verify(qq int64) (*Bot, error)

Verify 使用此方法校验并激活你的Session,同时将Session与一个已登录的Bot绑定

type CommonCall

type CommonCall struct {
	SessionKey string `json:"sessionKey"`
}

CommonCall 通用请求

type Friend

type Friend struct {
	ID       int64  `json:"id"`
	NickName string `json:"nickName"`
	Remark   string `json:"remark"`
}

Friend 好友

type Group

type Group struct {
	ID         int64  `json:"id"`
	Name       string `json:"name"`
	Permission string `json:"permission"`
}

Group 群

type GroupConfig

type GroupConfig struct {
	Name              string `json:"name"`
	Announcement      string `json:"announcement"`
	ConfessTalk       bool   `json:"confessTalk"`
	AllowMemberInvite bool   `json:"allowMemberInvite"`
	AutoApprove       bool   `json:"autoApprove"`
	AnonymousChat     bool   `json:"anonymousChat"`
}

GroupConfig 群设置

type GroupMember

type GroupMember struct {
	ID         int64  `json:"id"`
	MemberName string `json:"memberName"`
	Permission string `json:"permission"`
	Group      Group  `json:"group"`
}

GroupMember 群成员

type GroupMemberInfo

type GroupMemberInfo struct {
	Name         string `json:"name"`
	SpecialTitle string `json:"specialTitle"`
}

GroupMemberInfo 群成员信息

type InEvent

type InEvent struct {
	Type string `json:"type"`
	QQ   int64  `json:"qq,omitempty"`

	// Event
	AuthorID        int64       `json:"authorId,omitempty"`
	MessageID       int64       `json:"messageId,omitempty"`
	Time            int64       `json:"time,omitempty"`
	Group           Group       `json:"group,omitempty"`
	Origin          interface{} `json:"origin,omitempty"`
	Current         interface{} `json:"current,omitempty"`
	DurationSeconds int64       `json:"durationSeconds,omitempty"`
	IsByBot         bool        `json:"isByBot,omitempty"`
	Member          GroupMember `json:"member,omitempty"`

	//Message
	MessageChain []Message `json:"messageChain,omitempty"`

	Sender       interface{} `json:"sender,omitempty"`
	SenderGroup  GroupMember `json:"-"`
	SenderFriend Friend      `json:"-"`

	Operator       interface{} `json:"operator,omitempty"` // Operator 可能是GroupMember或int64
	OperatorGroup  GroupMember `json:"-"`
	OperatorFriend int64       `json:"-"`
}

InEvent 获取到的事件

func (*InEvent) OperatorDetail

func (e *InEvent) OperatorDetail() error

OperatorDetail 获取Operator的详细信息

func (*InEvent) SenderDetail

func (e *InEvent) SenderDetail() error

SenderDetail 获取Sender的详细信息

type InEventAll

type InEventAll struct {
	Code         int64     `json:"code"`
	ErrorMessage string    `json:"errorMessage,omitempty"`
	Data         []InEvent `json:"data,omitempty"`
}

InEvent http-api新返回格式

type Message

type Message struct {
	Type string `json:"type"`

	ID       int64     `json:"id,omitempty" message:"Source|Quote"`
	Text     string    `json:"text,omitempty" message:"Plain"`
	Time     int64     `json:"time,omitempty" message:"Source"`
	GroupID  int64     `json:"groupId,omitempty" message:"Quote"`
	SenderID int64     `json:"senderId,omitempty" message:"Quote"`
	Origin   []Message `json:"origin,omitempty" message:"Quote"`
	Target   int64     `json:"target,omitempty" message:"At"`
	Display  string    `json:"display,omitempty" message:"At"`
	FaceID   int64     `json:"faceId,omitempty" message:"Face"`
	Name     string    `json:"name,omitempty" message:"Face"`
	ImageID  string    `json:"imageId,omitempty" message:"Image"`
	URL      string    `json:"url,omitempty" message:"Image"`
	Path     string    `json:"path,omitempty" message:"Image"`
	XML      string    `json:"xml,omitempty" message:"Xml"`
	JSON     string    `json:"json,omitempty" message:"Json"`
	Content  string    `json:"content,omitempty" message:"App"`
}

Message 消息

type MessageCall

type MessageCall struct {
	CommonCall
	Target       int64     `json:"target"`
	MessageChain []Message `json:"messageChain"`
}

MessageCall 消息用

type Response

type Response struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`

	MessageID int64 `json:"messageId,omitempty"`
}

Response 通用响应

type SessionConfig

type SessionConfig struct {
	SessionKey      string `json:"sessionKey,omitempty"`
	CacheSize       int64  `json:"cacheSize"`
	EnableWebsocket bool   `json:"enableWebsocket"`
}

SessionConfig Session设置

Jump to

Keyboard shortcuts

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