hennus-api
Version:
Esta es una libreria para el bot Hennus
98 lines (97 loc) • 2.91 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChannelsManager = void 0;
const base_1 = require("./base");
const v10_1 = require("discord-api-types/v10");
const functions_1 = require("../functions");
class ChannelsManager extends base_1.cacheManager {
constructor(client) {
super(client);
}
;
async setall(map) {
if (map && Array.isArray(map)) {
map.forEach((channel) => {
if (channel)
this.cache.set(channel.id, channel);
});
return true;
}
else {
return false;
}
}
update(channel) {
if (this.cache.has(channel.id)) {
this.cache.delete(channel.id);
this.cache.set(channel.id, channel);
}
else {
this.cache.set(channel.id, channel);
}
;
return this.cache;
}
;
search(guildId) {
const map = this.cache.filter((x) => { if (!x.isChannelDm() && x.guildId == guildId)
return x; return undefined; }).filter((x) => x != undefined);
return map;
}
;
async fetchall(guildId) {
let channels = await this.rest.get("guildChannels", guildId);
if (channels && Array.isArray(channels))
channels.forEach((channel) => {
if (!this.resolve(channel))
this.cache.set(channel.id, channel);
});
return this.cache;
}
;
async createGuildChannel(guild_id, data) {
try {
const channel = await this.client.rest.api.post(v10_1.Routes.guildChannels(guild_id), { body: data });
if (!channel)
return undefined;
if (channel instanceof Error)
throw channel;
return (0, functions_1.channelConvertidor)(channel, this.client);
}
catch (error) {
console.error("Error creating guild channel:", error);
return undefined;
}
}
async delete(id) {
this.client.rest.api.delete(v10_1.Routes.channel(id));
if (this.cache.has(id)) {
return this.resolve(id);
}
else
return undefined;
}
;
async edit(id, body) {
const channel = await this.client.rest.api.patch(v10_1.Routes.channel(id), { body });
if (!channel)
return undefined;
if (channel instanceof Error)
throw channel;
return (0, functions_1.channelConvertidor)(channel, this.client);
}
;
async fetch(id, force) {
const cache = this.cache.get(id);
if (!force)
return cache;
let channel = await this.rest.get("channel", id);
if (channel)
return channel;
else
return undefined;
}
;
}
exports.ChannelsManager = ChannelsManager;
;