CoralBot

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: AGPL-3.0 Imports: 15 Imported by: 1

README

CoralBot

概述

基于基于go-cqhttp的后端开发库

快速开始

要求
  • go 1.18以上
安装
$ go get -u github.com/BoyChai/CoralBot
使用

使用之前需开启go-cqhttp并且指定http事件主机为本程序主机和端口,之后,创建一个名为example.go

$ touch example.go

接下来,将以下代码放入example.go

package main

import (
	coral "github.com/BoyChai/CoralBot"
)

func main() {
	var e coral.Event
	h := coral.Handle{
		Host:      "127.0.0.1:5700",
		Agreement: "http",
	}
	c1 := []coral.Condition{{
		Key:   &e.Message,
		Value: "hello",
		Regex: true,
	}, {
		Key:   &e.GroupID,
		Value: "<你的QQ群号>",
	}}
	coral.NewTask(coral.Task{
		Condition: c1,
		Run: func() {
			h.Reply(e, coral.Msg{
				Message: "你好",
			})
		},
	})
	coral.RunCoralBot(":8080", &e)
}

您可以通过以下方式运行代码go run example.go,运行之后可以发送hello即可收到回复。效果如下:

效果

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Tasks []Task

Functions

func NewPluginTask added in v0.3.0

func NewPluginTask(task Task)

NewPluginTask 创建一个插件动作

func NewTask

func NewTask(task Task)

NewTask 创建一个动作

func RunCoralBot

func RunCoralBot(port string, e *Event)

Types

type ChannelInfo added in v0.2.0

type ChannelInfo struct {
	OwnerGuildID    string `json:"owner_guild_id"`
	ChannelID       string `json:"channel_id"`
	ChannelType     int32  `json:"channel_type"`
	ChannelName     string `json:"channel_name"`
	CreateTime      int64  `json:"create_time"`
	CreatorTinyID   string `json:"creator_tiny_id"`
	TalkPermission  int32  `json:"talk_permission"`
	VisibleType     int32  `json:"visible_type"`
	CurrentSlowMode int32  `json:"current_slow_mode"`
	SlowModes       []struct {
		SlowModeKey    int32  `json:"slow_mode_key"`
		SlowModeText   string `json:"slow_mode_text"`
		SpeakFrequency int32  `json:"speak_frequency"`
		SlowModeCircle int32  `json:"slow_mode_circle"`
	} `json:"slow_modes"`
}

ChannelInfo 频道信息

type Condition

type Condition struct {
	Key   interface{}
	Value string
	Regex bool
}

Condition 触发条件

type Event

type Event struct {
	//https://docs.go-cqhttp.org/event/
	//bodyData    []byte
	PostType    string `json:"post_type"`
	RequestType string `json:"request_type"`
	MessageType string `json:"message_type"`
	Time        int64  `json:"time"`
	SelfID      int64  `json:"self_id"`
	SubType     string `json:"sub_type"`
	RawMessage  string `json:"raw_message"`
	Font        int32  `json:"font"`
	TempSource  int64  `json:"temp_source"`
	Sender      struct {
		Age      int32  `json:"age"`
		Nickname string `json:"nickname"`
		Sex      string `json:"sex"`
		UserID   int64  `json:"user_id"`
		Area     string `json:"area"`
		Card     string `json:"card"`
		Level    string `json:"level"`
		Role     string `json:"role"`
		Title    string `json:"title"`
		//频道
		TinyID string `json:"tiny_id"`
	} `json:"sender"`
	Anonymous struct {
		ID   int64  `json:"id"`
		Name string `json:"name"`
		Flag string `json:"flag"`
	} `json:"anonymous"`
	GroupID        int64  `json:"group_id"`
	Message        string `json:"message"`
	MessageSeq     int    `json:"message_seq"`
	UserID         int64  `json:"user_id"`
	GuildUserID    string `json:"guild_user_id"`
	MessageID      int32  `json:"message_id"`
	GuildMessageID string `json:"guild_message_id"`
	NoticeType     string `json:"notice_type"`
	MetaEventType  string `json:"meta_event_type"`
	File           struct {
		BusID int64  `json:"busid"`
		ID    string `json:"id"`
		Name  string `json:"name"`
		Size  int64  `json:"size"`
		URL   string `json:"url"`
	} `json:"file"`
	OperatorID int64  `json:"operator_id"`
	Duration   int64  `json:"duration"`
	SenderID   int64  `json:"sender_id"`
	TargetID   int64  `json:"target_id"`
	HonorType  string `json:"honor_type"`
	CardNew    string `json:"card_new"`
	CardOld    string `json:"card_old"`
	Comment    string `json:"comment"`
	Flag       string `json:"flag"`
	Client     struct {
		AppID      int64  `json:"app_id"`
		DeviceName string `json:"device_name"`
		DeviceKind string `json:"device_kind"`
	} `json:"client"`
	Online bool `json:"online"`
	//频道
	GuildID          string `json:"guild_id"`
	ChannelID        string `json:"channel_id"`
	CurrentReactions []struct {
		EmojiID    string `json:"emoji_id"`
		EmojiIndex int32  `json:"emoji_index"`
		EmojiType  int32  `json:"emoji_type"`
		EmojiName  string `json:"emoji_name"`
		Count      int32  `json:"count"`
		Clicked    bool   `json:"clicked"`
	} `json:"current_reactions"`
	OldInfo     ChannelInfo `json:"old_info"`
	NewInfo     ChannelInfo `json:"new_info"`
	ChannelInfo ChannelInfo `json:"channel_info"`
	Other       Other
}

Event 消息全部信息

type Handle

type Handle struct {
	Host      string
	Agreement string
}

func (Handle) CanSendImage

func (h Handle) CanSendImage() (map[string]interface{}, error)

CanSendImage 检查是否可以发送图片

func (Handle) CanSendRecord

func (h Handle) CanSendRecord() (map[string]interface{}, error)

CanSendRecord 检查是否可以发送语音

func (Handle) CheckUrlSafely

func (h Handle) CheckUrlSafely(u string) (map[string]interface{}, error)

CheckUrlSafely 检查链接安全性

func (Handle) CleanCache

func (h Handle) CleanCache() (map[string]interface{}, error)

CleanCache 清理缓存

func (Handle) CreateGroupFileFolder

func (h Handle) CreateGroupFileFolder(groupId int64, name string, parentId string) (map[string]interface{}, error)

CreateGroupFileFolder 创建群文件文件夹

func (Handle) CreateGuildRole added in v0.2.0

func (h Handle) CreateGuildRole(guildID string, name string, color string, independent bool, initialUsers string) (map[string]interface{}, error)

CreateGuildRole 创建频道角色

func (Handle) DeleteEssenceMsg

func (h Handle) DeleteEssenceMsg(messageId int32) (map[string]interface{}, error)

DeleteEssenceMsg 移除精华消息

func (Handle) DeleteFriend

func (h Handle) DeleteFriend(friendId int64) (map[string]interface{}, error)

DeleteFriend 删除好友

func (Handle) DeleteGroupFile

func (h Handle) DeleteGroupFile(groupId int64, fileId string, busId int32) (map[string]interface{}, error)

DeleteGroupFile 删除群文件

func (Handle) DeleteGroupFolder

func (h Handle) DeleteGroupFolder(groupId int64, folderId string) (map[string]interface{}, error)

DeleteGroupFolder 删除群文件夹

func (Handle) DeleteGuildRole added in v0.2.0

func (h Handle) DeleteGuildRole(guildID string, roleID string) (map[string]interface{}, error)

DeleteGuildRole 删除频道角色

func (Handle) DeleteMsg

func (h Handle) DeleteMsg(messageId int32) (map[string]interface{}, error)

DeleteMsg 撤回消息

func (Handle) DownloadFile

func (h Handle) DownloadFile(fileUrl string, threadCount int32, headers string) (map[string]interface{}, error)

DownloadFile 下载文件到缓存目录

func (Handle) GetCookies

func (h Handle) GetCookies(domain string) (map[string]interface{}, error)

GetCookies 获取 Cookies 该 API 暂未被 go-cqhttp 支持, 您可以提交 pr 以使该 API 被支持 提交 pr

func (Handle) GetCredentials

func (h Handle) GetCredentials(domain string) (map[string]interface{}, error)

GetCredentials 获取 QQ 相关接口凭证 该 API 暂未被 go-cqhttp 支持, 您可以提交 pr 以使该 API 被支持 提交 pr 即GetCookies和GetCsrfToken两个接口的合并

func (Handle) GetCsrfToken

func (h Handle) GetCsrfToken() (map[string]interface{}, error)

GetCsrfToken 获取 CSRF Token 该 API 暂未被 go-cqhttp 支持, 您可以提交 pr 以使该 API 被支持 提交 pr

func (Handle) GetEssenceMsgList

func (h Handle) GetEssenceMsgList(groupId int64) (map[string]interface{}, error)

GetEssenceMsgList 获取精华消息列表

func (Handle) GetForwardMsg

func (h Handle) GetForwardMsg(messageId int32) (map[string]interface{}, error)

GetForwardMsg 获取合并转发内容

func (Handle) GetFriendList

func (h Handle) GetFriendList() (map[string]interface{}, error)

GetFriendList 获取好友列表

func (Handle) GetGroupAtAllRemain

func (h Handle) GetGroupAtAllRemain(groupId int64) (map[string]interface{}, error)

GetGroupAtAllRemain 获取群@全体成员剩余次数

func (Handle) GetGroupFileSystemInfo

func (h Handle) GetGroupFileSystemInfo(groupId int64) (map[string]interface{}, error)

GetGroupFileSystemInfo 获取群文件系统信息

func (Handle) GetGroupFileUrl

func (h Handle) GetGroupFileUrl(groupId int64, fileId string, busId int32) (map[string]interface{}, error)

GetGroupFileUrl 获取群文件资源链接

func (Handle) GetGroupFilesByFolder

func (h Handle) GetGroupFilesByFolder(groupId int64, folderId string) (map[string]interface{}, error)

GetGroupFilesByFolder 获取群子目录文件列表

func (Handle) GetGroupHonorInfo

func (h Handle) GetGroupHonorInfo(groupId int64, typ string) (map[string]interface{}, error)

GetGroupHonorInfo 获取群荣誉信息

func (Handle) GetGroupInfo

func (h Handle) GetGroupInfo(groupId int64, noCache bool) (map[string]interface{}, error)

GetGroupInfo 获取群信息

func (Handle) GetGroupList

func (h Handle) GetGroupList() (map[string]interface{}, error)

GetGroupList 获取群列表

func (Handle) GetGroupMemberInfo

func (h Handle) GetGroupMemberInfo(groupId int64, userId int64, noCache bool) (map[string]interface{}, error)

GetGroupMemberInfo 获取群成员信息

func (Handle) GetGroupMemberList

func (h Handle) GetGroupMemberList(groupId int64) (map[string]interface{}, error)

GetGroupMemberList 获取群成员列表

func (Handle) GetGroupMsgHistory

func (h Handle) GetGroupMsgHistory(messageSeq int64, groupId int64) (map[string]interface{}, error)

GetGroupMsgHistory 获取群消息历史记录

func (Handle) GetGroupNotice

func (h Handle) GetGroupNotice(groupId int64) (map[string]interface{}, error)

GetGroupNotice 获取群公告

func (Handle) GetGroupRootFiles

func (h Handle) GetGroupRootFiles(groupId int64) (map[string]interface{}, error)

GetGroupRootFiles 获取群根目录文件列表

func (Handle) GetGroupSystemMsg

func (h Handle) GetGroupSystemMsg() (map[string]interface{}, error)

GetGroupSystemMsg 获取群系统消息 如果列表不存在任何消息, 将返回 null

func (Handle) GetGuildChannelList added in v0.2.0

func (h Handle) GetGuildChannelList(guildID string, noCache bool) (map[string]interface{}, error)

GetGuildChannelList 获取子频道列表

func (Handle) GetGuildList added in v0.2.0

func (h Handle) GetGuildList() (map[string]interface{}, error)

GetGuildList 获取频道列表

func (Handle) GetGuildMemberList added in v0.2.0

func (h Handle) GetGuildMemberList(guildID string, nextToken string) (map[string]interface{}, error)

GetGuildMemberList 获取频道成员列表

func (Handle) GetGuildMemberProfile added in v0.2.0

func (h Handle) GetGuildMemberProfile(guildID string, userID string) (map[string]interface{}, error)

GetGuildMemberProfile 单独获取频道成员信息

func (Handle) GetGuildMetaByGuest added in v0.2.0

func (h Handle) GetGuildMetaByGuest(guildID string) (map[string]interface{}, error)

GetGuildMetaByGuest 通过访客获取频道元数据

func (Handle) GetGuildMsg added in v0.2.0

func (h Handle) GetGuildMsg(messageID string, noCache bool) (map[string]interface{}, error)

GetGuildMsg 获取频道消息

func (Handle) GetGuildRoles added in v0.2.0

func (h Handle) GetGuildRoles(guildID string) (map[string]interface{}, error)

GetGuildRoles 获取频道角色列表

func (Handle) GetGuildServiceProfile added in v0.2.0

func (h Handle) GetGuildServiceProfile() (map[string]interface{}, error)

GetGuildServiceProfile 获取频道系统内BOT的资料

func (Handle) GetImage

func (h Handle) GetImage(file string) (map[string]interface{}, error)

GetImage 获取图片信息

func (Handle) GetLoginInfo

func (h Handle) GetLoginInfo() (map[string]interface{}, error)

GetLoginInfo 获取登录号信息

func (Handle) GetModelShow

func (h Handle) GetModelShow(model string) (map[string]interface{}, error)

GetModelShow 获取在线机型

func (Handle) GetMsg

func (h Handle) GetMsg(messageId int32) (map[string]interface{}, error)

GetMsg 获取消息

func (Handle) GetOnlineClients

func (h Handle) GetOnlineClients(noCache bool) (map[string]interface{}, error)

GetOnlineClients 获取当前账号在线客户端列表

func (Handle) GetRecord

func (h Handle) GetRecord(file string, outFormat string) (map[string]interface{}, error)

GetRecord 获取语音 该 API 暂未被 go-cqhttp 支持, 您可以提交 pr 以使该 API 被支持 提交 pr 要使用此接口, 通常需要安装 ffmpeg, 请参考 OneBot 实现的相关说明。

func (Handle) GetStatus

func (h Handle) GetStatus() (map[string]interface{}, error)

GetStatus 获取状态

func (Handle) GetStrangerInfo

func (h Handle) GetStrangerInfo(userId int64, noCache bool) (map[string]interface{}, error)

GetStrangerInfo 获取陌生人信息

func (Handle) GetTopicChannelFeeds added in v0.2.0

func (h Handle) GetTopicChannelFeeds(guildID string, channelID string) (map[string]interface{}, error)

GetTopicChannelFeeds 获取话题频道帖子

func (Handle) GetUnidirectionalFriendList

func (h Handle) GetUnidirectionalFriendList() (map[string]interface{}, error)

GetUnidirectionalFriendList 获取单向好友列表

func (Handle) GetVersionInfo

func (h Handle) GetVersionInfo() (map[string]interface{}, error)

GetVersionInfo 获取版本信息

func (Handle) MarkMsgAsRead

func (h Handle) MarkMsgAsRead(messageId int32) (map[string]interface{}, error)

MarkMsgAsRead 标记消息已读

func (Handle) OcrImage

func (h Handle) OcrImage(image string) (map[string]interface{}, error)

OcrImage 图片 OCR 目前图片OCR接口仅支持接受的图片

func (Handle) QiDianGetAccountInfo

func (h Handle) QiDianGetAccountInfo() (map[string]interface{}, error)

QiDianGetAccountInfo 获取企点账号信息 该API只有企点协议可用

func (Handle) ReloadEventFilter

func (h Handle) ReloadEventFilter(file string) (map[string]interface{}, error)

ReloadEventFilter 重载事件过滤器

func (Handle) Reply added in v0.3.0

func (h Handle) Reply(e Event, m Msg) (map[string]interface{}, error)

Reply 快速回复

func (Handle) SendGroupMsg

func (h Handle) SendGroupMsg(m Msg) (map[string]interface{}, error)

SendGroupMsg 发送群聊消息 func (h Handle) SendGroupMsg(groupId int64, message string, autoEscape string) (map[string]interface{}, error) {

func (Handle) SendGroupNotice

func (h Handle) SendGroupNotice(groupId int64, content string, image string) (map[string]interface{}, error)

SendGroupNotice 发送群公告

func (Handle) SendGroupSign

func (h Handle) SendGroupSign(groupId int64) (map[string]interface{}, error)

SendGroupSign 群打卡

func (Handle) SendGuildChannelMsg added in v0.2.0

func (h Handle) SendGuildChannelMsg(guildID string, channelID string, message string) (map[string]interface{}, error)

SendGuildChannelMsg 发送信息到子频道

func (Handle) SendMsg

func (h Handle) SendMsg(m Msg) (map[string]interface{}, error)

SendMsg 发送消息 func (h Handle) SendMsg(userId int64, groupId int64, message string, autoEscape string) (map[string]interface{}, error) {

func (Handle) SendPrivateMsg

func (h Handle) SendPrivateMsg(m Msg) (map[string]interface{}, error)

SendPrivateMsg 发送私聊消息

func (Handle) SetEssenceMsg

func (h Handle) SetEssenceMsg(messageId int32) (map[string]interface{}, error)

SetEssenceMsg 设置精华消息

func (Handle) SetFriendAddRequest

func (h Handle) SetFriendAddRequest(flag string, approve bool, remark string) (map[string]interface{}, error)

SetFriendAddRequest 处理加好友请求

func (Handle) SetGroupAddRequest

func (h Handle) SetGroupAddRequest(flag string, subType string, approve bool, reason string) (map[string]interface{}, error)

SetGroupAddRequest 处理加群请求/邀请

func (Handle) SetGroupAdmin

func (h Handle) SetGroupAdmin(groupId int64, userId int64, enable bool) (map[string]interface{}, error)

SetGroupAdmin 群组设置管理员

func (Handle) SetGroupAnonymous

func (h Handle) SetGroupAnonymous(groupId int64, enable bool) (map[string]interface{}, error)

SetGroupAnonymous 群组匿名

func (Handle) SetGroupAnonymousBan

func (h Handle) SetGroupAnonymousBan(groupId int64, flag string, duration string) (map[string]interface{}, error)

SetGroupAnonymousBan 群组匿名用户禁言

func (Handle) SetGroupBan

func (h Handle) SetGroupBan(groupId int64, userId int64, duration string) (map[string]interface{}, error)

SetGroupBan 群组单人禁言

func (Handle) SetGroupKick

func (h Handle) SetGroupKick(groupId int64, userId int64, rejectAddRequest bool) (map[string]interface{}, error)

SetGroupKick 群组踢人

func (Handle) SetGroupLeave

func (h Handle) SetGroupLeave(groupId int64, isDismiss bool) (map[string]interface{}, error)

SetGroupLeave 退出群聊

func (Handle) SetGroupName

func (h Handle) SetGroupName(groupId int64, groupName string) (map[string]interface{}, error)

SetGroupName 修改群聊名称

func (Handle) SetGroupPortrait

func (h Handle) SetGroupPortrait(groupId int64, file string, cache int) (map[string]interface{}, error)

SetGroupPortrait 设置群头像 目前这个API在登录一段时间后因cookie失效而失效, 请考虑后使用

func (Handle) SetGroupSpecialTitle

func (h Handle) SetGroupSpecialTitle(groupId int64, userId int64, specialTitle string, duration string) (map[string]interface{}, error)

SetGroupSpecialTitle 设置群组专属头衔

func (Handle) SetGroupWholeBan

func (h Handle) SetGroupWholeBan(groupId int64, enable bool) (map[string]interface{}, error)

SetGroupWholeBan 群组全员禁言

func (Handle) SetGuildMemberRole added in v0.2.0

func (h Handle) SetGuildMemberRole(guildID string, set bool, roleID string, users string) (map[string]interface{}, error)

SetGuildMemberRole 设置用户在频道中的角色

func (Handle) SetModelShow

func (h Handle) SetModelShow(model string, modelShow string) (map[string]interface{}, error)

SetModelShow 设置在线机型

func (Handle) SetQQProfile

func (h Handle) SetQQProfile(p Profile) (map[string]interface{}, error)

SetQQProfile 设置登录号资料

func (Handle) SetRestart

func (h Handle) SetRestart(delay int) (map[string]interface{}, error)

SetRestart 重启 go-cqhttp

func (Handle) UpdateGuildRole added in v0.2.0

func (h Handle) UpdateGuildRole(guildID string, roleID string, name string, color string, indepedent bool) (map[string]interface{}, error)

UpdateGuildRole 设置用户在频道中的角色

func (Handle) UploadGroupFile

func (h Handle) UploadGroupFile(groupId int64, file string, name string, folder string) (map[string]interface{}, error)

UploadGroupFile 上传群文件

func (Handle) UploadPrivateFile

func (h Handle) UploadPrivateFile(userId int64, file string, name string) (map[string]interface{}, error)

UploadPrivateFile 上传私聊文件

type Msg

type Msg struct {
	UserId     int64
	GroupId    int64
	Message    string
	AutoEscape bool
}

type Other added in v0.3.1

type Other struct {
	// 运行插件
	RunName string
}

Other 其他

type PluginInfo added in v0.3.0

type PluginInfo struct {
	// 插件名称
	Name string
	// 插件简介
	Summary string
	// 插件版本
	Version string
	// 插件开发者
	Developer string
	// 插件开发者邮箱
	Email string
}

PluginInfo 插件信息

type PluginTool added in v0.3.0

type PluginTool struct {
	H *Handle
	E *Event
}

type Profile

type Profile struct {
	Nickname     string
	Company      string
	Email        string
	College      string
	PersonalNote string
}

Profile 账号资料

type Task

type Task struct {
	Condition []Condition
	Run       func()

	RunName string
	// contains filtered or unexported fields
}

Task 创建一个任务

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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