UNPKG

node-groupme

Version:

The only GroupMe API library that isn't a million years old.

90 lines 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const __1 = require(".."); class Group extends __1.BaseGroup { constructor(client, data) { super(client, data); this.type = __1.ChannelType.Group; this.messages = new __1.GroupMessageManager(client, this); this.polls = new __1.PollManager(client, this); } async send(text) { const body = { message: { text, attachments: [], source_guid: this.client.rest.guid(), }, }; const response = await this.client.rest.api('POST', `groups/${this.id}/messages`, { body, }); const message = new __1.GroupMessage(this.client, this, response.message); return this.messages._upsert(message); } fetch() { return this.client.groups.fetch(this.id); } async update(options) { const body = options; const response = await this.client.rest.api('POST', `groups/${this.id}/update`, { body }); const group = new Group(this.client, response); return this.client.groups._upsert(group); } async transferOwnershipTo(newOwner) { const body = { requests: [ { group_id: this.id, owner_id: newOwner, }, ], }; const response = await this.client.rest.api('POST', 'groups/change_owners', { body }); const status = response.results[0].status; let errorMessage = ''; switch (status) { case '200': return this.fetch(); case '400': errorMessage = 'You cannot transfer a group to yourself.'; break; case '403': errorMessage = 'You cannot transfer a group you do not own.'; break; case '404': errorMessage = 'Group not found, or new owner is not a member of the group.'; break; case '405': errorMessage = 'Invalid request; Request object is missing a required field, or one of the required fields is not an ID.'; break; default: errorMessage = "Idk what this status code means, but it's probably an error. It wasn't on the docs and I've never seen it before. Please report this to the developers of node-groupme and/or the GroupMe API!"; break; } const err = { statusCode: status, message: errorMessage, groupId: this.id, groupName: this.name, newOwner: newOwner, }; throw err; // Failed to transfer group, see error details } async delete() { await this.client.rest.api('POST', `groups/${this.id}/destroy`); } changeNickname(nickname) { throw new Error('Method not implemented.'); } leave() { throw new Error('Method not implemented.'); } get me() { return this.members.cache.get(this.client.user.id); } } exports.default = Group; //# sourceMappingURL=Group.js.map