UNPKG

seyfert

Version:

The most advanced framework for discord bots

92 lines (91 loc) 3.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EntryPointContext = void 0; const types_1 = require("../../types"); const basecontext_1 = require("../basecontext"); class EntryPointContext extends basecontext_1.BaseContext { client; interaction; shardId; command; constructor(client, interaction, shardId, command) { super(client); this.client = client; this.interaction = interaction; this.shardId = shardId; this.command = command; } metadata = {}; globalMetadata = {}; get t() { return this.client.t(this.interaction.locale ?? this.client.langs.defaultLang ?? 'en-US'); } get fullCommandName() { return this.command.name; } write(body, withResponse) { return this.interaction.write(body, withResponse); } modal(body) { return this.interaction.modal(body); } deferReply(ephemeral = false, withResponse) { return this.interaction.deferReply(ephemeral ? types_1.MessageFlags.Ephemeral : undefined, withResponse); } editResponse(body) { return this.interaction.editResponse(body); } deleteResponse() { return this.interaction.deleteResponse(); } editOrReply(body, withResponse) { return this.interaction.editOrReply(body, withResponse); } fetchResponse() { return this.interaction.fetchResponse(); } channel(mode = 'flow') { if (this.interaction.channel && mode === 'cache') return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel; return this.client.channels.fetch(this.channelId, mode === 'rest'); } me(mode = 'flow') { if (!this.guildId) return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve(); switch (mode) { case 'cache': return this.client.cache.members?.get(this.client.botId, this.guildId); default: return this.client.members.fetch(this.guildId, this.client.botId, mode === 'rest'); } } guild(mode = 'flow') { if (!this.guildId) return (mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve()); switch (mode) { case 'cache': return this.client.cache.guilds?.get(this.guildId); default: return this.client.guilds.fetch(this.guildId, mode === 'rest'); } } get guildId() { return this.interaction.guildId; } get channelId() { return this.interaction.channel.id; } get author() { return this.interaction.user; } get member() { return this.interaction.member; } isEntryPoint() { return true; } inGuild() { return !!this.guildId; } } exports.EntryPointContext = EntryPointContext;