@wilcosp/rex
Version:
Rex is an automated command manager for discord js
118 lines (117 loc) • 3.16 kB
JavaScript
/*!
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { ChannelType } from "discord-api-types/v10";
export class RexInteractionBase {
constructor(inter) {
this.inter = inter;
}
get appPermissions() {
return this.inter.appPermissions;
}
get channel() {
return this.inter.channel;
}
get channelId() {
return this.inter.channelId;
}
get client() {
return this.inter.client;
}
get createdAt() {
return this.inter.createdAt;
}
get createdTimestamp() {
return this.inter.createdTimestamp;
}
get guild() {
return this.inter.guild;
}
get guildId() {
return this.inter.guildId;
}
get guildLocale() {
return this.inter.guildLocale;
}
get id() {
return this.inter.id;
}
get member() {
return this.inter.member;
}
get memberPermissions() {
return this.inter.memberPermissions;
}
get token() {
return this.inter.token;
}
get user() {
return this.inter.user;
}
get locale() {
return this.inter.locale;
}
inGuild() {
return this.inter.inGuild();
}
inCachedGuild() {
return this.inter.inCachedGuild();
}
inRawGuild() {
return this.inter.inRawGuild();
}
toString() {
return this.inter.toString();
}
toJSON(...props) {
return this.inter.toJSON(...props);
}
async fetchChannel() {
if (this.inter.channel) {
return this.inter.channel;
}
if (this.inter.channelId) {
return this.inter.client.channels.fetch(this.inter.channelId).then(channel => {
if (channel?.isTextBased()) {
return channel;
}
throw new TypeError("CHANNEL_NOT_FOUND_OR_NOT_TEXT");
});
}
throw new TypeError("NO_CHANNEL_ID");
}
async inNSFWChannel(DMisNsfw = false) {
if (!this.inter.inGuild()) {
return DMisNsfw;
}
const channel = await this.fetchChannel().catch(() => null);
if (!channel) {
return false;
}
switch (channel.type) {
case ChannelType.DM:
case ChannelType.GroupDM: {
return DMisNsfw;
}
case ChannelType.GuildCategory:
case ChannelType.GuildStageVoice: {
return false;
}
case ChannelType.GuildText:
case ChannelType.GuildNews:
case ChannelType.GuildVoice:
case ChannelType.GuildForum: {
return channel.nsfw;
}
case ChannelType.GuildPublicThread:
case ChannelType.GuildNewsThread:
case ChannelType.GuildPrivateThread: {
return channel.parent?.nsfw ?? false;
}
default:
return false;
}
}
}