robot

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventGroupChat           = "EventGroupChat"           // 群聊消息事件
	EventPrivateChat         = "EventPrivateChat"         // 私聊消息事件
	EventMPChat              = "EventMPChat"              // 公众号消息事件
	EventSelfMessage         = "EventSelfMessage"         // 自己发的消息事件
	EventFriendVerify        = "EventFriendVerify"        // 好友请求事件
	EventTransfer            = "EventTransfer"            // 好友转账事件
	EventMessageWithdraw     = "EventMessageWithdraw"     // 消息撤回事件
	EventSystem              = "EventSystem"              // 系统消息事件
	EventGroupMemberIncrease = "EventGroupMemberIncrease" // 群成员增加事件
	EventGroupMemberDecrease = "EventGroupMemberDecrease" // 群成员减少事件
	EventInvitedInGroup      = "EventInvitedInGroup"      // 被邀请入群事件
)
View Source
const (
	MsgTypeText           = 1     // 文本消息
	MsgTypeImage          = 3     // 图片消息
	MsgTypeVoice          = 34    // 语音消息
	MsgTypeAuthentication = 37    // 认证消息
	MsgTypePossibleFriend = 40    // 好友推荐消息
	MsgTypeShareCard      = 42    // 名片消息
	MsgTypeVideo          = 43    // 视频消息
	MsgTypeMemePicture    = 47    // 表情消息
	MsgTypeLocation       = 48    // 地理位置消息
	MsgTypeApp            = 49    // APP消息
	MsgTypeMicroVideo     = 62    // 小视频消息
	MsgTypeSystem         = 10000 // 系统消息
	MsgTypeRecalled       = 10002 // 消息撤回
	MsgTypeReference      = 10003 // 消息引用
)

Variables

View Source
var EmojiSymbol = []string{}/* 134 elements not displayed */

EmojiSymbol 表情符号

Functions

func AdminPermission

func AdminPermission(ctx *Ctx) bool

AdminPermission 只允许系统配置的管理员使用

func HasMemePicture

func HasMemePicture(ctx *Ctx) bool

HasMemePicture 检查消息是否存在表情包图片

func MustMemePicture

func MustMemePicture(ctx *Ctx) bool

MustMemePicture 消息不存在表情包图片阻塞至有图片,默认30s,超时返回false 阻塞时长可通过ctx.State["timeout"]设置

func OnlyAtMe

func OnlyAtMe(ctx *Ctx) bool

OnlyAtMe 只允许@机器人使用

func OnlyGroup

func OnlyGroup(ctx *Ctx) bool

OnlyGroup 只允许群聊使用

func OnlyPrivate

func OnlyPrivate(ctx *Ctx) bool

OnlyPrivate 只允许私聊使用

func Run

func Run(c *Config, f IFramework)

Run 运行并阻塞主线程,等待事件

func UserOrGroupAdmin

func UserOrGroupAdmin(ctx *Ctx) bool

UserOrGroupAdmin 允许用户单独使用或群管使用

Types

type Bot added in v1.2.0

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

func GetBot added in v1.2.0

func GetBot() *Bot

GetBot 获取机器人本身

func (*Bot) Friends added in v1.2.7

func (b *Bot) Friends() Friends

Friends 从缓存中获取好友列表

func (*Bot) GetBotNick added in v1.2.0

func (b *Bot) GetBotNick() string

GetBotNick 获取机器人昵称

func (*Bot) GetBotWxId added in v1.2.0

func (b *Bot) GetBotWxId() string

GetBotWxId 获取机器人微信ID

func (*Bot) GetCommandPrefix added in v1.2.0

func (b *Bot) GetCommandPrefix() string

GetCommandPrefix 获取命令前缀

func (*Bot) GetSelf added in v1.2.0

func (b *Bot) GetSelf() (*Self, error)

GetSelf 获取Self对象,Self对象包含了对用户、群、公众号的包装

func (*Bot) GetSuperUsers added in v1.2.0

func (b *Bot) GetSuperUsers() []string

GetSuperUsers 获取超级用户

func (*Bot) Groups added in v1.2.7

func (b *Bot) Groups() Groups

Groups 从缓存中获取群列表

func (*Bot) MPs added in v1.2.7

func (b *Bot) MPs() MPs

MPs 从缓存中获取公众号列表

type Config

type Config struct {
	BotWxId        string        `mapstructure:"botWxId"`       // 机器人微信ID
	BotNickname    string        `mapstructure:"botNickname"`   // 机器人名称
	SuperUsers     []string      `mapstructure:"superUsers"`    // 超级用户(管理员)
	CommandPrefix  string        `mapstructure:"commandPrefix"` // 管理员触发命令
	ServerPort     uint          `mapstructure:"serverPort"`    // 启动HTTP服务端口
	BufferLen      uint          `mapstructure:"-"`             // 事件缓冲区长度, 默认4096
	Latency        time.Duration `mapstructure:"-"`             // 事件处理延迟 (延迟 latency + (0~100ms) 再处理事件) (默认1s)
	MaxProcessTime time.Duration `mapstructure:"-"`             // 事件最大处理时间 (默认3min)
	Framework      struct {
		Name     string `mapstructure:"name"`     // 接入框架名称
		ApiUrl   string `mapstructure:"apiUrl"`   // 接入框架API地址
		ApiToken string `mapstructure:"apiToken"` // 接入框架API Token
	} `mapstructure:"framework"`
}

type Ctx

type Ctx struct {
	Bot   *Bot
	Event *Event
	State State
	// contains filtered or unexported fields
}

func GetCtx added in v1.2.0

func GetCtx() *Ctx

GetCtx 获取当前系统中的CTX

func (*Ctx) AgreeFriendVerify

func (ctx *Ctx) AgreeFriendVerify(v3, v4, scene string) error

AgreeFriendVerify 同意好友验证

func (*Ctx) CheckGroupSession

func (ctx *Ctx) CheckGroupSession() Rule

CheckGroupSession 判断会话连续性,必须同一个群,可以不同用户

func (*Ctx) CheckUserSession

func (ctx *Ctx) CheckUserSession() Rule

CheckUserSession 判断会话连续性,必须同一个群同一个用户

func (*Ctx) EventChannel

func (ctx *Ctx) EventChannel(rule ...Rule) *EventChannel

EventChannel 用当前事件创建一个新的事件通道

func (*Ctx) GetFriends added in v1.2.7

func (ctx *Ctx) GetFriends(isRefresh ...bool) (Friends, error)

GetFriends 获取好友列表

func (*Ctx) GetGroupMembers added in v1.2.7

func (ctx *Ctx) GetGroupMembers(groupWxId string, isRefresh ...bool) (GroupMembers, error)

GetGroupMembers 获取群组成员列表

func (*Ctx) GetGroups added in v1.2.7

func (ctx *Ctx) GetGroups(isRefresh ...bool) (Groups, error)

GetGroups 获取群组列表

func (*Ctx) GetHistoryByWxId added in v1.2.1

func (ctx *Ctx) GetHistoryByWxId(wxId string) ([]MessageRecord, error)

GetHistoryByWxId 根据wxId获取消息记录

func (*Ctx) GetHistoryByWxIdAndDate added in v1.2.2

func (ctx *Ctx) GetHistoryByWxIdAndDate(wxId, date string) ([]MessageRecord, error)

GetHistoryByWxIdAndDate 根据wxId和日期获取消息记录

func (*Ctx) GetMPs added in v1.2.7

func (ctx *Ctx) GetMPs(isRefresh ...bool) (MPs, error)

GetMPs 获取公众号列表

func (*Ctx) GetMatcher

func (ctx *Ctx) GetMatcher() *Matcher

GetMatcher 获取匹配器

func (*Ctx) GetMemePictures added in v1.2.1

func (ctx *Ctx) GetMemePictures() (string, bool)

GetMemePictures 获取表情包图片地址

func (*Ctx) InviteIntoGroup

func (ctx *Ctx) InviteIntoGroup(groupWxId, wxId string, typ int) error

InviteIntoGroup 邀请好友加入群组; typ:1-直接拉,2-发送邀请链接

func (*Ctx) IsApp

func (ctx *Ctx) IsApp() bool

IsApp 判断消息类型是否是APP消息

func (*Ctx) IsAt

func (ctx *Ctx) IsAt() bool

IsAt 判断是否被@了,仅在群聊中有效,私聊也算被@了

func (*Ctx) IsAuthentication

func (ctx *Ctx) IsAuthentication() bool

IsAuthentication 判断消息类型是否是认证消息

func (*Ctx) IsEventFriendVerify

func (ctx *Ctx) IsEventFriendVerify() bool

IsEventFriendVerify 判断消息是否是好友请求消息

func (*Ctx) IsEventGroupChat

func (ctx *Ctx) IsEventGroupChat() bool

IsEventGroupChat 判断消息是否是群聊消息

func (*Ctx) IsEventPrivateChat

func (ctx *Ctx) IsEventPrivateChat() bool

IsEventPrivateChat 判断消息是否是私聊消息

func (*Ctx) IsEventSelfMessage added in v1.0.10

func (ctx *Ctx) IsEventSelfMessage() bool

IsEventSelfMessage 判断消息是否是机器人自己发出的消息

func (*Ctx) IsEventSubscription added in v1.1.2

func (ctx *Ctx) IsEventSubscription() bool

IsEventSubscription 判断消息是否是订阅消息

func (*Ctx) IsImage

func (ctx *Ctx) IsImage() bool

IsImage 判断消息类型是否为图片

func (*Ctx) IsLocation

func (ctx *Ctx) IsLocation() bool

IsLocation 判断消息类型是否是地理位置消息

func (*Ctx) IsMemePictures

func (ctx *Ctx) IsMemePictures() bool

IsMemePictures 判断消息类型是否为表情包

func (*Ctx) IsMicroVideo

func (ctx *Ctx) IsMicroVideo() bool

IsMicroVideo 判断消息类型是否是小视频消息

func (*Ctx) IsPossibleFriend

func (ctx *Ctx) IsPossibleFriend() bool

IsPossibleFriend 判断消息类型是否是好友推荐消息

func (*Ctx) IsRecalled

func (ctx *Ctx) IsRecalled() bool

IsRecalled 判断消息类型是否是消息撤回

func (*Ctx) IsReference

func (ctx *Ctx) IsReference() bool

IsReference 判断消息类型是否是消息引用

func (*Ctx) IsShareCard

func (ctx *Ctx) IsShareCard() bool

IsShareCard 判断消息类型是否是名片消息

func (*Ctx) IsSystem

func (ctx *Ctx) IsSystem() bool

IsSystem 判断消息类型是否是系统消息

func (*Ctx) IsText

func (ctx *Ctx) IsText() bool

IsText 判断消息类型是否为文本

func (*Ctx) IsVideo

func (ctx *Ctx) IsVideo() bool

IsVideo 判断消息类型是否是视频消息

func (*Ctx) IsVoice

func (ctx *Ctx) IsVoice() bool

IsVoice 判断消息类型是否为语音

func (*Ctx) MessageString

func (ctx *Ctx) MessageString() string

MessageString 字符串消息便于Regex

func (*Ctx) ReplyBusinessCard

func (ctx *Ctx) ReplyBusinessCard(targetWxId string) error

ReplyBusinessCard 回复名片消息

func (*Ctx) ReplyEmoji

func (ctx *Ctx) ReplyEmoji(path string) error

ReplyEmoji 回复表情消息

func (*Ctx) ReplyFavorites

func (ctx *Ctx) ReplyFavorites(favoritesId string) error

ReplyFavorites 回复收藏消息

func (*Ctx) ReplyFile

func (ctx *Ctx) ReplyFile(path string) error

ReplyFile 回复文件消息

func (*Ctx) ReplyImage

func (ctx *Ctx) ReplyImage(path string) error

ReplyImage 回复图片消息

func (*Ctx) ReplyMessageRecord

func (ctx *Ctx) ReplyMessageRecord(title string, dataList []map[string]interface{}) error

ReplyMessageRecord 回复消息记录

func (*Ctx) ReplyMessageRecordXML

func (ctx *Ctx) ReplyMessageRecordXML(xmlStr string) error

ReplyMessageRecordXML 回复消息记录(XML方式)

func (*Ctx) ReplyMiniProgram

func (ctx *Ctx) ReplyMiniProgram(ghId, title, content, imagePath, jumpPath string) error

ReplyMiniProgram 回复小程序消息

func (*Ctx) ReplyMusic

func (ctx *Ctx) ReplyMusic(name, author, app, jumpUrl, musicUrl, coverUrl string) error

ReplyMusic 回复音乐消息

func (ctx *Ctx) ReplyShareLink(title, desc, imageUrl, jumpUrl string) error

ReplyShareLink 回复分享链接消息

func (*Ctx) ReplyText

func (ctx *Ctx) ReplyText(text string) error

ReplyText 回复文本消息

func (*Ctx) ReplyTextAndAt

func (ctx *Ctx) ReplyTextAndAt(text string) error

ReplyTextAndAt 回复文本消息并@某人,如果在私聊中则不会@某人

func (*Ctx) ReplyVideo

func (ctx *Ctx) ReplyVideo(path string) error

ReplyVideo 回复视频消息

func (*Ctx) ReplyXML

func (ctx *Ctx) ReplyXML(xmlStr string) error

ReplyXML 回复XML消息

func (*Ctx) SendBusinessCard

func (ctx *Ctx) SendBusinessCard(toWxId, targetWxId string) error

SendBusinessCard 发送名片消息到指定好友

func (*Ctx) SendEmoji

func (ctx *Ctx) SendEmoji(wxId, path string) error

SendEmoji 发送表情消息到指定好友

func (*Ctx) SendFavorites

func (ctx *Ctx) SendFavorites(toWxId, favoritesId string) error

SendFavorites 发送收藏消息到指定好友

func (*Ctx) SendFile

func (ctx *Ctx) SendFile(wxId, path string) error

SendFile 发送文件消息到指定好友

func (*Ctx) SendImage

func (ctx *Ctx) SendImage(wxId, path string) error

SendImage 发送图片消息到指定好友

func (*Ctx) SendMessageRecord

func (ctx *Ctx) SendMessageRecord(toWxId, title string, dataList []map[string]interface{}) error

SendMessageRecord 发送消息记录到指定好友

func (*Ctx) SendMessageRecordXML

func (ctx *Ctx) SendMessageRecordXML(toWxId, xmlStr string) error

SendMessageRecordXML 发送消息记录(XML方式)到指定好友

func (*Ctx) SendMiniProgram

func (ctx *Ctx) SendMiniProgram(toWxId, ghId, title, content, imagePath, jumpPath string) error

SendMiniProgram 发送小程序消息到指定好友

func (*Ctx) SendMusic

func (ctx *Ctx) SendMusic(toWxId, name, author, app, jumpUrl, musicUrl, coverUrl string) error

SendMusic 发送音乐消息到指定好友

func (ctx *Ctx) SendShareLink(wxId, title, desc, imageUrl, jumpUrl string) error

SendShareLink 发送分享链接消息到指定好友

func (*Ctx) SendText

func (ctx *Ctx) SendText(wxId, text string) error

SendText 发送文本消息到指定好友

func (*Ctx) SendTextAndAt

func (ctx *Ctx) SendTextAndAt(groupWxId, wxId, text string) error

SendTextAndAt 发送文本消息并@某人到指定群指定用户,仅限群聊

func (*Ctx) SendVideo

func (ctx *Ctx) SendVideo(wxId, path string) error

SendVideo 发送视频消息到指定好友

func (*Ctx) SendXML

func (ctx *Ctx) SendXML(toWxId, xmlStr string) error

SendXML 发送XML消息到指定好友

type Engine

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

func New

func New() *Engine

New 生成空引擎

func (*Engine) On

func (e *Engine) On(rules ...Rule) *Matcher

On 添加新的匹配器

func (*Engine) OnCommand

func (e *Engine) OnCommand(commands string, rules ...Rule) *Matcher

OnCommand 命令触发器

func (*Engine) OnCommandGroup

func (e *Engine) OnCommandGroup(commands []string, rules ...Rule) *Matcher

OnCommandGroup 命令触发器组

func (*Engine) OnFullMatch

func (e *Engine) OnFullMatch(src string, rules ...Rule) *Matcher

OnFullMatch 完全匹配触发器

func (*Engine) OnFullMatchGroup

func (e *Engine) OnFullMatchGroup(src []string, rules ...Rule) *Matcher

OnFullMatchGroup 完全匹配触发器组

func (*Engine) OnKeyword

func (e *Engine) OnKeyword(keyword string, rules ...Rule) *Matcher

OnKeyword 关键词触发器

func (*Engine) OnKeywordGroup

func (e *Engine) OnKeywordGroup(keywords []string, rules ...Rule) *Matcher

OnKeywordGroup 关键词触发器组

func (*Engine) OnMessage added in v1.2.1

func (e *Engine) OnMessage(rules ...Rule) *Matcher

OnMessage 消息触发器

func (*Engine) OnPrefix

func (e *Engine) OnPrefix(prefix string, rules ...Rule) *Matcher

OnPrefix 前缀触发器

func (*Engine) OnPrefixGroup

func (e *Engine) OnPrefixGroup(prefix []string, rules ...Rule) *Matcher

OnPrefixGroup 前缀触发器组

func (*Engine) OnRegex

func (e *Engine) OnRegex(regexPattern string, rules ...Rule) *Matcher

OnRegex 正则触发器

func (*Engine) OnSuffix

func (e *Engine) OnSuffix(suffix string, rules ...Rule) *Matcher

OnSuffix 后缀触发器

func (*Engine) OnSuffixGroup

func (e *Engine) OnSuffixGroup(suffix []string, rules ...Rule) *Matcher

OnSuffixGroup 后缀触发器组

func (*Engine) SetBlock

func (e *Engine) SetBlock(block bool) *Engine

SetBlock 设置是否阻断后续处理器

func (*Engine) UseMidHandler

func (e *Engine) UseMidHandler(rules ...Rule)

UseMidHandler 添加中间处理器,会在 Rule 判断后, Matcher 触发前触发,如果 midHandler 没有通过,则 Matcher 不会触发 可用于速率限制等

func (*Engine) UsePostHandler

func (e *Engine) UsePostHandler(handler ...Handler)

UsePostHandler 添加后置处理器,会在 Matcher 触发后触发,如果 postHandler 返回 false,则后续的 post handler 不会触发 可用于反并发等

func (*Engine) UsePreHandler

func (e *Engine) UsePreHandler(rules ...Rule)

UsePreHandler 添加前置处理器,会在 Rule 判断前触发,如果 preHandler 没有通过,则 Rule, Matcher 不会触发 可用于分群组管理插件等

type Event

type Event struct {
	Type                string               // 消息类型
	RobotWxId           string               // 机器人微信id
	IsAtMe              bool                 // 机器人是否被@了,@所有人不算
	FromUniqueID        string               // 消息来源唯一id, 私聊为发送者微信id, 群聊为群id
	FromUniqueName      string               // 消息来源唯一名称, 私聊为发送者昵称, 群聊为群名称
	FromWxId            string               // 消息来源微信id
	FromName            string               // 消息来源昵称
	FromGroup           string               // 消息来源群id
	FromGroupName       string               // 消息来源群名称
	RawMessage          string               // 原始消息
	Message             *Message             // 消息内容
	SubscriptionMessage *Message             // 订阅号消息
	FriendVerify        *FriendVerify        // 好友验证消息
	Transfer            *Transfer            // 转账消息
	Withdraw            *Withdraw            // 撤回消息
	GroupMemberIncrease *GroupMemberIncrease // 群成员增加消息
	GroupMemberDecrease *GroupMemberDecrease // 群成员减少消息
}

Event 记录一次回调事件

type EventBuffer

type EventBuffer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewEventBuffer

func NewEventBuffer(bufferLen uint) *EventBuffer

func (*EventBuffer) Loop

func (e *EventBuffer) Loop(latency, maxWait time.Duration, process func(*Event, IFramework, time.Duration))

Loop 以给定的延迟和最长等待时间处理环中的事件

func (*EventBuffer) ProcessEvent

func (e *EventBuffer) ProcessEvent(event *Event, framework IFramework)

ProcessEvent 处理事件

func (*EventBuffer) Stop

func (e *EventBuffer) Stop()

Stop 停止事件处理循环

type EventBufferItem

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

type EventChannel

type EventChannel struct {
	Type     string
	Priority uint64
	Rule     []Rule
	Block    bool
}

EventChannel 用于异步获取指定事件

func NewEventChannel

func NewEventChannel(Priority uint64, Block bool, rule ...Rule) *EventChannel

NewEventChannel 创建一个新的 EventChannel用于异步获取指定事件

func (*EventChannel) Next

func (n *EventChannel) Next() <-chan *Ctx

Next 返回一个 chan 用于接收下一个指定事件 该 chan 必须接收,如需手动取消监听,请使用 Repeat 方法

func (*EventChannel) Repeat

func (n *EventChannel) Repeat() (recv <-chan *Ctx, cancel func())

Repeat 返回一个 chan 用于接收无穷个指定事件,和一个取消监听的函数 如果没有取消监听,将不断监听指定事件

type Friend added in v1.2.0

type Friend struct{ *User }

Friend 好友对象

func (*Friend) AsUser added in v1.2.7

func (f *Friend) AsUser() *User

AsUser 将当前对象转换为User对象

func (*Friend) SendBusinessCard added in v1.2.0

func (f *Friend) SendBusinessCard(targetWxId string) error

SendBusinessCard 发送名片消息

func (*Friend) SendEmoji added in v1.2.0

func (f *Friend) SendEmoji(path string) error

SendEmoji 发送表情消息

func (*Friend) SendFavorites added in v1.2.0

func (f *Friend) SendFavorites(favoritesId string) error

SendFavorites 发送收藏消息

func (*Friend) SendFile added in v1.2.0

func (f *Friend) SendFile(path string) error

SendFile 发送文件消息

func (*Friend) SendImage added in v1.2.0

func (f *Friend) SendImage(path string) error

SendImage 发送图片消息

func (*Friend) SendMessageRecord added in v1.2.0

func (f *Friend) SendMessageRecord(title string, dataList []map[string]interface{}) error

SendMessageRecord 发送消息记录

func (*Friend) SendMessageRecordXML added in v1.2.0

func (f *Friend) SendMessageRecordXML(xmlStr string) error

SendMessageRecordXML 发送消息记录(支持xml)

func (*Friend) SendMiniProgram added in v1.2.0

func (f *Friend) SendMiniProgram(ghId, title, content, imagePath, jumpPath string) error

SendMiniProgram 发送小程序消息

func (*Friend) SendMusic added in v1.2.0

func (f *Friend) SendMusic(name, author, app, jumpUrl, musicUrl, coverUrl string) error

SendMusic 发送音乐消息

func (f *Friend) SendShareLink(title, desc, imageUrl, jumpUrl string) error

SendShareLink 发送分享链接消息

func (*Friend) SendText added in v1.2.0

func (f *Friend) SendText(content string) error

SendText 发送文本消息

func (*Friend) SendVideo added in v1.2.0

func (f *Friend) SendVideo(path string) error

SendVideo 发送视频消息

func (*Friend) SendXML added in v1.2.0

func (f *Friend) SendXML(xmlStr string) error

SendXML 发送xml消息

type FriendVerify

type FriendVerify struct {
	WxId      string // 发送者微信id
	Nick      string // 发送者昵称
	V1        string // 验证V1
	V2        string // 验证V2
	V3        string // 验证V3
	V4        string // 验证V4
	AvatarUrl string // 头像url
	Content   string // 验证内容
	Scene     string // 验证场景
}

FriendVerify 记录好友验证消息的具体内容

type Friends added in v1.2.0

type Friends []*Friend

Friends 好友列表

func (Friends) Count added in v1.2.0

func (f Friends) Count() int

Count 获取好友的数量

func (Friends) SendBusinessCard added in v1.2.7

func (f Friends) SendBusinessCard(targetWxId string, delays ...time.Duration) error

SendBusinessCard 依次发送名片消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Friends) SendEmoji added in v1.2.7

func (f Friends) SendEmoji(path string, delays ...time.Duration) error

SendEmoji 依次发送表情消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Friends) SendFavorites added in v1.2.7

func (f Friends) SendFavorites(favoritesId string, delays ...time.Duration) error

SendFavorites 依次发送收藏消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Friends) SendFile added in v1.2.7

func (f Friends) SendFile(path string, delays ...time.Duration) error

SendFile 依次发送文件消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Friends) SendImage added in v1.2.7

func (f Friends) SendImage(path string, delays ...time.Duration) error

SendImage 依次发送图片消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Friends) SendMessageRecord added in v1.2.7

func (f Friends) SendMessageRecord(title string, dataList []map[string]interface{}, delays ...time.Duration) error

SendMessageRecord 依次发送消息记录, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Friends) SendMessageRecordXML added in v1.2.7

func (f Friends) SendMessageRecordXML(xmlStr string, delays ...time.Duration) error

SendMessageRecordXML 依次发送消息记录, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Friends) SendMiniProgram added in v1.2.7

func (f Friends) SendMiniProgram(ghId, title, content, imagePath, jumpPath string, delays ...time.Duration) error

SendMiniProgram 依次发送小程序消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Friends) SendMusic added in v1.2.7

func (f Friends) SendMusic(name, author, app, jumpUrl, musicUrl, coverUrl string, delays ...time.Duration) error

SendMusic 依次发送音乐消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (f Friends) SendShareLink(title, desc, imageUrl, jumpUrl string, delays ...time.Duration) error

SendShareLink 依次发送分享链接消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Friends) SendText added in v1.2.7

func (f Friends) SendText(content string, delays ...time.Duration) error

SendText 依次发送文本消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Friends) SendVideo added in v1.2.7

func (f Friends) SendVideo(path string, delays ...time.Duration) error

SendVideo 依次发送视频消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Friends) SendXML added in v1.2.7

func (f Friends) SendXML(xmlStr string, delays ...time.Duration) error

SendXML 依次发送XML消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

type Group added in v1.2.0

type Group struct{ *User }

Group 群组对象

func (*Group) AsUser added in v1.2.7

func (g *Group) AsUser() *User

AsUser 将当前对象转换为User对象

func (*Group) SendBusinessCard added in v1.2.7

func (g *Group) SendBusinessCard(targetWxId string) error

SendBusinessCard 发送名片消息

func (*Group) SendEmoji added in v1.2.7

func (g *Group) SendEmoji(path string) error

SendEmoji 发送表情消息

func (*Group) SendFavorites added in v1.2.7

func (g *Group) SendFavorites(favoritesId string) error

SendFavorites 发送收藏消息

func (*Group) SendFile added in v1.2.7

func (g *Group) SendFile(path string) error

SendFile 发送文件消息

func (*Group) SendImage added in v1.2.7

func (g *Group) SendImage(path string) error

SendImage 发送图片消息

func (*Group) SendMessageRecord added in v1.2.7

func (g *Group) SendMessageRecord(title string, dataList []map[string]interface{}) error

SendMessageRecord 发送消息记录

func (*Group) SendMessageRecordXML added in v1.2.7

func (g *Group) SendMessageRecordXML(xmlStr string) error

SendMessageRecordXML 发送消息记录(支持xml)

func (*Group) SendMiniProgram added in v1.2.7

func (g *Group) SendMiniProgram(ghId, title, content, imagePath, jumpPath string) error

SendMiniProgram 发送小程序消息

func (*Group) SendMusic added in v1.2.7

func (g *Group) SendMusic(name, author, app, jumpUrl, musicUrl, coverUrl string) error

SendMusic 发送音乐消息

func (g *Group) SendShareLink(title, desc, imageUrl, jumpUrl string) error

SendShareLink 发送分享链接消息

func (*Group) SendText added in v1.2.7

func (g *Group) SendText(content string) error

SendText 发送文本消息

func (*Group) SendVideo added in v1.2.7

func (g *Group) SendVideo(path string) error

SendVideo 发送视频消息

func (*Group) SendXML added in v1.2.7

func (g *Group) SendXML(xmlStr string) error

SendXML 发送xml消息

type GroupMemberDecrease added in v1.0.10

type GroupMemberDecrease struct {
}

GroupMemberDecrease 记录群成员减少消息的具体内容

type GroupMemberIncrease added in v1.0.10

type GroupMemberIncrease struct {
}

GroupMemberIncrease 记录群成员增加消息的具体内容

type GroupMembers added in v1.2.7

type GroupMembers []*User

GroupMembers 群成员列表对象

func (GroupMembers) Count added in v1.2.7

func (g GroupMembers) Count() int

Count 获取群成员数量

type Groups added in v1.2.0

type Groups []*Group

Groups 群组列表

func (Groups) Count added in v1.2.7

func (g Groups) Count() int

Count 获取群组的数量

func (Groups) SendBusinessCard added in v1.2.7

func (g Groups) SendBusinessCard(targetWxId string, delays ...time.Duration) error

SendBusinessCard 依次发送名片消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Groups) SendEmoji added in v1.2.7

func (g Groups) SendEmoji(path string, delays ...time.Duration) error

SendEmoji 依次发送表情消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Groups) SendFavorites added in v1.2.7

func (g Groups) SendFavorites(favoritesId string, delays ...time.Duration) error

SendFavorites 依次发送收藏夹消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Groups) SendFile added in v1.2.7

func (g Groups) SendFile(path string, delays ...time.Duration) error

SendFile 依次发送文件消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Groups) SendImage added in v1.2.7

func (g Groups) SendImage(path string, delays ...time.Duration) error

SendImage 依次发送图片消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Groups) SendMessageRecord added in v1.2.7

func (g Groups) SendMessageRecord(title string, dataList []map[string]interface{}, delays ...time.Duration) error

SendMessageRecord 依次发送消息记录, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Groups) SendMessageRecordXML added in v1.2.7

func (g Groups) SendMessageRecordXML(xmlStr string, delays ...time.Duration) error

SendMessageRecordXML 依次发送消息记录, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Groups) SendMiniProgram added in v1.2.7

func (g Groups) SendMiniProgram(ghId, title, content, imagePath, jumpPath string, delays ...time.Duration) error

SendMiniProgram 依次发送小程序消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Groups) SendMusic added in v1.2.7

func (g Groups) SendMusic(name, author, app, jumpUrl, musicUrl, coverUrl string, delays ...time.Duration) error

SendMusic 依次发送音乐消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (g Groups) SendShareLink(title, desc, imageUrl, jumpUrl string, delays ...time.Duration) error

SendShareLink 依次发送分享链接消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Groups) SendText added in v1.2.7

func (g Groups) SendText(content string, delays ...time.Duration) error

SendText 依次发送文本消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Groups) SendVideo added in v1.2.7

func (g Groups) SendVideo(path string, delays ...time.Duration) error

SendVideo 依次发送视频消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (Groups) SendXML added in v1.2.7

func (g Groups) SendXML(xmlStr string, delays ...time.Duration) error

SendXML 依次发送XML消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

type Handler

type Handler func(ctx *Ctx) // 事件处理

type IFramework

type IFramework interface {
	// Callback 这是消息回调方法,vx框架回调消息转发给该Server
	Callback(func(*Event, IFramework))

	// GetMemePictures 获取表情包图片地址(迷因图)
	// return: 图片链接(网络URL或图片base64)
	GetMemePictures(message *Message) string

	// SendText 发送文本消息
	// toWxId: 好友ID/群ID
	// text: 文本内容
	SendText(toWxId, text string) error

	// SendTextAndAt 发送文本消息并@,只有群聊有效
	// toGroupWxId: 群ID
	// toWxId: 好友ID/群ID/all
	// toWxName: 好友昵称/群昵称,留空为自动获取
	// text: 文本内容
	SendTextAndAt(toGroupWxId, toWxId, toWxName, text string) error

	// SendImage 发送图片消息
	// toWxId: 好友ID/群ID
	// path: 图片路径
	SendImage(toWxId, path string) error

	// SendShareLink 发送分享链接消息
	// toWxId: 好友ID/群ID
	// title: 标题
	// desc: 描述
	// imageUrl: 图片链接
	// jumpUrl: 跳转链接
	SendShareLink(toWxId, title, desc, imageUrl, jumpUrl string) error

	// SendFile 发送文件消息
	// toWxId: 好友ID/群ID/公众号ID
	// path: 本地文件绝对路径
	SendFile(toWxId, path string) error

	// SendVideo 发送视频消息
	// toWxId: 好友ID/群ID/公众号ID
	// path: 本地视频文件绝对路径
	SendVideo(toWxId, path string) error

	// SendEmoji 发送表情消息
	// toWxId: 好友ID/群ID/公众号ID
	// path: 本地动态表情文件绝对路径
	SendEmoji(toWxId, path string) error

	// SendMusic 发送音乐消息
	// toWxId: 好友ID/群ID/公众号ID
	// name: 音乐名称
	// author: 音乐作者
	// app: 音乐来源(VLW需留空),酷狗/wx79f2c4418704b4f8,网易云/wx8dd6ecd81906fd84,QQ音乐/wx5aa333606550dfd5
	// jumpUrl: 音乐跳转链接
	// musicUrl: 网络歌曲直链
	// coverUrl: 封面图片链接
	SendMusic(toWxId, name, author, app, jumpUrl, musicUrl, coverUrl string) error

	// SendMiniProgram 发送小程序消息
	// toWxId: 好友ID/群ID/公众号ID
	// ghId: 小程序ID
	// title: 标题
	// content: 内容
	// imagePath: 图片路径, 本地图片路径或网络图片URL
	// jumpPath: 小程序点击跳转地址,例如:pages/index/index.html
	SendMiniProgram(toWxId, ghId, title, content, imagePath, jumpPath string) error

	// SendMessageRecord 发送消息记录
	// toWxId: 好友ID/群ID/公众号ID
	// title: 仅供电脑上显示用,手机上的话微信会根据[显示昵称]来自动生成 谁和谁的聊天记录
	// dataList:
	// 	- wxid: 发送此条消息的人的wxid
	// 	- nickName: 显示的昵称(可随意伪造)
	// 	- timestamp: 10位时间戳
	// 	- msg: 消息内容
	SendMessageRecord(toWxId, title string, dataList []map[string]interface{}) error

	// SendMessageRecordXML 发送消息记录(XML方式)
	// toWxId: 好友ID/群ID/公众号ID
	// xmlStr: 消息记录XML代码
	SendMessageRecordXML(toWxId, xmlStr string) error

	// SendFavorites 发送收藏消息
	// toWxId: 好友ID/群ID/公众号ID
	// favoritesId: 收藏夹ID
	SendFavorites(toWxId, favoritesId string) error

	// SendXML 发送XML消息
	// toWxId: 好友ID/群ID/公众号ID
	// xmlStr: XML代码
	SendXML(toWxId, xmlStr string) error

	// SendBusinessCard 发送名片消息
	// toWxId: 好友ID/群ID/公众号ID
	// targetWxId: 目标用户ID
	SendBusinessCard(toWxId, targetWxId string) error

	// AgreeFriendVerify 同意好友验证
	// v3: 验证V3
	// v4: 验证V4
	// scene: 验证场景
	AgreeFriendVerify(v3, v4, scene string) error

	// InviteIntoGroup 邀请好友加入群组
	// groupWxId: 群ID
	// wxId: 好友ID
	// typ: 邀请类型,1-直接拉,2-发送邀请链接
	InviteIntoGroup(groupWxId, wxId string, typ int) error

	// GetObjectInfo 获取对象信息
	// wxId: 好友ID/群ID/公众号ID
	// return: User, error
	GetObjectInfo(wxId string) (*User, error)

	// GetFriends 获取好友列表
	// isRefresh: 是否刷新 false-从缓存中获取,true-重新遍历二叉树并刷新缓存
	// return: []*User, error
	GetFriends(isRefresh bool) ([]*User, error)

	// GetGroups 获取群组列表
	// isRefresh: 是否刷新 false-从缓存中获取,true-重新遍历二叉树并刷新缓存
	// return: []*User, error
	GetGroups(isRefresh bool) ([]*User, error)

	// GetGroupMembers 获取群成员列表
	// groupWxId: 群ID
	// isRefresh: 是否刷新 false-从缓存中获取,true-重新遍历二叉树并刷新缓存
	// return: []*User, error
	GetGroupMembers(groupWxId string, isRefresh bool) ([]*User, error)

	// GetMPs 获取公众号订阅列表
	// isRefresh: 是否刷新 false-从缓存中获取,true-重新遍历二叉树并刷新缓存
	// return: []*User, error
	GetMPs(isRefresh bool) ([]*User, error)
}

IFramework 这是接入框架所定义的接口

type MP added in v1.2.0

type MP struct{ *User }

MP 公众号对象

func (*MP) AsUser added in v1.2.7

func (m *MP) AsUser() *User

AsUser 将当前对象转换为User对象

func (*MP) SendBusinessCard added in v1.2.7

func (m *MP) SendBusinessCard(targetWxId string) error

SendBusinessCard 发送名片消息

func (*MP) SendEmoji added in v1.2.7

func (m *MP) SendEmoji(path string) error

SendEmoji 发送表情消息

func (*MP) SendFavorites added in v1.2.7

func (m *MP) SendFavorites(favoritesId string) error

SendFavorites 发送收藏消息

func (*MP) SendFile added in v1.2.7

func (m *MP) SendFile(path string) error

SendFile 发送文件消息

func (*MP) SendImage added in v1.2.7

func (m *MP) SendImage(path string) error

SendImage 发送图片消息

func (*MP) SendMessageRecord added in v1.2.7

func (m *MP) SendMessageRecord(title string, dataList []map[string]interface{}) error

SendMessageRecord 发送消息记录

func (*MP) SendMessageRecordXML added in v1.2.7

func (m *MP) SendMessageRecordXML(xmlStr string) error

SendMessageRecordXML 发送消息记录(支持xml)

func (*MP) SendMiniProgram added in v1.2.7

func (m *MP) SendMiniProgram(ghId, title, content, imagePath, jumpPath string) error

SendMiniProgram 发送小程序消息

func (*MP) SendMusic added in v1.2.7

func (m *MP) SendMusic(name, author, app, jumpUrl, musicUrl, coverUrl string) error

SendMusic 发送音乐消息

func (m *MP) SendShareLink(title, desc, imageUrl, jumpUrl string) error

SendShareLink 发送分享链接消息

func (*MP) SendText added in v1.2.7

func (m *MP) SendText(content string) error

SendText 发送文本消息

func (*MP) SendVideo added in v1.2.7

func (m *MP) SendVideo(path string) error

SendVideo 发送视频消息

func (*MP) SendXML added in v1.2.7

func (m *MP) SendXML(xmlStr string) error

SendXML 发送xml消息

type MPs added in v1.2.0

type MPs []*MP

MPs 公众号列表

func (MPs) Count added in v1.2.7

func (m MPs) Count() int

Count 获取公众号的数量

func (MPs) SendBusinessCard added in v1.2.7

func (m MPs) SendBusinessCard(targetWxId string, delays ...time.Duration) error

SendBusinessCard 依次发送名片消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (MPs) SendEmoji added in v1.2.7

func (m MPs) SendEmoji(path string, delays ...time.Duration) error

SendEmoji 依次发送表情消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (MPs) SendFavorites added in v1.2.7

func (m MPs) SendFavorites(favoritesId string, delays ...time.Duration) error

SendFavorites 依次发送收藏夹消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (MPs) SendFile added in v1.2.7

func (m MPs) SendFile(path string, delays ...time.Duration) error

SendFile 依次发送文件消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (MPs) SendImage added in v1.2.7

func (m MPs) SendImage(path string, delays ...time.Duration) error

SendImage 依次发送图片消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (MPs) SendMessageRecord added in v1.2.7

func (m MPs) SendMessageRecord(title string, dataList []map[string]interface{}, delays ...time.Duration) error

SendMessageRecord 依次发送消息记录, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (MPs) SendMessageRecordXML added in v1.2.7

func (m MPs) SendMessageRecordXML(xmlStr string, delays ...time.Duration) error

SendMessageRecordXML 依次发送消息记录, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (MPs) SendMiniProgram added in v1.2.7

func (m MPs) SendMiniProgram(ghId, title, content, imagePath, jumpPath string, delays ...time.Duration) error

SendMiniProgram 依次发送小程序消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (MPs) SendMusic added in v1.2.7

func (m MPs) SendMusic(name, author, app, jumpUrl, musicUrl, coverUrl string, delays ...time.Duration) error

SendMusic 依次发送音乐消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (m MPs) SendShareLink(title, desc, imageUrl, jumpUrl string, delays ...time.Duration) error

SendShareLink 依次发送分享链接消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (MPs) SendText added in v1.2.7

func (m MPs) SendText(content string, delays ...time.Duration) error

SendText 依次发送文本消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (MPs) SendVideo added in v1.2.7

func (m MPs) SendVideo(path string, delays ...time.Duration) error

SendVideo 依次发送视频消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

func (MPs) SendXML added in v1.2.7

func (m MPs) SendXML(xmlStr string, delays ...time.Duration) error

SendXML 依次发送XML消息, delays为每个好友发送消息的间隔时间, 默认为1秒, 为0时不间隔

type Matcher

type Matcher struct {
	// Temp 是否为临时Matcher,临时 Matcher 匹配一次后就会删除当前 Matcher
	Temp bool

	// Block 是否阻断后续 Matcher,为true时当前Matcher匹配成功后,后续Matcher不参与匹配
	Block bool

	// Break 是否退出后续匹配流程, 只有 Rule 返回false且此值为真才会退出, 且不对 mid handler以下的 Rule 生效
	Break bool

	// NoTimeout 处理是否不设超时
	NoTimeout bool

	// Priority 优先级,越小优先级越高
	Priority uint64

	// Rules 匹配规则
	Rules []Rule

	// Handler 处理事件的函数
	Handler Handler

	// Engine 注册 Matcher 的 Engine,Engine可为一系列 Matcher 添加通用 Rule 和其他钩子
	Engine *Engine
}

Matcher 是匹配和处理事件的最小单元

func On

func On(rules ...Rule) *Matcher

On 添加新的匹配器

func OnCommand

func OnCommand(commands string, rules ...Rule) *Matcher

OnCommand 命令触发器

func OnCommandGroup

func OnCommandGroup(commands []string, rules ...Rule) *Matcher

OnCommandGroup 命令触发器组

func OnFullMatch

func OnFullMatch(src string, rules ...Rule) *Matcher

OnFullMatch 完全匹配触发器

func OnFullMatchGroup

func OnFullMatchGroup(src []string, rules ...Rule) *Matcher

OnFullMatchGroup 完全匹配触发器组

func OnKeyword

func OnKeyword(keyword string, rules ...Rule) *Matcher

OnKeyword 关键词触发器

func OnKeywordGroup

func OnKeywordGroup(keywords []string, rules ...Rule) *Matcher

OnKeywordGroup 关键词触发器组

func OnMessage added in v1.2.1

func OnMessage(rules ...Rule) *Matcher

OnMessage 消息触发器

func OnPrefix

func OnPrefix(prefix string, rules ...Rule) *Matcher

OnPrefix 前缀触发器

func OnPrefixGroup

func OnPrefixGroup(prefix []string, rules ...Rule) *Matcher

OnPrefixGroup 前缀触发器组

func OnRegex

func OnRegex(regexPattern string, rules ...Rule) *Matcher

OnRegex 正则触发器

func OnSuffix

func OnSuffix(suffix string, rules ...Rule) *Matcher

OnSuffix 后缀触发器

func OnSuffixGroup

func OnSuffixGroup(suffix []string, rules ...Rule) *Matcher

OnSuffixGroup 后缀触发器组

func StoreMatcher

func StoreMatcher(m *Matcher) *Matcher

StoreMatcher 向匹配器列表中添加一个匹配器

func StoreTempMatcher

func StoreTempMatcher(m *Matcher) *Matcher

StoreTempMatcher 向匹配器列表中添加一个临时匹配器,临时匹配器只会触发匹配一次

func (*Matcher) Delete

func (m *Matcher) Delete()

Delete 从匹配器列表中删除当前匹配器

func (*Matcher) EventChannel

func (m *Matcher) EventChannel(rule ...Rule) *EventChannel

EventChannel 用当前上下文创建一个EventChannel,会阻塞其他事件

func (*Matcher) FirstPriority

func (m *Matcher) FirstPriority() *Matcher

FirstPriority 设置当前 Matcher 优先级 - 0

func (*Matcher) Handle

func (m *Matcher) Handle(handler Handler) *Matcher

Handle 直接处理事件

func (*Matcher) SetBlock

func (m *Matcher) SetBlock(block bool) *Matcher

SetBlock 设置是否阻断后面的 Matcher 触发

func (*Matcher) SetNoTimeout

func (m *Matcher) SetNoTimeout(noTimeout bool) *Matcher

SetNoTimeout 设置处理时不设超时

func (*Matcher) SetPriority

func (m *Matcher) SetPriority(priority uint64) *Matcher

SetPriority 设置当前 Matcher 优先级

type Message

type Message struct {
	Id      string // 消息id
	Type    int64  // 消息类型
	Content string // 消息内容
}

Message 记录消息的具体内容

type MessageRecord added in v1.2.1

type MessageRecord struct {
	ID         uint      `gorm:"primarykey"`         // 主键
	Type       string    `gorm:"column:type"`        // 消息类型
	FromWxId   string    `gorm:"column:from_wxid"`   // 消息来源wxid,群消息为群wxid,私聊消息为发送者wxid
	FromNick   string    `gorm:"column:from_nick"`   // 消息来源昵称,群消息为群昵称,私聊消息为发送者昵称
	SenderWxId string    `gorm:"column:sender_wxid"` // 消息具体发送者wxid
	SenderNick string    `gorm:"column:sender_nick"` // 消息具体发送者昵称
	Content    string    `gorm:"column:content"`     // 消息内容
	CreatedAt  time.Time `gorm:"column:created_at"`  // 创建时间
}

MessageRecord 消息记录表

type Rule

type Rule func(ctx *Ctx) bool // 用于过滤事件

func CommandRule

func CommandRule(commands ...string) Rule

CommandRule 检查消息是否为命令

func FullMatchRule

func FullMatchRule(src ...string) Rule

FullMatchRule 检查消息是否完全匹配

func KeywordRule

func KeywordRule(src ...string) Rule

KeywordRule 检查消息是否包含关键字

func PrefixRule

func PrefixRule(prefixes ...string) Rule

PrefixRule 检查消息前缀

func RegexRule

func RegexRule(regexPattern string) Rule

RegexRule 检查消息是否匹配正则表达式

func SuffixRule

func SuffixRule(suffixes ...string) Rule

SuffixRule 检查消息后缀

type Self added in v1.2.0

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

Self 包装了关于bot、好友、群组、公众号的操作

func (*Self) CheckUserObjNil added in v1.2.0

func (s *Self) CheckUserObjNil() bool

CheckUserObjNil 检查好友、群、公众号列表是否为空

func (*Self) Friends added in v1.2.0

func (s *Self) Friends(update ...bool) (Friends, error)

Friends 获取所有的好友

func (*Self) GroupMembers added in v1.2.7

func (s *Self) GroupMembers(groupWxId string, update ...bool) (GroupMembers, error)

GroupMembers 获取所有的群成员

func (*Self) Groups added in v1.2.0

func (s *Self) Groups(update ...bool) (Groups, error)

Groups 获取所有的群组

func (*Self) Init added in v1.2.0

func (s *Self) Init() error

Init 初始化获取好友、群、公众号列表

func (*Self) MPs added in v1.2.0

func (s *Self) MPs(update ...bool) (MPs, error)

MPs 获取所有的公众号

type State

type State map[string]interface{}

State 用来存储匹配器的上下文

type Transfer added in v1.0.10

type Transfer struct {
	FromWxId     string // 发送者微信ID
	MsgSource    int64  // 消息来源 1:收到转账 2:对方接收转账 3:发出转账 4:自己接收转账 5:对方退还 6:自己退还
	TransferType int64  // 转账类型 1:即时到账 2:延时到账
	Money        string // 转账金额,单位元
	Memo         string // 转账备注
	TransferId   string // 转账ID
	TransferTime string // 转账时间,10位时间戳
}

Transfer 记录转账消息的具体内容

type User added in v1.2.0

type User struct {
	WxId                    string `json:"wxId"`                    // 微信ID
	WxNum                   string `json:"wxNum"`                   // 微信号
	Nick                    string `json:"nick"`                    // 昵称
	Remark                  string `json:"remark"`                  // 备注
	NickBrief               string `json:"nickBrief"`               // 昵称简拼
	NickWhole               string `json:"nickWhole"`               // 昵称全拼
	RemarkBrief             string `json:"remarkBrief"`             // 备注简拼
	RemarkWhole             string `json:"remarkWhole"`             // 备注全拼
	EnBrief                 string `json:"enBrief"`                 // 英文简拼
	EnWhole                 string `json:"enWhole"`                 // 英文全拼
	V3                      string `json:"v3"`                      // v3数据,同意好友验证时需要
	V4                      string `json:"v4"`                      // v4数据,同意好友验证时需要
	Sign                    string `json:"sign"`                    // 签名,需要在会话列表中
	Country                 string `json:"country"`                 // 国家,需要在会话列表中
	Province                string `json:"province"`                // 省份,需要在会话列表中
	City                    string `json:"city"`                    // 城市,需要在会话列表中
	MomentsBackgroundImgUrl string `json:"momentsBackgroundImgUrl"` // 朋友圈背景图,需要在朋友圈中
	AvatarMinUrl            string `json:"avatarMinUrl"`            // 头像小图,需要在会话列表中
	AvatarMaxUrl            string `json:"avatarMaxUrl"`            // 头像大图,需要在会话列表中
	Sex                     string `json:"sex"`                     // 性别,1男,2女,0未知
	MemberNum               int    `json:"memberNum"`               // 群成员数量,仅当对象是群聊时有效
	// contains filtered or unexported fields
}

User 抽象用户对象,对象可以是好友、群组、公众号

func (*User) AsFriend added in v1.2.7

func (u *User) AsFriend() (*Friend, bool)

AsFriend 将当前对象转换为好友对象

func (*User) AsGroup added in v1.2.7

func (u *User) AsGroup() (*Group, bool)

AsGroup 将当前对象转换为群聊对象

func (*User) AsMP added in v1.2.7

func (u *User) AsMP() (*MP, bool)

AsMP 将当前对象转换为公众号对象

func (*User) IsFriend added in v1.2.7

func (u *User) IsFriend() bool

IsFriend 判断当前对象是否是好友

func (*User) IsGroup added in v1.2.7

func (u *User) IsGroup() bool

IsGroup 判断当前对象是否是群聊

func (*User) IsMP added in v1.2.7

func (u *User) IsMP() bool

IsMP 判断当前对象是否是公众号

func (*User) MustAsFriend added in v1.2.7

func (u *User) MustAsFriend() *Friend

MustAsFriend 转换为好友对象,Must表示确定当前对象一定是好友对象,如果不是可能会出错

func (*User) MustAsGroup added in v1.2.7

func (u *User) MustAsGroup() *Group

MustAsGroup 转换为群聊对象,Must表示确定当前对象一定是群聊对象,如果不是可能会出错

func (*User) MustAsMP added in v1.2.7

func (u *User) MustAsMP() *MP

MustAsMP 转换为公众号对象,Must表示确定当前对象一定是公众号对象,如果不是可能会出错

type Withdraw added in v1.0.10

type Withdraw struct {
	FromType  int64  // 消息来源 1:私聊 2:群聊
	FromGroup string // 消息来源群ID
	FromWxId  string // 消息来源微信ID
	MsgSource int64  // 消息来源 1:别人撤回 2:自己使用手机撤回 3:自己使用电脑撤回
	Msg       string // 消息内容
}

Withdraw 记录撤回消息的具体内容

Jump to

Keyboard shortcuts

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