kyodo.dorks
Version:
TypeScript API wrapper for Kyodo: Communities & Chats
132 lines (131 loc) • 6.11 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DorksChatManager = void 0;
const basic_1 = require("../schemas/responses/basic");
const impl_1 = require("../schemas/responses/impl");
const crypt_1 = require("../utils/crypt");
const exceptions_1 = require("../utils/exceptions");
class DorksChatManager {
constructor(config, httpWorkflow) {
this.endpoint = '/v1/g/s';
this.__editChatBuilder = async (chatId, jsonPayload) => {
return await this.httpWorkflow.sendXSigPost({
path: `${this.endpoint}/chats/${chatId}`,
body: jsonPayload
}, basic_1.BasicResponseSchema);
};
this.get = async (id) => {
return (await this.httpWorkflow.sendGet({
path: `${this.endpoint}/chats/${id}`
}, impl_1.GetChatResponseSchema)).chat;
};
this.create = async (name, icon, invitedIds = []) => {
return (await this.httpWorkflow.sendXSigPost({
path: `${this.endpoint}/chats`,
body: JSON.stringify({ name, icon, invitedIds, type: 2 })
}, impl_1.GetChatResponseSchema)).chat;
};
this.createGroup = async (invitedIds, type = 1) => {
return (await this.httpWorkflow.sendXSigPost({
path: `${this.endpoint}/chats`,
body: JSON.stringify({ invitedIds, type })
}, impl_1.GetChatResponseSchema)).chat;
};
this.getMany = async (startLimit = { start: 0, limit: 20 }) => {
return (await this.httpWorkflow.sendGet({
path: `${this.endpoint}/chats?type=0&start=${startLimit.start}&limit=${startLimit.limit}`
}, impl_1.GetChatsResponseSchema)).chats;
};
this.getPublic = async (startLimit = { start: 0, limit: 10 }) => {
if (!this.config.enviroment.circleId)
exceptions_1.KyodoDorksAPIError.throw(1);
return (await this.httpWorkflow.sendGet({
path: `${this.endpoint}/chats/feed?type=hottest&start=${startLimit.start}&limit=${startLimit.limit}&status=0`
}, impl_1.GetChatsResponseSchema)).chats;
};
this.join = async (chatId) => {
return await this.httpWorkflow.sendXSigPost({
path: `${this.endpoint}/chats/${chatId}/join`,
body: JSON.stringify({})
}, basic_1.BasicResponseSchema);
};
this.leave = async (chatId, confirmAsHost = true) => {
return await this.httpWorkflow.sendXSigPost({
path: `${this.endpoint}/chats/${chatId}/leave`,
body: JSON.stringify({ confirmAsHost })
}, basic_1.BasicResponseSchema);
};
this.addCoHost = async (chatId, userId) => {
return await this.httpWorkflow.sendXSigPost({
path: `${this.endpoint}/chats/${chatId}/members/cohosts`,
body: JSON.stringify({ uid: userId })
}, basic_1.BasicResponseSchema);
};
this.transferHost = async (chatId, userId) => {
return await this.httpWorkflow.sendXSigPost({
path: `${this.endpoint}/chats/${chatId}/members/host-transfer`,
body: JSON.stringify({ uid: userId })
}, basic_1.BasicResponseSchema);
};
this.editName = async (chatId, name) => {
return await this.__editChatBuilder(chatId, JSON.stringify({ name }));
};
this.editContent = async (chatId, content) => {
return await this.__editChatBuilder(chatId, JSON.stringify({ content }));
};
this.editIcon = async (chatId, icon) => {
return await this.__editChatBuilder(chatId, JSON.stringify({ icon }));
};
this.editBackground = async (chatId, background) => {
return await this.__editChatBuilder(chatId, JSON.stringify({ background }));
};
this.editReadOnly = async (chatId) => {
return await this.httpWorkflow.sendXSigPost({
path: `${this.endpoint}/chats/${chatId}/read-only`,
body: JSON.stringify({})
}, basic_1.BasicResponseSchema);
};
this.sendMessage = async (chatId, content, type = 0, replyMessageId) => {
return (await this.httpWorkflow.sendXSigPost({
path: `${this.endpoint}/chats/${chatId}/messages`,
body: JSON.stringify({
content,
config: {
type,
refId: (0, crypt_1.generateRandomValue)(),
replyMessageId
}
})
}, impl_1.SendMessageResponseSchema)).messageItem;
};
this.deleteMessage = async (chatId, messageId) => {
return await this.httpWorkflow.sendDelete({
path: `${this.endpoint}/chats/${chatId}/messages/${messageId}`
}, basic_1.BasicResponseSchema);
};
this.kick = async (chatId, userId) => {
return await this.httpWorkflow.sendDelete({
path: `${this.endpoint}/chats/${chatId}/members/${userId}`
}, basic_1.BasicResponseSchema);
};
this.amnesty = async (chatId, userId) => {
return await this.httpWorkflow.sendXSigPost({
path: `${this.endpoint}/chats/${chatId}/members/${userId}/unkick`,
body: JSON.stringify({})
}, basic_1.BasicResponseSchema);
};
this.invite = async (chatId, invitedIds) => {
return await this.httpWorkflow.sendXSigPost({
path: `${this.endpoint}/chats/${chatId}/members/invite`,
body: JSON.stringify({ invitedIds })
}, basic_1.BasicResponseSchema);
};
if (config.enviroment.circleId)
this.endpoint = `/v1/${config.enviroment.circleId}/s`;
this.config = config;
this.httpWorkflow = httpWorkflow;
}
;
}
exports.DorksChatManager = DorksChatManager;
;