mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c636af0b0e | ||
![]() |
b8af582749 | ||
![]() |
8e09a9e0fd | ||
![]() |
001dfc4db2 | ||
![]() |
a164884b76 | ||
![]() |
58f0a99d0b | ||
![]() |
528c6061e2 | ||
![]() |
f5ac499861 | ||
![]() |
621d9df450 |
95
README.md
95
README.md
@@ -18,6 +18,17 @@ TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
||||
|
||||
*插件目录:`LiteLoaderQQNT/plugins`*
|
||||
|
||||
安装后的目录结构如下
|
||||
```
|
||||
├── plugins
|
||||
│ ├── LLOneBot
|
||||
│ │ └── main.js
|
||||
│ │ └── preload.js
|
||||
│ │ └── renderer.js
|
||||
│ │ └── manifest.json
|
||||
│ │ └── node_modules/...
|
||||
```
|
||||
|
||||
## 支持的API
|
||||
|
||||
目前支持的协议
|
||||
@@ -42,6 +53,11 @@ TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
||||
- [x] 上报好友、群消息撤回
|
||||
- [x] 上报加群请求
|
||||
- [x] 上报群员人数变动(尚不支持识别群员人数变动原因)
|
||||
- [x] 设置群管理员
|
||||
- [x] 群禁言/全体禁言
|
||||
- [x] 群踢人
|
||||
- [x] 群改群成员名片
|
||||
- [x] 修改群名
|
||||
|
||||
消息格式支持:
|
||||
- [x] cq码
|
||||
@@ -53,34 +69,19 @@ TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
||||
- [x] 语音(支持mp3、wav等多种音频格式直接发送)
|
||||
- [x] json消息(只上报)
|
||||
- [x] 转发消息记录(目前只能发不能收)
|
||||
- [ ] 红包
|
||||
- [ ] xml
|
||||
|
||||
支持的api:
|
||||
- [x] get_login_info
|
||||
- [x] send_msg
|
||||
- [x] send_group_msg
|
||||
- [x] send_private_msg
|
||||
- [x] delete_msg
|
||||
- [x] get_group_list
|
||||
- [x] get_group_info
|
||||
- [x] get_group_member_list
|
||||
- [x] get_group_member_info
|
||||
- [x] get_friend_list
|
||||
- [x] set_friend_add_request
|
||||
- [x] get_msg
|
||||
- [x] send_like
|
||||
- [x] set_group_add_request
|
||||
- [x] set_group_leave
|
||||
- [x] get_version_info
|
||||
- [x] get_status
|
||||
- [x] can_send_image
|
||||
- [x] can_send_record
|
||||
|
||||
支持的go-cqhtp api:
|
||||
- [x] send_private_forward_msg
|
||||
- [x] send_group_forward_msg
|
||||
- [x] get_stranger_info
|
||||
- [x] 视频(上报时暂时只有个空的file)
|
||||
- [x] 文件(上报时暂时只有个空的file), type为file, data为{file: uri}, 发送时uri支持http://, file://, base64://
|
||||
```
|
||||
{
|
||||
"type": "file",
|
||||
"data": {
|
||||
"file": "file:///D:/1.txt"
|
||||
}
|
||||
}
|
||||
```
|
||||
- [ ] 发送音乐卡片
|
||||
- [ ] 红包(没有计划支持)
|
||||
- [ ] xml (没有计划支持)
|
||||
|
||||
## 示例
|
||||
|
||||
@@ -99,6 +100,7 @@ TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
||||
<summary>调用接口报404</summary>
|
||||
<br/>
|
||||
目前没有支持全部的onebot规范接口,请检查是否调用了不支持的接口
|
||||
-
|
||||
</details>
|
||||
<br/>
|
||||
|
||||
@@ -116,12 +118,49 @@ TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
||||
</details>
|
||||
<br/>
|
||||
|
||||
## 支持的onebot v11 api:
|
||||
- [x] get_login_info
|
||||
- [x] send_msg
|
||||
- [x] send_group_msg
|
||||
- [x] send_private_msg
|
||||
- [x] delete_msg
|
||||
- [x] get_group_list
|
||||
- [x] get_group_info
|
||||
- [x] get_group_member_list
|
||||
- [x] get_group_member_info
|
||||
- [x] get_friend_list
|
||||
- [x] set_friend_add_request
|
||||
- [x] get_msg
|
||||
- [x] send_like
|
||||
- [x] set_group_add_request
|
||||
- [x] set_group_leave
|
||||
- [x] set_group_kick
|
||||
- [x] set_group_ban
|
||||
- [x] set_group_whole_ban
|
||||
- [x] set_group_kick
|
||||
- [x] set_group_admin
|
||||
- [x] set_group_card
|
||||
- [x] set_group_name
|
||||
- [x] get_version_info
|
||||
- [x] get_status
|
||||
- [x] can_send_image
|
||||
- [x] can_send_record
|
||||
|
||||
### 支持的go-cqhtp api:
|
||||
- [x] send_private_forward_msg
|
||||
- [x] send_group_forward_msg
|
||||
- [x] get_stranger_info
|
||||
|
||||
## TODO
|
||||
- [x] 重构摆脱LLAPI,目前调用LLAPI只能在renderer进程调用,需重构成在main进程调用
|
||||
- [x] 支持正、反向websocket(感谢@disymayufei的PR)
|
||||
- [x] 转发消息记录
|
||||
- [x] 好友点赞api
|
||||
- [x] 群管理功能,禁言、踢人,改群名片等
|
||||
- [x] 视频消息
|
||||
- [x] 文件消息
|
||||
- [ ] 音乐卡片
|
||||
- [ ] 无头模式
|
||||
|
||||
## onebot11文档
|
||||
<https://11.onebot.dev/>
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"name": "LLOneBot",
|
||||
"slug": "LLOneBot",
|
||||
"description": "LiteLoaderQQNT的OneBotApi",
|
||||
"version": "3.8.0",
|
||||
"version": "3.9.0",
|
||||
"thumbnail": "./icon.png",
|
||||
"authors": [
|
||||
{
|
||||
|
@@ -2,7 +2,7 @@ import fs from "fs";
|
||||
import {Config, OB11Config} from "./types";
|
||||
import {mergeNewProperties} from "./utils";
|
||||
|
||||
export const HOOK_LOG = false;
|
||||
export const HOOK_LOG= false;
|
||||
|
||||
export class ConfigUtil {
|
||||
private readonly configPath: string;
|
||||
|
@@ -5,7 +5,7 @@ import {LLOneBotError} from "./types";
|
||||
export let groups: Group[] = []
|
||||
export let friends: Friend[] = []
|
||||
export let msgHistory: Record<string, RawMessage> = {} // msgId: RawMessage
|
||||
export const version = "3.8.0"
|
||||
export const version = "3.9.0"
|
||||
export let groupNotifies: Map<string, GroupNotify> = new Map<string, GroupNotify>();
|
||||
export let friendRequests: Map<number, FriendRequest> = new Map<number, FriendRequest>();
|
||||
export let llonebotError: LLOneBotError = {
|
||||
@@ -50,7 +50,11 @@ export async function getGroup(qq: string): Promise<Group | undefined> {
|
||||
return group
|
||||
}
|
||||
|
||||
export async function getGroupMember(groupQQ: string, memberQQ: string, memberUid: string = null) {
|
||||
export async function getGroupMember(groupQQ: string | number, memberQQ: string | number, memberUid: string = null) {
|
||||
groupQQ = groupQQ.toString();
|
||||
if (memberQQ){
|
||||
memberQQ = memberQQ.toString();
|
||||
}
|
||||
const group = await getGroup(groupQQ)
|
||||
if (group) {
|
||||
let filterFunc: (member: GroupMember) => boolean
|
||||
|
@@ -2,13 +2,14 @@ import {
|
||||
AtType,
|
||||
ElementType,
|
||||
SendFaceElement,
|
||||
SendFileElement,
|
||||
SendPicElement,
|
||||
SendPttElement,
|
||||
SendReplyElement,
|
||||
SendTextElement
|
||||
} from "./types";
|
||||
import {NTQQApi} from "./ntcall";
|
||||
import {encodeSilk} from "../common/utils";
|
||||
import {encodeSilk, log} from "../common/utils";
|
||||
import fs from "fs";
|
||||
|
||||
|
||||
@@ -80,12 +81,34 @@ export class SendMsgElementConstructor {
|
||||
};
|
||||
}
|
||||
|
||||
static async file(filePath: string, isVideo:boolean = false): Promise<SendFileElement> {
|
||||
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(filePath);
|
||||
let element: SendFileElement = {
|
||||
elementType: ElementType.FILE,
|
||||
elementId: "",
|
||||
fileElement: {
|
||||
fileName,
|
||||
"filePath": path,
|
||||
"fileSize": (fileSize).toString(),
|
||||
}
|
||||
}
|
||||
if (isVideo){
|
||||
element.fileElement.picHeight = 1024;
|
||||
element.fileElement.picWidth = 768;
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
static video(filePath: string): Promise<SendFileElement> {
|
||||
return SendMsgElementConstructor.file(filePath, true);
|
||||
}
|
||||
static async ptt(pttPath: string): Promise<SendPttElement> {
|
||||
const {converted, path: silkPath, duration} = await encodeSilk(pttPath);
|
||||
// log("生成语音", silkPath, duration);
|
||||
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(silkPath, ElementType.PTT);
|
||||
if (converted){
|
||||
fs.unlink(silkPath, ()=>{});
|
||||
if (converted) {
|
||||
fs.unlink(silkPath, () => {
|
||||
});
|
||||
}
|
||||
return {
|
||||
elementType: ElementType.PTT,
|
||||
|
@@ -7,7 +7,7 @@ import {
|
||||
Friend,
|
||||
FriendRequest,
|
||||
Group,
|
||||
GroupMember,
|
||||
GroupMember, GroupMemberRole,
|
||||
GroupNotifies,
|
||||
GroupNotify,
|
||||
GroupRequestOperateTypes,
|
||||
@@ -62,6 +62,13 @@ export enum NTQQApiMethod {
|
||||
QUIT_GROUP = "nodeIKernelGroupService/quitGroup",
|
||||
// READ_FRIEND_REQUEST = "nodeIKernelBuddyListener/onDoubtBuddyReqUnreadNumChange"
|
||||
HANDLE_FRIEND_REQUEST = "nodeIKernelBuddyService/approvalFriendRequest",
|
||||
KICK_MEMBER = "nodeIKernelGroupService/kickMember",
|
||||
MUTE_MEMBER = "nodeIKernelGroupService/setMemberShutUp",
|
||||
MUTE_GROUP = "nodeIKernelGroupService/setGroupShutUp",
|
||||
SET_MEMBER_CARD = "nodeIKernelGroupService/modifyMemberCardName",
|
||||
SET_MEMBER_ROLE = "nodeIKernelGroupService/modifyMemberRole",
|
||||
PUBLISH_GROUP_BULLETIN = "nodeIKernelGroupService/publishGroupBulletinBulletin",
|
||||
SET_GROUP_NAME = "nodeIKernelGroupService/modifyGroupName",
|
||||
}
|
||||
|
||||
enum NTQQApiChannel {
|
||||
@@ -331,7 +338,7 @@ export class NTQQApi {
|
||||
}
|
||||
|
||||
// 上传文件到QQ的文件夹
|
||||
static async uploadFile(filePath: string, elementType: ElementType=ElementType.PIC) {
|
||||
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) {
|
||||
const md5 = await NTQQApi.getFileMd5(filePath);
|
||||
let ext = (await NTQQApi.getFileType(filePath))?.ext
|
||||
if (ext) {
|
||||
@@ -582,7 +589,7 @@ export class NTQQApi {
|
||||
|
||||
static async handleFriendRequest(sourceId: number, accept: boolean,) {
|
||||
const request: FriendRequest = friendRequests[sourceId]
|
||||
if (!request){
|
||||
if (!request) {
|
||||
throw `sourceId ${sourceId}, 对应的好友请求不存在`
|
||||
}
|
||||
const result = await callNTQQApi<GeneralCallResult>({
|
||||
@@ -600,4 +607,88 @@ export class NTQQApi {
|
||||
delete friendRequests[sourceId];
|
||||
return result;
|
||||
}
|
||||
|
||||
static kickMember(groupQQ: string, kickUids: string[], refuseForever: boolean = false, kickReason: string = "") {
|
||||
return callNTQQApi<GeneralCallResult>(
|
||||
{
|
||||
methodName: NTQQApiMethod.KICK_MEMBER,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
kickUids,
|
||||
refuseForever,
|
||||
kickReason,
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
static banMember(groupQQ: string, memList: { uid: string, timeStamp: number }[]) {
|
||||
// timeStamp为秒数, 0为解除禁言
|
||||
return callNTQQApi<GeneralCallResult>(
|
||||
{
|
||||
methodName: NTQQApiMethod.MUTE_MEMBER,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
memList,
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
}
|
||||
static banGroup(groupQQ: string, shutUp: boolean){
|
||||
return callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.MUTE_GROUP,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
shutUp
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static setMemberCard(groupQQ: string, memberUid: string, cardName: string) {
|
||||
return callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_MEMBER_CARD,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
uid: memberUid,
|
||||
cardName
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) {
|
||||
return callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_MEMBER_ROLE,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
uid: memberUid,
|
||||
role
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static setGroupName(groupQQ: string, groupName: string){
|
||||
return callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_GROUP_NAME,
|
||||
args:[
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
groupName
|
||||
},null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static publishGroupBulletin(groupQQ: string, title: string, content: string) {
|
||||
|
||||
}
|
||||
}
|
@@ -45,6 +45,12 @@ export interface Group {
|
||||
members: GroupMember[] // 原始数据是没有这个的,为了方便自己加了这个字段
|
||||
}
|
||||
|
||||
export enum GroupMemberRole {
|
||||
normal = 2,
|
||||
admin = 3,
|
||||
owner = 4
|
||||
}
|
||||
|
||||
export interface GroupMember {
|
||||
avatarPath: string;
|
||||
cardName: string;
|
||||
@@ -53,7 +59,7 @@ export interface GroupMember {
|
||||
nick: string;
|
||||
qid: string;
|
||||
remark: string;
|
||||
role: number; // 群主:4, 管理员:3,群员:2
|
||||
role: GroupMemberRole; // 群主:4, 管理员:3,群员:2
|
||||
shutUpTime: number; // 禁言时间,单位是什么暂时不清楚
|
||||
uid: string; // 加密的字符串
|
||||
uin: string; // QQ号
|
||||
@@ -62,6 +68,7 @@ export interface GroupMember {
|
||||
export enum ElementType {
|
||||
TEXT = 1,
|
||||
PIC = 2,
|
||||
FILE = 3,
|
||||
PTT = 4,
|
||||
FACE = 6,
|
||||
REPLY = 7,
|
||||
@@ -136,7 +143,30 @@ export interface SendFaceElement {
|
||||
faceElement: FaceElement
|
||||
}
|
||||
|
||||
export type SendMessageElement = SendTextElement | SendPttElement | SendPicElement | SendReplyElement | SendFaceElement
|
||||
export interface FileElement {
|
||||
"fileMd5"?: "",
|
||||
"fileName": string,
|
||||
"filePath": string,
|
||||
"fileSize": string,
|
||||
"picHeight"?: number,
|
||||
"picWidth"?: number,
|
||||
"picThumbPath"?: {},
|
||||
"file10MMd5"?: "",
|
||||
"fileSha"?: "",
|
||||
"fileSha3"?: "",
|
||||
"fileUuid"?: "",
|
||||
"fileSubId"?: "",
|
||||
"thumbFileSize"?: number
|
||||
}
|
||||
|
||||
export interface SendFileElement {
|
||||
"elementType": ElementType.FILE,
|
||||
"elementId": "",
|
||||
"fileElement": FileElement
|
||||
}
|
||||
|
||||
export type SendMessageElement = SendTextElement | SendPttElement |
|
||||
SendPicElement | SendReplyElement | SendFaceElement | SendFileElement
|
||||
|
||||
export enum AtType {
|
||||
notAt = 0,
|
||||
@@ -206,6 +236,31 @@ export interface FaceElement {
|
||||
faceType: 1
|
||||
}
|
||||
|
||||
export interface VideoElement {
|
||||
"filePath": string,
|
||||
"fileName": string,
|
||||
"videoMd5": string,
|
||||
"thumbMd5": string
|
||||
"fileTime": 87, // second
|
||||
"thumbSize": 314235, // byte
|
||||
"fileFormat": 2, // 2表示mp4?
|
||||
"fileSize": string, // byte
|
||||
"thumbWidth": number,
|
||||
"thumbHeight": number,
|
||||
"busiType": 0, // 未知
|
||||
"subBusiType": 0, // 未知
|
||||
"thumbPath": {},
|
||||
"transferStatus": 0, // 未知
|
||||
"progress": 0, // 下载进度?
|
||||
"invalidState": 0, // 未知
|
||||
"fileUuid": string, // 可以用于下载链接?
|
||||
"fileSubId": "",
|
||||
"fileBizId": null,
|
||||
"originVideoMd5": "",
|
||||
"import_rich_media_context": null,
|
||||
"sourceVideoCodecFormat": 0
|
||||
}
|
||||
|
||||
export interface RawMessage {
|
||||
msgId: string;
|
||||
msgShortId?: number; // 自己维护的消息id
|
||||
@@ -239,6 +294,8 @@ export interface RawMessage {
|
||||
arkElement: ArkElement;
|
||||
grayTipElement: GrayTipElement;
|
||||
faceElement: FaceElement;
|
||||
videoElement: VideoElement;
|
||||
fileElement: FileElement;
|
||||
}[];
|
||||
}
|
||||
|
||||
@@ -276,12 +333,12 @@ export interface GroupNotify {
|
||||
warningTips: string
|
||||
}
|
||||
|
||||
export enum GroupRequestOperateTypes{
|
||||
export enum GroupRequestOperateTypes {
|
||||
approve = 1,
|
||||
reject = 2
|
||||
}
|
||||
|
||||
export interface FriendRequest{
|
||||
export interface FriendRequest {
|
||||
friendUid: string,
|
||||
reqTime: string, // 时间戳,秒
|
||||
extWords: string, // 申请人填写的验证消息
|
||||
@@ -290,7 +347,8 @@ export interface FriendRequest{
|
||||
sourceId: number,
|
||||
groupCode: string
|
||||
}
|
||||
export interface FriendRequestNotify{
|
||||
|
||||
export interface FriendRequestNotify {
|
||||
data: {
|
||||
unreadNums: number,
|
||||
buddyReqs: FriendRequest[]
|
||||
|
@@ -10,6 +10,7 @@ import * as fs from "fs";
|
||||
import {log} from "../../common/utils";
|
||||
import {v4 as uuidv4} from "uuid"
|
||||
import {decodeCQCode} from "../cqcode";
|
||||
import {Send} from "express";
|
||||
|
||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||
function checkUri(uri: string): boolean {
|
||||
@@ -145,13 +146,13 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
peerUid: selfInfo.uid
|
||||
}
|
||||
let nodeIds: string[] = []
|
||||
for (const messageNode of messageNodes){
|
||||
for (const messageNode of messageNodes) {
|
||||
// 一个node表示一个人的消息
|
||||
let nodeId = messageNode.data.id;
|
||||
// 有nodeId表示一个子转发消息卡片
|
||||
if (nodeId) {
|
||||
let nodeMsg = getHistoryMsgByShortId(nodeId);
|
||||
if (nodeMsg){
|
||||
if (nodeMsg) {
|
||||
nodeIds.push(nodeMsg.msgId);
|
||||
}
|
||||
} else {
|
||||
@@ -230,6 +231,8 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
}
|
||||
break;
|
||||
case OB11MessageDataType.image:
|
||||
case OB11MessageDataType.file:
|
||||
case OB11MessageDataType.video:
|
||||
case OB11MessageDataType.voice: {
|
||||
const file = sendMsg.data?.file
|
||||
if (file) {
|
||||
@@ -238,11 +241,13 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
if (!isLocal) { // 只删除http和base64转过来的文件
|
||||
deleteAfterSentFiles.push(path)
|
||||
}
|
||||
if (sendMsg.type === OB11MessageDataType.image) {
|
||||
sendElements.push(await SendMsgElementConstructor.pic(path))
|
||||
} else {
|
||||
sendElements.push(await SendMsgElementConstructor.ptt(path))
|
||||
const constructorMap = {
|
||||
[OB11MessageDataType.image]: SendMsgElementConstructor.pic,
|
||||
[OB11MessageDataType.voice]: SendMsgElementConstructor.ptt,
|
||||
[OB11MessageDataType.video]: SendMsgElementConstructor.video,
|
||||
[OB11MessageDataType.file]: SendMsgElementConstructor.file,
|
||||
}
|
||||
sendElements.push(await constructorMap[sendMsg.type](path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
23
src/onebot11/action/SetGroupAdmin.ts
Normal file
23
src/onebot11/action/SetGroupAdmin.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {GroupMemberRole} from "../../ntqqapi/types";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
interface Payload{
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
enable: boolean
|
||||
}
|
||||
|
||||
export default class SetGroupAdmin extends BaseAction<Payload, null>{
|
||||
actionName = ActionName.SetGroupAdmin
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const member = await getGroupMember(payload.group_id, payload.user_id)
|
||||
if(!member){
|
||||
throw `群成员${payload.user_id}不存在`
|
||||
}
|
||||
await NTQQApi.setMemberRole(payload.group_id.toString(), member.uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal)
|
||||
return null
|
||||
}
|
||||
}
|
23
src/onebot11/action/SetGroupBan.ts
Normal file
23
src/onebot11/action/SetGroupBan.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
interface Payload{
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
duration: number
|
||||
}
|
||||
|
||||
export default class SetGroupBan extends BaseAction<Payload, null>{
|
||||
actionName = ActionName.SetGroupBan
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const member = await getGroupMember(payload.group_id, payload.user_id)
|
||||
if(!member){
|
||||
throw `群成员${payload.user_id}不存在`
|
||||
}
|
||||
await NTQQApi.banMember(payload.group_id.toString(),
|
||||
[{uid:member.uid, timeStamp: parseInt(payload.duration.toString())}])
|
||||
return null
|
||||
}
|
||||
}
|
23
src/onebot11/action/SetGroupCard.ts
Normal file
23
src/onebot11/action/SetGroupCard.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {GroupMemberRole} from "../../ntqqapi/types";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
interface Payload{
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
card: string
|
||||
}
|
||||
|
||||
export default class SetGroupCard extends BaseAction<Payload, null>{
|
||||
actionName = ActionName.SetGroupCard
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const member = await getGroupMember(payload.group_id, payload.user_id)
|
||||
if(!member){
|
||||
throw `群成员${payload.user_id}不存在`
|
||||
}
|
||||
await NTQQApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || "")
|
||||
return null
|
||||
}
|
||||
}
|
22
src/onebot11/action/SetGroupKick.ts
Normal file
22
src/onebot11/action/SetGroupKick.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
interface Payload{
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
reject_add_request: boolean
|
||||
}
|
||||
|
||||
export default class SetGroupKick extends BaseAction<Payload, null>{
|
||||
actionName = ActionName.SetGroupKick
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const member = await getGroupMember(payload.group_id, payload.user_id)
|
||||
if(!member){
|
||||
throw `群成员${payload.user_id}不存在`
|
||||
}
|
||||
await NTQQApi.kickMember(payload.group_id.toString(), [member.uid], !!payload.reject_add_request);
|
||||
return null
|
||||
}
|
||||
}
|
18
src/onebot11/action/SetGroupName.ts
Normal file
18
src/onebot11/action/SetGroupName.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
group_name: string
|
||||
}
|
||||
|
||||
export default class SetGroupName extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupName
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
|
||||
await NTQQApi.setGroupName(payload.group_id.toString(), payload.group_name)
|
||||
return null
|
||||
}
|
||||
}
|
18
src/onebot11/action/SetGroupWholeBan.ts
Normal file
18
src/onebot11/action/SetGroupWholeBan.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
enable: boolean
|
||||
}
|
||||
|
||||
export default class SetGroupWholeBan extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupWholeBan
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
|
||||
await NTQQApi.banGroup(payload.group_id.toString(), !!payload.enable)
|
||||
return null
|
||||
}
|
||||
}
|
@@ -22,6 +22,12 @@ import SetGroupLeave from "./SetGroupLeave";
|
||||
import GetGuildList from "./GetGuildList";
|
||||
import Debug from "./Debug";
|
||||
import SetFriendAddRequest from "./SetFriendAddRequest";
|
||||
import SetGroupWholeBan from "./SetGroupWholeBan";
|
||||
import SetGroupName from "./SetGroupName";
|
||||
import SetGroupBan from "./SetGroupBan";
|
||||
import SetGroupKick from "./SetGroupKick";
|
||||
import SetGroupAdmin from "./SetGroupAdmin";
|
||||
import SetGroupCard from "./SetGroupCard";
|
||||
|
||||
export const actionHandlers = [
|
||||
new Debug(),
|
||||
@@ -39,6 +45,12 @@ export const actionHandlers = [
|
||||
new CanSendRecord(),
|
||||
new CanSendImage(),
|
||||
new GetStatus(),
|
||||
new SetGroupWholeBan(),
|
||||
new SetGroupBan(),
|
||||
new SetGroupKick(),
|
||||
new SetGroupAdmin(),
|
||||
new SetGroupName(),
|
||||
new SetGroupCard(),
|
||||
|
||||
//以下为go-cqhttp api
|
||||
new GoCQHTTPSendGroupForwardMsg(),
|
||||
|
@@ -34,6 +34,12 @@ export enum ActionName {
|
||||
GetStatus = "get_status",
|
||||
CanSendRecord = "can_send_record",
|
||||
CanSendImage = "can_send_image",
|
||||
SetGroupKick = "set_group_kick",
|
||||
SetGroupBan = "set_group_ban",
|
||||
SetGroupWholeBan = "set_group_whole_ban",
|
||||
SetGroupAdmin = "set_group_admin",
|
||||
SetGroupCard = "set_group_card",
|
||||
SetGroupName = "set_group_name",
|
||||
// 以下为go-cqhttp api
|
||||
GoCQHTTP_SendGroupForwardMsg = "send_group_forward_msg",
|
||||
GoCQHTTP_SendPrivateForwardMsg = "send_private_forward_msg",
|
||||
|
@@ -88,6 +88,14 @@ export class OB11Constructor {
|
||||
continue;
|
||||
}
|
||||
message_data["data"]["text"] = text
|
||||
} else if (element.replyElement) {
|
||||
message_data["type"] = "reply"
|
||||
const replyMsg = getHistoryMsgBySeq(element.replyElement.replayMsgSeq)
|
||||
if (replyMsg) {
|
||||
message_data["data"]["id"] = replyMsg.msgShortId.toString()
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
} else if (element.picElement) {
|
||||
message_data["type"] = "image"
|
||||
message_data["data"]["file_id"] = element.picElement.fileUuid
|
||||
@@ -99,15 +107,19 @@ export class OB11Constructor {
|
||||
element.elementId, element.picElement.thumbPath.get(0), element.picElement.sourcePath)
|
||||
} catch (e) {
|
||||
}
|
||||
} else if (element.replyElement) {
|
||||
message_data["type"] = "reply"
|
||||
const replyMsg = getHistoryMsgBySeq(element.replyElement.replayMsgSeq)
|
||||
if (replyMsg) {
|
||||
message_data["data"]["id"] = replyMsg.msgShortId.toString()
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
} else if (element.pttElement) {
|
||||
} else if (element.videoElement) {
|
||||
message_data["type"] = OB11MessageDataType.video;
|
||||
message_data["data"]["file"] = element.videoElement.filePath
|
||||
message_data["data"]["file_id"] = element.videoElement.fileUuid
|
||||
// 怎么拿到url呢
|
||||
} else if (element.fileElement) {
|
||||
message_data["type"] = OB11MessageDataType.file;
|
||||
message_data["data"]["file"] = element.fileElement.filePath
|
||||
message_data["data"]["file_id"] = element.fileElement.fileUuid
|
||||
message_data["data"]["file_size"] = element.fileElement.fileSize
|
||||
// 怎么拿到url呢
|
||||
}
|
||||
else if (element.pttElement) {
|
||||
message_data["type"] = OB11MessageDataType.voice;
|
||||
message_data["data"]["file"] = element.pttElement.filePath
|
||||
message_data["data"]["file_id"] = element.pttElement.fileUuid
|
||||
@@ -125,20 +137,26 @@ export class OB11Constructor {
|
||||
message_data["type"] = OB11MessageDataType.face;
|
||||
message_data["data"]["id"] = element.faceElement.faceIndex.toString();
|
||||
}
|
||||
|
||||
if (message_data.data.file) {
|
||||
let filePath: string = message_data.data.file;
|
||||
if (!enableLocalFile2Url) {
|
||||
message_data.data.file = "file://" + filePath
|
||||
} else { // 不使用本地路径
|
||||
if (message_data.data.url && !message_data.data.url.startsWith(IMAGE_HTTP_HOST + "/download")) {
|
||||
message_data.data.file = message_data.data.url
|
||||
} else {
|
||||
let {err, data} = await file2base64(filePath);
|
||||
if (err) {
|
||||
log("文件转base64失败", filePath, err)
|
||||
const ignoreTypes = [OB11MessageDataType.file, OB11MessageDataType.video]
|
||||
if (!ignoreTypes.includes(message_data.type)) {
|
||||
if (message_data.data.url && !message_data.data.url.startsWith(IMAGE_HTTP_HOST + "/download")) {
|
||||
message_data.data.file = message_data.data.url
|
||||
} else {
|
||||
message_data.data.file = "base64://" + data
|
||||
let {err, data} = await file2base64(filePath);
|
||||
if (err) {
|
||||
log("文件转base64失败", filePath, err)
|
||||
} else {
|
||||
message_data.data.file = "base64://" + data
|
||||
}
|
||||
}
|
||||
}else{
|
||||
message_data.data.file = "file://" + filePath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ import {EventType} from "../OB11BaseEvent";
|
||||
|
||||
|
||||
export class OB11FriendRequestEvent extends OB11BaseNoticeEvent {
|
||||
post_type = EventType.REQUEST
|
||||
// post_type = EventType.REQUEST
|
||||
user_id: number;
|
||||
request_type: "friend" = "friend";
|
||||
comment: string;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import {AtType, RawMessage} from "../ntqqapi/types";
|
||||
import {RawMessage} from "../ntqqapi/types";
|
||||
import {EventType} from "./event/OB11BaseEvent";
|
||||
|
||||
export interface OB11User {
|
||||
@@ -85,7 +85,9 @@ export interface OB11Return<DataType> {
|
||||
export enum OB11MessageDataType {
|
||||
text = "text",
|
||||
image = "image",
|
||||
video = "video",
|
||||
voice = "record",
|
||||
file = "file",
|
||||
at = "at",
|
||||
reply = "reply",
|
||||
json = "json",
|
||||
@@ -115,6 +117,14 @@ export interface OB11MessageRecord extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.voice
|
||||
}
|
||||
|
||||
export interface OB11MessageFile extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.file
|
||||
}
|
||||
|
||||
export interface OB11MessageVideo extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.video
|
||||
}
|
||||
|
||||
export interface OB11MessageAt {
|
||||
type: OB11MessageDataType.at
|
||||
data: {
|
||||
@@ -152,7 +162,7 @@ export type OB11MessageData =
|
||||
OB11MessageText |
|
||||
OB11MessageFace |
|
||||
OB11MessageAt | OB11MessageReply |
|
||||
OB11MessageImage | OB11MessageRecord |
|
||||
OB11MessageImage | OB11MessageRecord | OB11MessageFile | OB11MessageVideo |
|
||||
OB11MessageNode
|
||||
|
||||
export interface OB11PostSendMsg {
|
||||
|
Reference in New Issue
Block a user