UNPKG

nodevk-ts

Version:

Simple Node.js module that allows you to interact with the VKontakte API.

47 lines (46 loc) 1.53 kB
import API from "./api.js"; class GroupsAPI extends API { constructor() { super(...arguments); this.api_name = "groups"; } async getMembers(group_id, params = {}) { const method = this.api_name + ".getMembers"; params.group_id = group_id; return await this.call(method, params); } async isMembers(group_id, users_ids, extended = false) { const method = this.api_name + ".isMember"; const is_array = Array.isArray(users_ids); let params = { group_id: group_id }; if (is_array) params.user_ids = users_ids; else params.user_id = users_ids; if (extended) params.extended = 1; return await this.call(method, params); } /** * WARNING! This method uses the getMembers method and goes through ALL users of the group. */ async isDonut(group_id, users_id) { const startUsers = await this.getMembers(group_id, { filter: "donut" }); const countUsers = startUsers.count; let iUsers = 1000; let users = startUsers.items; do { if (users.indexOf(users_id) != -1) return true; users = (await this.getMembers(group_id, { filter: "donut", offset: iUsers })).items; iUsers += 1000; } while (iUsers < countUsers); return false; } } export default GroupsAPI;