Skip to content
This repository was archived by the owner on Mar 4, 2021. It is now read-only.

Commit 45ca82d

Browse files
committed
继续调整
1 parent d338153 commit 45ca82d

File tree

9 files changed

+103
-77
lines changed

9 files changed

+103
-77
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414

1515
# test
1616
test/
17+
.DS_Store

README.md

100644100755
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# CoolQ Golang SDK
2-
酷Q插件Go语言SDK
3-
4-
TODO list:
5-
- [x] 成功编译成dll
6-
- [x] 导出函数供酷Q调用
7-
- [ ] 调用酷Q提供的函数
1+
# CoolQ Golang SDK
2+
酷Q插件Go语言SDK
3+
4+
TODO list:
5+
- [x] 成功编译成dll
6+
- [x] 导出函数供酷Q调用
7+
- [ ] 调用酷Q提供的函数
88
- [ ] 编写使用文档

app.go

100644100755
+7-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
// 您的应用的代码写在这里
22
package main
33

4-
import "C"
4+
import "C"
5+
56
import (
7+
68
)
79

10+
//AppID 需要修改为你的插件的appid
811
const AppID = "your.app.id"
912

10-
//export Enable
13+
//Enable 在插件启动时被调用一次
1114
func Enable() int32 {
12-
code,err:=SendPrivateMsg(1624188026, "test")
13-
if err!=nil{
14-
15-
}
15+
AddLog(3000, "Debug", "res")
16+
1617
return 0
1718
}

app.h

100644100755
+24-16
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,31 @@
22

33
/* package _/C_/Users/lenovo/Desktop/酷Q_Air/dev/your.app.id */
44

5-
65
#line 1 "cgo-builtin-prolog"
76

87
#include <stddef.h> /* for ptrdiff_t below */
98

109
#ifndef GO_CGO_EXPORT_PROLOGUE_H
1110
#define GO_CGO_EXPORT_PROLOGUE_H
1211

13-
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
12+
typedef struct
13+
{
14+
const char *p;
15+
ptrdiff_t n;
16+
} _GoString_;
1417

1518
#endif
1619

1720
/* Start of preamble from import "C" comments. */
1821

19-
20-
2122
#line 3 "cq.go"
22-
#include <stdlib.h>
23-
#include "cq.h"
23+
#include <stdlib.h>
24+
#include "cq.h"
2425

2526
#line 1 "cgo-generated-wrapper"
2627

27-
2828
/* End of preamble from import "C" comments. */
2929

30-
3130
/* Start of boilerplate cgo prologue. */
3231
#line 1 "cgo-gcc-export-header-prolog"
3332

@@ -54,28 +53,37 @@ typedef double _Complex GoComplex128;
5453
static assertion to make sure the file is being used on architecture
5554
at least with matching size of GoInt.
5655
*/
57-
typedef char _check_for_32_bit_pointer_matching_GoInt[sizeof(void*)==32/8 ? 1:-1];
56+
typedef char _check_for_32_bit_pointer_matching_GoInt[sizeof(void *) == 32 / 8 ? 1 : -1];
5857

5958
typedef _GoString_ GoString;
6059
typedef void *GoMap;
6160
typedef void *GoChan;
62-
typedef struct { void *t; void *v; } GoInterface;
63-
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
61+
typedef struct
62+
{
63+
void *t;
64+
void *v;
65+
} GoInterface;
66+
typedef struct
67+
{
68+
void *data;
69+
GoInt len;
70+
GoInt cap;
71+
} GoSlice;
6472

6573
#endif
6674

6775
/* End of boilerplate cgo prologue. */
6876

6977
#ifdef __cplusplus
70-
extern "C" {
78+
extern "C"
79+
{
7180
#endif
7281

82+
extern GoInt32 Enable();
7383

74-
extern GoInt32 Enable();
75-
76-
extern char* AppInfo();
84+
extern char *appinfo();
7785

78-
extern GoInt32 Init(GoInt32 p0);
86+
extern GoInt32 Init(GoInt32 p0);
7987

8088
#ifdef __cplusplus
8189
}

app.json

100644100755
+24-23
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
{
2-
"ret": 1, // 返回码,固定为1
3-
"apiver": 9, // Api版本,本SDK为9
4-
"name": "GoCQ", // 应用名称
5-
"version": "1.0.0", // 应用版本
6-
"version_id": 1, // 应用顺序版本(每次发布时至少+1)
7-
"author": "Tnze", // 应用作者
8-
"description": "Golang酷Q样例应用(V9应用机制)",
9-
"event": [ // 事件列表,同一事件类型可重复定义(发布前请删除无用事件)
10-
{
11-
"name":"应用启动",
12-
"function":"Enable",
13-
"type":1003,
14-
"priority":30000,
15-
"id":1
16-
}
17-
],
18-
"menu": [ // 设置菜单(发布前请删除无用菜单,如果无需设置菜单请全部删除)
19-
],
20-
"status": [ // 悬浮窗状态(见 com.example.status 样例)
21-
],
22-
"auth": [ // 应用权限(发布前请删除无用权限)
23-
]
1+
{
2+
"ret": 1, // 返回码,固定为1
3+
"apiver": 9, // Api版本,本SDK为9
4+
"name": "GoCQ", // 应用名称
5+
"version": "1.0.0", // 应用版本
6+
"version_id": 1, // 应用顺序版本(每次发布时至少+1)
7+
"author": "Tnze", // 应用作者
8+
"description": "Golang酷Q样例应用(V9应用机制)",
9+
"event": [ // 事件列表,同一事件类型可重复定义(发布前请删除无用事件)
10+
{
11+
"name": "应用启动",
12+
"function": "on_Enable",
13+
"type": 1003,
14+
"priority": 30000,
15+
"id": 1
16+
}
17+
],
18+
"menu": [ // 设置菜单(发布前请删除无用菜单,如果无需设置菜单请全部删除)
19+
],
20+
"status": [ // 悬浮窗状态(见 com.example.status 样例)
21+
],
22+
"auth": [ // 应用权限(发布前请删除无用权限)
23+
106
24+
]
2425
}

build.bat

100644100755
File mode changed.

cq.c

100644100755
+22-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1+
#include <windows.h>
12
#include "app.h"
3+
#include "cq.h"
24

3-
extern int32_t __stdcall Initialize(int32_t p0) { return Init(p0); }
4-
extern int32_t __stdcall onEnable() {return Enable();}
5+
int32_t ac;
6+
CQEVENT Initialize(int32_t access_code)
7+
{
8+
ac = access_code;
9+
HMODULE hmod = LoadLibrary("CQP.dll");
10+
CQ_addLog_Ptr = GetProcAddress(hmod, "CQ_addLog");
11+
return 0;
12+
}
13+
14+
CQEVENT on_Enable() { return Enable(); }
15+
16+
//apis
17+
18+
int32_t CQ_addLog(GoInt32 priority, const char *type, const char *reason)
19+
{
20+
int32_t ret = CQ_addLog_Ptr(ac, priority, type, reason);
21+
free(type); //释放字符串内存
22+
free(reason);
23+
return ret;
24+
}

cq.go

100644100755
+8-19
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,21 @@ package main
55
import "C"
66
import (
77
"unsafe"
8-
"fmt"
98
)
109

1110
func main() {}
1211

13-
var AuthCode int32
1412
var info = C.CString("9," + AppID)
1513

16-
//export AppInfo
17-
func AppInfo() *C.char {
14+
//export appinfo
15+
func appinfo() *C.char {
1816
return info
1917
}
2018

21-
//export Init
22-
func Init(ac int32) int32 {
23-
AuthCode = ac
24-
return 0
19+
func AddLog(priority int32, logtype, reason string) int32 {
20+
return int32(C.CQ_addLog(
21+
priority,
22+
C.CString(logtype),
23+
C.CString(reason),
24+
))
2525
}
26-
27-
func SendPrivateMsg(qq int64, msg string) (int32, error) {
28-
str := C.CString(msg)
29-
code := int32(C.CQ_sendPrivateMsg(C.int32_t(AuthCode), C.int64_t(qq), str))
30-
C.free(unsafe.Pointer(str))
31-
32-
if code < 0 {
33-
return 0, fmt.Errorf("send private message error (%d)",code)
34-
}
35-
return code, nil
36-
}

cq.h

100644100755
+10-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#include <stdint.h>
2+
#include <stdlib.h>
3+
4+
#define CQEVENT extern int32_t __stdcall
5+
6+
#define CQAPI(RetType, Name, ...) \
7+
RetType(__stdcall *Name##_Ptr)(__VA_ARGS__); \
8+
RetType Name(__VA_ARGS__);
29

310
//events
4-
extern int32_t __stdcall Initialize(int32_t p0);
5-
extern int32_t __stdcall onEnable();
11+
CQEVENT Initialize(int32_t p0);
12+
CQEVENT on_Enable();
613

714
//apis
8-
extern int32_t __stdcall CQ_addLog(int32_t ac, int32_t priority, const char* type, const char* reason);
9-
extern int32_t __stdcall CQ_sendPrivateMsg(int32_t ac, int64_t qq, const char* msg);
15+
CQAPI(int32_t, CQ_addLog, int32_t ac, int32_t priority, const char *type, const char *reason);

0 commit comments

Comments
 (0)