hennus-api
Version:
Esta es una libreria para el bot Hennus
150 lines (149 loc) • 4.97 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseChannel = void 0;
const v10_1 = require("discord-api-types/v10");
const snowflake_1 = require("@sapphire/snowflake");
const data_1 = require("./data");
const bitfield_1 = require("../bitfield");
class BaseChannel extends data_1.BaseData {
constructor(_data, client) {
super(client);
this._data = _data;
this.id = "";
this.name = "";
this._data = _data;
Object.defineProperty(this, "_data", { value: _data });
this.id = this._data.id;
this.name = this._data.name ?? "";
this.flags = new bitfield_1.channelFlags(this._data.flags).freeze;
this.type = this._data.type;
}
;
get createdTimestamp() {
return snowflake_1.DiscordSnowflake.timestampFrom(this.id);
}
;
get createdAt() {
return new Date(this.createdTimestamp);
}
;
async delete() {
await this.client.rest.api.delete(v10_1.Routes.channel(this.id));
return this;
}
;
isChannelText() {
if (this.type == v10_1.ChannelType.GuildAnnouncement || this.type == v10_1.ChannelType.GuildText)
return true;
return false;
}
;
isChannelDm() {
if (this.type == v10_1.ChannelType.DM || this.type == v10_1.ChannelType.GroupDM)
return true;
return false;
}
;
isChannelVoice() {
if (this.type == v10_1.ChannelType.GuildVoice || this.type == v10_1.ChannelType.GuildStageVoice)
return true;
return false;
}
;
isChannelCategory() {
if (this.type == v10_1.ChannelType.GuildCategory)
return true;
return false;
}
;
isChannelForum() {
if (this.type == v10_1.ChannelType.GuildForum)
return true;
return false;
}
;
isChannelthread() {
if (this.type == v10_1.ChannelType.PublicThread || this.type == v10_1.ChannelType.PrivateThread || this.type == v10_1.ChannelType.AnnouncementThread)
return true;
return false;
}
;
async send(options) {
if (this.type == v10_1.ChannelType.GuildCategory)
return undefined;
const id = (this._data ?? this.data).id;
const mData = {
content: undefined,
embeds: undefined,
components: undefined,
};
let data = undefined;
if (typeof options === 'string') {
mData.content = options;
data = mData;
}
else if (typeof options == "object") {
if (options.components && Array.isArray(options.components))
mData.components = options.components;
if (options.embeds && Array.isArray(options.embeds))
mData.embeds = options.embeds;
if (options.content)
mData.content = options.content;
if (options.attachments) {
data = { files: [], body: undefined };
const from = [];
for (let i = 0; i < options.attachments.length; i++) {
const attach = options.attachments[i];
let contentType = "";
let _buffer = undefined;
let name = `default${i}.txt`;
if (typeof attach.attachment == "string") {
const imagen = await this.imagen(attach.attachment);
if (imagen) {
const buffer = Buffer.from(imagen.data, 'binary');
_buffer = buffer;
name = attach.name ?? `default.${imagen.type}`;
contentType = imagen.content_type;
}
;
}
else {
_buffer = attach.attachment;
name = attach.name ?? `default${i}.txt`;
}
;
if (_buffer)
from.push({
data: _buffer,
name,
contentType
});
}
;
data.body = mData;
data.files = from;
}
else {
data = mData;
}
;
}
;
const msg = await this.client.rest.post("channelMessages", data, id);
if (msg instanceof Error)
throw msg;
if (msg && typeof options == "object" && typeof options.timeout == "number")
setTimeout(() => msg.delete().catch(() => undefined), options.timeout);
return msg;
}
;
toString() {
if (this.id)
return `<#${this.id}>`;
else
return "";
}
;
}
exports.BaseChannel = BaseChannel;
;