UNPKG

wechaty-puppet-padplus

Version:
212 lines 8.71 kB
"use strict"; 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const config_1 = require("../../config"); const schemas_1 = require("../../schemas"); const PadPlusServer_pb_1 = require("../../server-manager/proto-ts/PadPlusServer_pb"); const PRE = 'PadplusRoom'; class PadplusRoom { constructor(requestClient) { // 修改微信群名称 this.setTopic = (roomId, topic) => __awaiter(this, void 0, void 0, function* () { config_1.log.verbose(PRE, `setTopic(${roomId}, ${topic})`); const OpType = 'UPDATE'; const type = 'MOD_TOPIC'; const data = { OpType, content: topic, roomId, type, }; const res = yield this.requestClient.request({ apiType: PadPlusServer_pb_1.ApiType.ROOM_OPERATION, data, }); config_1.log.silly(PRE, `message : ${JSON.stringify(res)}`); return schemas_1.RequestStatus.Success; }); this.getRoomInfo = (roomId) => __awaiter(this, void 0, void 0, function* () { config_1.log.verbose(PRE, `getRoomInfo(${roomId})`); const data = { userName: roomId, }; yield this.requestClient.request({ apiType: PadPlusServer_pb_1.ApiType.GET_CONTACT, data, }); return true; }); this.getRoomMembers = (uin, roomId) => __awaiter(this, void 0, void 0, function* () { config_1.log.verbose(PRE, `getRoomMembers(${uin}, ${roomId})`); const OpType = 'UPDATE'; const type = 'GET_MEMBER'; const data = { OpType, content: '', roomId, type, }; yield this.requestClient.request({ apiType: PadPlusServer_pb_1.ApiType.ROOM_OPERATION, data, }); }); this.getRoomQrcode = (roomId) => __awaiter(this, void 0, void 0, function* () { config_1.log.verbose(PRE, `getRoomQrcode(${roomId})`); const data = { roomId, }; const res = yield this.requestClient.request({ apiType: PadPlusServer_pb_1.ApiType.GET_ROOM_QRCODE, data, }); if (res) { const roomQrcodeDataStr = res.getData(); if (roomQrcodeDataStr) { const roomQrcodeData = JSON.parse(roomQrcodeDataStr); return roomQrcodeData.qrcodeBuf; } else { throw new Error(`can not parse room qrcode data from grpc`); } } else { throw new Error(`can not get room qrcode response from grpc server`); } }); this.setAnnouncement = (roomId, announcement) => __awaiter(this, void 0, void 0, function* () { config_1.log.verbose(PRE, `setAnnouncement(${roomId},${announcement})`); const data = { announcement, wxid: roomId, }; const res = yield this.requestClient.request({ apiType: PadPlusServer_pb_1.ApiType.SET_ROOM_ANNOUNCEMENT, data, }); if (res) { const announcementDataStr = res.getData(); if (announcementDataStr) { const announcementData = JSON.parse(announcementDataStr); if (announcementData.status !== 0) { // status: -2025 '仅群主可编辑群公告。' throw new Error(`set announcement failed.`); } return announcementData.content; } else { throw new Error(`can not parse announcement data from grpc`); } } else { throw new Error(`can not get announcement response from grpc server`); } }); this.getAnnouncement = (roomId) => __awaiter(this, void 0, void 0, function* () { config_1.log.verbose(PRE, `setAnnouncement(${roomId})`); const data = { wxid: roomId, }; const res = yield this.requestClient.request({ apiType: PadPlusServer_pb_1.ApiType.GET_ROOM_ANNOUNCEMENT, data, }); if (res) { const announcementDataStr = res.getData(); if (announcementDataStr) { const announcementData = JSON.parse(announcementDataStr); return announcementData.announcement; } else { throw new Error(`can not parse announcement data from grpc`); } } else { throw new Error(`can not get announcement response from grpc server`); } }); this.addMember = (roomId, memberId) => __awaiter(this, void 0, void 0, function* () { config_1.log.verbose(PRE, `addMember(${roomId},${memberId})`); const data = { OpType: 'UPDATE', content: memberId, roomId, type: 'ADD_MEMBER', }; yield this.requestClient.request({ apiType: PadPlusServer_pb_1.ApiType.ROOM_OPERATION, data, }); return schemas_1.RequestStatus.Success; }); this.createRoom = (topic, memberIdList) => __awaiter(this, void 0, void 0, function* () { config_1.log.verbose(PRE, `createRoom(${topic},memberIds${memberIdList.join(',')})`); const data = { memberList: memberIdList, topic, }; const res = yield this.requestClient.request({ apiType: PadPlusServer_pb_1.ApiType.CREATE_ROOM, data, }); if (res) { const roomDataStr = res.getData(); if (roomDataStr) { const roomData = JSON.parse(roomDataStr); if (roomData.roomId) { return roomData.roomId; } else { throw new Error(`can not create room by member: ${JSON.stringify(roomData.createMessage)}`); } } else { throw new Error(`can not parse room data from grpc`); } } else { throw new Error(`can not get response from grpc server`); } }); this.quitRoom = (roomId) => __awaiter(this, void 0, void 0, function* () { config_1.log.verbose(PRE, `quitRoom(${roomId})`); const data = { OpType: 'UPDATE', roomId, type: 'DEL_CHAT_ROOM', }; yield this.requestClient.request({ apiType: PadPlusServer_pb_1.ApiType.ROOM_OPERATION, data, }); return schemas_1.RequestStatus.Success; }); this.requestClient = requestClient; } deleteRoomMember(roomId, contactId) { return __awaiter(this, void 0, void 0, function* () { config_1.log.verbose(PRE, `deleteRoomMember(${roomId}, ${contactId})`); const OpType = 'UPDATE'; const type = 'DEL_MEMBER'; const data = { OpType, content: contactId, roomId, type, }; yield this.requestClient.request({ apiType: PadPlusServer_pb_1.ApiType.ROOM_OPERATION, data, }); }); } } exports.PadplusRoom = PadplusRoom; //# sourceMappingURL=room.js.map