hennus-api
Version:
Esta es una libreria para el bot Hennus
117 lines (116 loc) • 3.42 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Message = void 0;
const v10_1 = require("discord-api-types/v10");
const guild_1 = require("../guild");
const user_1 = require("../user");
const build_1 = require("../../build");
class Message {
constructor(message, client) {
this.message = message;
this.client = client;
if (message.guild_id)
this.guildId = message.guild_id;
if (message.channel_id)
this.channelId = message.channel_id;
const channel = client.channels.cache.get(this.channelId);
if (channel)
this.channel = channel;
if (!message.guild_id && channel && (channel.isChannelCategory() || channel.isChannelForum() || channel.isChannelText() || channel.isChannelVoice() || channel.isChannelthread()))
this.guildId = channel.guildId;
const guild = client.guilds.cache.get(this.guildId);
if (guild)
this.guild = guild;
}
;
get editedTimestamp() {
return this.message.edited_timestamp ?? "";
}
;
get id() {
return this.message.id;
}
;
get timestamp() {
return this.message.timestamp ?? "";
}
;
get tts() {
return this.message.tts ?? false;
}
;
get pinned() {
return this.message.pinned ?? false;
}
;
get embeds() {
return (this.message.embeds ?? []).map((x) => new build_1.EmbedBuilder(x));
}
;
get type() {
return this.message.type ?? 0;
}
;
get author() {
if (this.message.author)
return new user_1.User(this.message.author, this.client);
else if (this.member?.user)
return this.member.user;
else
return {};
}
;
get member() {
if (!this.message.member && this.author)
return this.guild.members.resolve(this.author.id);
else if (!this.message.member?.user && this.author)
return this.guild.members.resolve(this.author.id);
else
return new guild_1.GuildMember(this.message.member ?? {}, this.guild, this.client);
}
;
get content() {
return this.message.content;
}
;
get mention() {
return {
users: this.message.mentions.map((x) => new user_1.User(x, this.client)),
channels: this.message.mention_channels ?? [],
roles: this.message.mention_roles ?? [],
everyone: this.message.mention_everyone ?? false,
};
}
;
get components() {
return this.message.components ?? [];
}
;
get toJson() {
return this.message;
}
;
async delete() {
const data = await this.client.rest.api.delete(v10_1.Routes.channelMessage(this.channelId, this.id));
if (data instanceof Error)
throw data;
return data;
}
;
async edit(data) {
const msg = await this.client.rest.api.patch(v10_1.Routes.channelMessage(this.channelId, this.id), { body: data });
if (msg instanceof Error)
throw msg;
return msg;
}
;
async ping() {
const msg = await this.client.rest.api.put(v10_1.Routes.channelPin(this.channelId, this.id));
if (msg instanceof Error)
throw msg;
return msg;
}
;
}
exports.Message = Message;
;