cqp

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package cqp 是用于编写酷Q插件的包,酷Q是一个QQ机器人软件。

Usage 用法

通过导入本包,再使用特定的编译命令即可将go代码编译成dll,就可以作为插件被酷Q加载。 为了编译成一个dll,你的代码里需要一个空的main函数。 然后编写init函数,设置你的插件的AppID。

package main

import "github.com/Tnze/CoolQ-Golang-SDK/cqp"

func main() {}
func init() {
	// 设置AppID
	cqp.AppID = "your.app.id"
	// 注册事件
	cqp.Enable = Enable
}

func Enable(){
	// 当插件启用时被调用
}

Build 编译

当写完基本的代码之后可以将它编译成dll。 插件的编译需要在windows环境下进行, 需要go和gcc两种编译工具来分别编译go代码和c代码。 请检查你的go和gcc是否都安装完成:

go version
gcc --version

其中go工具可以从https://golang.google.cn 下载 没有gcc可以安装TDM-GCC http://tdm-gcc.tdragon.net/

编译时需要设置几个环境变量:

CGO_LDFLAGS=-Wl,--kill-at
CGO_ENABLED=1
GOOS=windows
GOARCH=386

然后执行编译命令:

go build -ldflags "-s -w" -buildmode=c-shared -o app.dll

若成功编译则会生成app.dll,将其和app.json一起复制到酷Q的指定文件夹内即可

函数调用顺序说明

API调用顺序:用户代码 -> Go函数 -> C函数 -> 酷Q函数指针
例:           -> AddLog() -> CQ_addLog() -> CQ_addLog_Ptr

Event调用顺序:酷Q -> C函数 -> Go导出函数 -> Go函数
例:           -> EVENT_ON_ENABLE() -> _on_enable() -> Enable()

Index

Constants

View Source
const (
	Debug       Priority = 0
	Info                 = 10
	InfoSuccess          = 11
	InfoRecv             = 12
	InfoSend             = 13
	Warning              = 20
	Error                = 30
	Fatal                = 40
)

Log优先级(priority, AddLog的第一个参数)

Variables

View Source
var AppID string

AppID 插件的AppID。 务必在init函数内为这个变量赋值,酷Q加载插件时会读取这个值。 为了保证其唯一性,酷Q定义了AppID的规则,即开发者域名反写.应用英文名。 AppID中仅允许数字、字母、短横线(-)、下划线(_)、点(.), 不允许出现其他字符(如空格等),同时其中域名反写部分的字母全部统一使用小写字母。

View Source
var Disable func() int32

Disable 在插件禁用时被调用

View Source
var DiscussMsg func(subType, msgID int32, fromDiscuss, fromQQ int64, msg string, font int32) int32
View Source
var Enable func() int32

Enable 在插件启动时被调用

View Source
var Exit func() int32
View Source
var FriendAdd func(subType, sendTime int32, fromQQ int64) int32
View Source
var FriendRequest func(subType, sendTime int32, fromQQ int64, msg, responseFlag string) int32
View Source
var GroupAdmin func(subType, sendTime int32, fromGroup, QQ int64) int32
View Source
var GroupMemberDecrease func(subType, sendTime int32, fromGroup, fromQQ, beingOperateQQ int64) int32
View Source
var GroupMemberIncrease func(subType, sendTime int32, fromGroup, fromQQ, beingOperateQQ int64) int32
View Source
var GroupMsg func(subType, msgID int32, fromGroup, fromQQ int64, fromAnonymous, msg string, font int32) int32

GroupMsg 在收到群聊消息时被调用 subType目前固定为1

View Source
var GroupRequest func(subType, sendTime int32, fromGroup, fromQQ int64, msg, responseFlag string) int32
View Source
var GroupUpload func(subType, sendTime int32, fromGroup, fromQQ int64, file string) int32
View Source
var PrivateMsg func(subType, msgID int32, fromQQ int64, msg string, font int32) int32

PrivateMsg 在收到私聊消息时被调用。 subType为子类型,可选的值有,11:来自好友 1:来自在线状态 2:来自群 3:来自讨论组。 若返回非0值,消息将被拦截,最高优先不可拦截。

View Source
var Start func() int32

Functions

func AddLog

func AddLog(p Priority, logType, reason string) int32

AddLog 增加运行日志

priority 是Log的优先级,请使用cqp预定义好的值。
logType 是日志类型,酷Q日志窗口将将其显示在日志本身的前一列。
reason 是日志内容

func CanSendImage

func CanSendImage() bool

CanSendImage 能否发送图片

func CanSendRecord

func CanSendRecord() bool

CanSendRecord 能否发送语音

func DeleteMsg

func DeleteMsg(msgID int64) int32

DeleteMsg 撤回消息

func GetAppDir

func GetAppDir() string

GetAppDir 取应用目录 返回的路径末尾带"\",一般用法如下,所以不用关心是否有斜线

os.Open(filepath.Join(cqp.GetAppDir(), "data.db"))

func GetCSRFToken

func GetCSRFToken() int32

GetCSRFToken 获取CSRF Token

需要严格授权

func GetCookies

func GetCookies() string

GetCookies 获取cookies

需要严格授权

func GetCookiesV2

func GetCookiesV2(domain string) string

GetCookiesV2 获取cookies V2

需要严格授权

func GetImage

func GetImage(file string) string

GetImage 获取图片 参数为CQ码内容,返回值为图片的文件路径

func GetLoginNick

func GetLoginNick() string

GetLoginNick 获取登录号昵称

func GetLoginQQ

func GetLoginQQ() int64

GetLoginQQ 获取登陆号QQ

func GetRecord

func GetRecord(file, format string) string

GetRecord 获取语音 file参数为CQ码内容,format为插件所需格式,返回值应该是文件路径

需要严格授权

func GetRecordV2

func GetRecordV2(file, format string) string

GetRecordV2 获取语音 应该同GetRecord

需要严格授权

func GetStrangerInfo

func GetStrangerInfo(qq int64, noCatch bool) string

GetStrangerInfo 获取陌生人信息 noCatch指定是否使用缓存

func SendDiscussMsg

func SendDiscussMsg(discuss int64, msg string) int32

SendDiscussMsg 发送讨论组消息

func SendGroupMsg

func SendGroupMsg(group int64, msg string) int32

SendGroupMsg 发送群消息

func SendLike

func SendLike(qq int64) int32

SendLike 发送赞

func SendLike2

func SendLike2(qq int64, times int32) int32

SendLike2 发送赞2 times指定赞的次数

func SendPrivateMsg

func SendPrivateMsg(qq int64, msg string) int32

SendPrivateMsg 发送私聊消息

func SetDiscussLeave

func SetDiscussLeave(discuss int64) int32

SetDiscussLeave 退出讨论组

func SetFriendAddRequest

func SetFriendAddRequest(ReqFeedback string, FeedbackType int32, remark string) int32

SetFriendAddRequest 响应好友申请 ReqFeedback 请传入好友请求事件(FriendRequest)中收到的responseFlag。 FeedbackType 是否同意请求,同意:1,拒绝:2。 remark 好友备注

func SetGroupAddRequest

func SetGroupAddRequest(ReqFeedback string, ReqType, FeedbackType int32) int32

func SetGroupAddRequest2

func SetGroupAddRequest2(ReqFeedback string, ReqType, FeedbackType int32, reason string) int32

func SetGroupAdmin

func SetGroupAdmin(group, qq int64, admin bool) int32

SetGroupAdmin 设置群管理员

func SetGroupAnonymous

func SetGroupAnonymous(group int64, anonymous bool) int32

SetGroupAnonymous 设置群匿名是否开启

func SetGroupAnonymousBan

func SetGroupAnonymousBan(group int64, anonymous string, time int64) int32

SetGroupAnonymousBan 设置群匿名成员禁言

func SetGroupBan

func SetGroupBan(group, qq, bantime int64) int32

SetGroupBan 设置群成员禁言

func SetGroupCard

func SetGroupCard(group, qq int64, card string) int32

SetGroupCard 设置群成员名片

func SetGroupKick

func SetGroupKick(group, qq int64, rej bool) int32

SetGroupKick 将群成员踢出群聊

func SetGroupLeave

func SetGroupLeave(group int64, dissolve bool) int32

SetGroupLeave 退出群聊

func SetGroupSpecialTitle

func SetGroupSpecialTitle(group, qq int64, title string, timeout int64) int32

SetGroupSpecialTitle 设置群成员头衔

func SetGroupWholeBan

func SetGroupWholeBan(group int64, ban bool) int32

SetGroupWholeBan 设置全员禁言

func SetRestart

func SetRestart() int32

SetRestart 未知函数,请不要调用

Types

type FriendInfo

type FriendInfo struct {
	QQ    int64
	Name  string
	Alias string
}

func GetFriendList

func GetFriendList() []FriendInfo

GetFriendList 获取好友列表

func UnpackFriendList

func UnpackFriendList(str string) ([]FriendInfo, error)

UnpackFriendList 解码好友列表

type GroupDetail

type GroupDetail struct {
	GroupInfo
	MembersNum   int32
	MaxMemberNum int32
}

func GetGroupInfo

func GetGroupInfo(group int64, noCatch bool) GroupDetail

func UnpackGroupInfo

func UnpackGroupInfo(str string) (g GroupDetail, err error)

UnpackGroupInfo 解码群信息

type GroupInfo

type GroupInfo struct {
	ID   int64
	Name string
}

func GetGroupList

func GetGroupList() []GroupInfo

GetGroupList 获取群列表

func UnpackGroupList

func UnpackGroupList(str string) ([]GroupInfo, error)

UnpackGroupList 解码群列表

type GroupMember

type GroupMember struct {
	//群号和Q号
	Group, QQ  int64
	Name, Card string
	//性别,0/男;1/女
	Gender             int32
	Age                int32
	Area               string
	JoinTime, LastChat time.Time
	Level              string
	//管理权限,1/成员;2/管理员;3/群主
	Auth int32
	//是否有不良记录
	Bad         bool
	Title       string
	TitleLife   time.Time
	CanSetTitle bool
}

GroupMember 群成员信息

func GetGroupMemberInfo

func GetGroupMemberInfo(group, qq int64, noCatch bool) GroupMember

GetGroupMemberInfo 获取群成员信息

func GetGroupMemberList

func GetGroupMemberList(group int64) []GroupMember

GetGroupMemberList 获取群成员列表

func UnpackGroupMemberInfo

func UnpackGroupMemberInfo(str string) (m GroupMember, err error)

UnpackGroupMemberInfo 解码群成员信息

func UnpackGroupMemberList

func UnpackGroupMemberList(str string) ([]GroupMember, error)

UnpackGroupMemberList 解码群成员列表

type Priority

type Priority int32

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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