UNPKG

miraipie

Version:

the most powerful nodejs development kit for mirai-api-http

925 lines (924 loc) 40.8 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TempChat = exports.GroupChat = exports.FriendChat = exports.Chat = void 0; var message_1 = require("./message"); var mirai_1 = require("./mirai"); var miraipie_1 = require("./miraipie"); /** * 聊天窗口, 用以模拟QQ客户端的聊天环境 */ var Chat = /** @class */ (function () { function Chat() { } /** * 撤回消息 * @param messageId 消息id * @return 是否撤回成功 */ Chat.recall = function (messageId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.recall(messageId)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 打开指定好友的聊天窗, 没有找到时返回null * @param friendId 好友QQ号 * @since 1.1.15 * @example * const chat = await Chat.findFriend(10000000); * await chat.send('Hello World!'); */ Chat.findFriend = function (friendId) { return __awaiter(this, void 0, void 0, function () { var resp, _a, _b, friend; var e_1, _c; return __generator(this, function (_d) { switch (_d.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.getFriendList()]; case 1: resp = _d.sent(); try { for (_a = __values(resp.data), _b = _a.next(); !_b.done; _b = _a.next()) { friend = _b.value; if (friend.id === friendId) return [2 /*return*/, new FriendChat(friend)]; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_1) throw e_1.error; } } return [2 /*return*/, null]; } }); }); }; /** * 打开指定群聊的聊天窗, 没有找到时返回null, 该聊天窗会将群主作为聊天窗的消息发送人 * @param groupId 群号 * @since 1.1.15 * @example * const chat = await Chat.findGroup(20000000); * await chat.send('Hello World!'); */ Chat.findGroup = function (groupId) { return __awaiter(this, void 0, void 0, function () { var resp, _a, _b, member; var e_2, _c; return __generator(this, function (_d) { switch (_d.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.getMemberList(groupId)]; case 1: resp = _d.sent(); if (resp.code === mirai_1.ResponseCode.Success) { try { for (_a = __values(resp.data), _b = _a.next(); !_b.done; _b = _a.next()) { member = _b.value; if (member.permission === 'OWNER') return [2 /*return*/, new GroupChat(member)]; } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_2) throw e_2.error; } } } return [2 /*return*/, null]; } }); }); }; /** * 发送一条消息<br/> * 使用该方法向当前聊天对象发送一条消息 * @param message 待发送的消息 * @param quoteMessageId 引用回复的消息id * @return 已发送消息的消息id * @example * chat.send('Hello World!'); // 纯文本消息 * chat.send(AtAll()); // 单个单一消息 * chat.send([AtAll(), Plain('Hello World!')]); // 单一消息列表 * chat.send(MessageChain.from([AtAll(), Plain('Hello World!')])); // 消息链对象 * chat.send('Hello World!', 123456); // 发送消息并引用回复消息 */ Chat.prototype.send = function (message, quoteMessageId) { return __awaiter(this, void 0, void 0, function () { var messageChain; return __generator(this, function (_a) { messageChain = new message_1.MessageChain(); if (typeof message === 'string') messageChain.push(message_1.Plain(message)); else if (Array.isArray(message)) messageChain = message_1.MessageChain.from(message); else messageChain.push(message); return [2 /*return*/, this._send(messageChain, quoteMessageId)]; }); }); }; /** 判断是否为好友聊天窗口 */ Chat.prototype.isFriendChat = function () { return this.type === 'FriendChat'; }; /** 判断是否为群聊聊天窗口 */ Chat.prototype.isGroupChat = function () { return this.type === 'GroupChat'; }; /** 判断是否为临时聊天窗口 */ Chat.prototype.isTempChat = function () { return this.type === 'TempChat'; }; return Chat; }()); exports.Chat = Chat; /** * 好友聊天窗 */ var FriendChat = /** @class */ (function (_super) { __extends(FriendChat, _super); function FriendChat(contact) { var _this = _super.call(this) || this; _this.contact = contact; _this.type = 'FriendChat'; _this.sender = contact; return _this; } FriendChat.prototype.nextMessage = function (timeout) { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { return [2 /*return*/, new Promise(function (resolve, reject) { var flag = true; miraipie_1.MiraiPieApplication.instance.once('FriendMessage', function (chatMessage) { if (_this.sender.id === chatMessage.sender.id) { flag = false; resolve(message_1.MessageChain.from(chatMessage.messageChain)); } }); if (timeout > 0) { setTimeout(function () { if (flag) reject(new Error('等待消息已超时')); }, timeout); } })]; }); }); }; FriendChat.prototype.sendNudge = function (targetId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.sendNudge(targetId || this.contact.id, this.contact.id, 'Friend')]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; FriendChat.prototype._send = function (messageChain, quoteMessageId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.sendFriendMessage(this.contact.id, messageChain, quoteMessageId)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.messageId]; } }); }); }; /** * 获取聊天对象的个人资料 * @return 聊天对象的个人资料 */ FriendChat.prototype.getProfile = function () { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.getFriendProfile(this.contact.id)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.data]; } }); }); }; /** * 删除好友(慎用) * @return 是否删除成功 */ FriendChat.prototype.delete = function () { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.deleteFriend(this.contact.id)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; return FriendChat; }(Chat)); exports.FriendChat = FriendChat; /** * 群聊聊天窗 */ var GroupChat = /** @class */ (function (_super) { __extends(GroupChat, _super); function GroupChat(sender) { var _this = _super.call(this) || this; _this.sender = sender; _this.type = 'GroupChat'; _this.contact = sender.group; return _this; } GroupChat.prototype.nextMessage = function (timeout) { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { return [2 /*return*/, new Promise(function (resolve, reject) { var flag = true; miraipie_1.MiraiPieApplication.instance.once('GroupMessage', function (chatMessage) { if (_this.sender.id === chatMessage.sender.id && _this.contact.id === chatMessage.sender.group.id) { flag = false; resolve(message_1.MessageChain.from(chatMessage.messageChain)); } }); if (timeout > 0) { setTimeout(function () { if (flag) reject(new Error('等待消息已超时')); }, timeout); } })]; }); }); }; GroupChat.prototype.sendNudge = function (targetId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.sendNudge(targetId, this.contact.id, 'Group')]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; GroupChat.prototype._send = function (messageChain, quoteMessageId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.sendGroupMessage(this.contact.id, messageChain, quoteMessageId)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.messageId]; } }); }); }; Object.defineProperty(GroupChat.prototype, "permission", { /** 机器人在本群权限 */ get: function () { return this.contact.permission; }, enumerable: false, configurable: true }); /** * 设置群精华消息 * @param messageId 消息id * @return 是否设置成功 */ GroupChat.setEssence = function (messageId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.setEssence(messageId)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 等待下一条群消息, 无论发送人是谁 * @since 1.1.14 * @param timeout 超时时间, 单位毫秒, 默认为0(不超时) */ GroupChat.prototype.nextGroupMessage = function (timeout) { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { return [2 /*return*/, new Promise(function (resolve, reject) { var flag = true; miraipie_1.MiraiPieApplication.instance.once('GroupMessage', function (chatMessage) { if (_this.contact.id === chatMessage.sender.group.id) { flag = false; resolve(message_1.MessageChain.from(chatMessage.messageChain)); } }); if (timeout > 0) { setTimeout(function () { if (flag) reject(new Error('等待消息已超时')); }, timeout); } })]; }); }); }; /** * 获取群成员列表 * @return 群成员列表 */ GroupChat.prototype.getMemberList = function () { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.getMemberList(this.contact.id)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.data]; } }); }); }; /** * 获取成员的个人资料 * @param memberId 成员QQ号(默认为当前消息发送人) * @return 聊天对象的个人资料 */ GroupChat.prototype.getProfile = function (memberId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.getMemberProfile(memberId || this.sender.id, this.contact.id)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.data]; } }); }); }; /** * 获取群公告列表 * @since 1.2.9 * @param offset 分页偏移 * @param size 分页大小 * @return 群公告列表 */ GroupChat.prototype.getAnnouncements = function (offset, size) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.getGroupAnnouncements(this.contact.id, offset, size)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.data]; } }); }); }; /** * 发布群公告 * @since 1.2.9 * @param groupId 群号 * @param announcement 公告内容 * @return 群公告 */ GroupChat.prototype.postAnnouncement = function (groupId, announcement) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.postGroupAnnouncement(this.contact.id, announcement)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.data]; } }); }); }; /** * 删除群公告 * @since 1.2.9 * @param announcementId 群公告id * @return 是否删除成功 */ GroupChat.prototype.deleteAnnouncement = function (announcementId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.deleteGroupAnnouncement(this.contact.id, announcementId)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 获取成员信息 * @param memberId 成员QQ号(默认为当前消息发送人) * @return 成员信息 */ GroupChat.prototype.getInfo = function (memberId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.getMemberInfo(memberId || this.sender.id, this.contact.id)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.data]; } }); }); }; /** * 修改成员信息 * @param info 成员信息 * @param memberId 成员QQ号(默认为当前消息发送人) * @return 是否修改成功 */ GroupChat.prototype.setInfo = function (info, memberId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.setMemberInfo(memberId || this.sender.id, this.contact.id, info)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 禁言成员 * @param time 禁言时长(秒) * @param memberId 成员QQ号(默认为当前消息发送人) * @return 是否禁言成功 */ GroupChat.prototype.mute = function (time, memberId) { if (time === void 0) { time = 60; } return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.muteMember(memberId || this.sender.id, this.contact.id, time)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 取消禁言成员 * @param memberId 成员QQ号(默认为当前消息发送人) * @return 是否取消成功 */ GroupChat.prototype.unmute = function (memberId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.unmuteMember(memberId || this.sender.id, this.contact.id)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 踢出成员 * @param message 留言 * @param memberId 成员QQ号(默认为当前消息发送人) * @return 是否踢出成功 */ GroupChat.prototype.kick = function (message, memberId) { if (message === void 0) { message = ''; } return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.kickMember(memberId || this.sender.id, this.contact.id, message)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 退出群聊 * @return 是否退出成功 */ GroupChat.prototype.quit = function () { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.quitGroup(this.contact.id)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 全体禁言 * @return 是否禁言成功 */ GroupChat.prototype.muteAll = function () { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.muteAll(this.contact.id)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 取消全体禁言 * @return 是否取消成功 */ GroupChat.prototype.unmuteAll = function () { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.unmuteAll(this.contact.id)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 获取群设置 * @return 群设置 */ GroupChat.prototype.getConfig = function () { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.getGroupConfig(this.contact.id)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.data]; } }); }); }; /** * 修改群设置 * @param config 群设置 * @return 是否修改成功 */ GroupChat.prototype.setConfig = function (config) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.setGroupConfig(this.contact.id, config)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 设置或取消管理员 * @since 1.1.14 * @param admin 是否为管理员 * @param memberId 成员QQ号(默认为当前消息发送人) * @return 是否操作成功 */ GroupChat.prototype.setAdmin = function (admin, memberId) { if (admin === void 0) { admin = true; } return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.setMemberAdmin(memberId || this.sender.id, this.contact.id, admin)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 获取群文件列表 * @param directoryPathOrId 文件夹路径或id * @param offset 分页偏移 * @param size 分页大小 * @return 文件列表 */ GroupChat.prototype.getFileList = function (directoryPathOrId, offset, size) { if (directoryPathOrId === void 0) { directoryPathOrId = ''; } if (offset === void 0) { offset = 0; } if (size === void 0) { size = 100; } return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.getFileList(directoryPathOrId, directoryPathOrId, this.contact.id, null, offset, size, true)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.data]; } }); }); }; /** * 获取文件详情 * @param pathOrId 文件路径或id * @return 文件概览 */ GroupChat.prototype.getFileInfo = function (pathOrId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.getFileInfo(pathOrId, pathOrId, this.contact.id, null, true)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.data]; } }); }); }; /** * 创建群文件夹 * @param directoryName 文件夹名称 * @param parentDirectoryPathOrId 父文件夹路径或id * @return 文件夹概览 */ GroupChat.prototype.createDirectory = function (directoryName, parentDirectoryPathOrId) { if (parentDirectoryPathOrId === void 0) { parentDirectoryPathOrId = ''; } return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.createFileDirectory(parentDirectoryPathOrId, parentDirectoryPathOrId, directoryName, this.contact.id, null)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.data]; } }); }); }; /** * 删除群文件 * @param pathOrId 文件路径或id * @return 是否删除成功 */ GroupChat.prototype.deleteFile = function (pathOrId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.deleteFile(pathOrId, pathOrId, this.contact.id, null)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 移动群文件 * @param pathOrId 文件路径或id * @param moveToDirectoryPathOrId 移动到文件夹路径或id * @return 是否移动成功 */ GroupChat.prototype.moveFile = function (pathOrId, moveToDirectoryPathOrId) { if (moveToDirectoryPathOrId === void 0) { moveToDirectoryPathOrId = null; } return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.moveFile(pathOrId, pathOrId, this.contact.id, null, moveToDirectoryPathOrId, moveToDirectoryPathOrId)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 重命名群文件 * @param pathOrId 文件路径或id * @param name 文件名 * @return 是否重命名成功 */ GroupChat.prototype.renameFile = function (pathOrId, name) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.renameFile(pathOrId, pathOrId, this.contact.id, null, name)]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; /** * 打开私聊窗口 * @since 1.1.14 * @return 当前消息发送人的私聊窗口 */ GroupChat.prototype.openTempChat = function () { return new TempChat(this.sender); }; return GroupChat; }(Chat)); exports.GroupChat = GroupChat; /** * 临时消息聊天窗 */ var TempChat = /** @class */ (function (_super) { __extends(TempChat, _super); function TempChat(contact) { var _this = _super.call(this) || this; _this.contact = contact; _this.type = 'TempChat'; _this.sender = contact; return _this; } TempChat.prototype.nextMessage = function (timeout) { return __awaiter(this, void 0, void 0, function () { var _this = this; return __generator(this, function (_a) { return [2 /*return*/, new Promise(function (resolve, reject) { var flag = true; miraipie_1.MiraiPieApplication.instance.once('TempMessage', function (chatMessage) { if (_this.sender.id === chatMessage.sender.id) { flag = false; resolve(message_1.MessageChain.from(chatMessage.messageChain)); } }); if (timeout > 0) { setTimeout(function () { if (flag) reject(new Error('等待消息已超时')); }, timeout); } })]; }); }); }; TempChat.prototype.sendNudge = function (targetId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.sendNudge(targetId || this.contact.id, this.contact.id, 'Stranger')]; case 1: resp = _a.sent(); return [2 /*return*/, (resp === null || resp === void 0 ? void 0 : resp.code) === mirai_1.ResponseCode.Success]; } }); }); }; TempChat.prototype._send = function (messageChain, quoteMessageId) { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.sendTempMessage(this.contact.id, this.contact.group.id, messageChain, quoteMessageId)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.messageId]; } }); }); }; /** * 获取聊天对象的个人资料 * @return 聊天对象的个人资料 */ TempChat.prototype.getProfile = function () { return __awaiter(this, void 0, void 0, function () { var resp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, miraipie_1.MiraiPieApplication.instance.api.getMemberProfile(this.contact.group.id, this.contact.id)]; case 1: resp = _a.sent(); return [2 /*return*/, resp === null || resp === void 0 ? void 0 : resp.data]; } }); }); }; return TempChat; }(Chat)); exports.TempChat = TempChat;