Skip to content

Commit

Permalink
fix: interactions in dms. closes #504
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Nov 1, 2021
1 parent 9a9a5b4 commit 9f772e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/eventHandlers/InteractionHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ module.exports = class InteractionHandler extends require('../models/BaseEventHa
const match = this.#loadedCommands.find(c => c.command.name === interaction.commandName);
const customMatch = this.#customCommands
.find(c => c?.command?.name === interaction.commandName
&& c?.guildId === interaction.guild.id);
&& c?.guildId === interaction?.guild?.id);

const noAccess = (match?.elevated
&& !interaction.member.permissions.has(Permissions.MANAGE_GUILD, false))
Expand All @@ -298,7 +298,8 @@ module.exports = class InteractionHandler extends require('../models/BaseEventHa
return interaction.reply({ content: 'No Access', ephemeral: true });
}

const ctx = await this.settings.getCommandContext(interaction.channel, interaction.user);
const ctx = await this.settings
.getCommandContext(interaction.channel || interaction.user, interaction.user);
ctx.settings = this.settings;
ctx.ws = ws;
ctx.handler = this;
Expand Down
19 changes: 10 additions & 9 deletions src/settings/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,21 +353,21 @@ module.exports = class Database {
context.webhook = undefined;
}

if (context.tempCategory && channel.guild.channels.cache.has(context.tempCategory.trim())) {
context.tempCategory = channel.guild.channels.cache.get(context.tempCategory.trim());
if (context.tempCategory && channel?.guild.channels?.cache.has(context.tempCategory.trim())) {
context.tempCategory = channel?.guild.channels?.cache.get(context.tempCategory.trim());
} else {
context.tempCategory = undefined;
}

if (context.tempChannel && channel.guild.channels.cache.has(context.tempChannel.trim())) {
context.tempChannel = channel.guild.channels.cache.get(context.tempChannel.trim());
if (context.tempChannel && channel?.guild?.channels.cache.has(context.tempChannel.trim())) {
context.tempChannel = channel?.guild?.channels.cache.get(context.tempChannel.trim());
} else {
context.tempChannel = undefined;
}

if (context.lfgChannel) {
context.lfg = {};
context.lfg.pc = channel.guild.channels.cache.get(context.lfgChannel);
context.lfg.pc = channel?.guild?.channels.cache.get(context.lfgChannel);
delete context.lfgChannel;
}

Expand All @@ -383,7 +383,7 @@ module.exports = class Database {
if (!context.lfg) {
context.lfg = {};
}
context.lfg[platform] = channel.guild.channels.cache.get(context[`lfgChannel.${platform}`]);
context.lfg[platform] = channel?.guild?.channels.cache.get(context[`lfgChannel.${platform}`]);
delete context[`lfgChannel.${platform}`];
}
});
Expand All @@ -395,11 +395,12 @@ module.exports = class Database {
delete context.respond_to_settings;
}

if (typeof context.ephemerate === 'undefined') context.ephemerate = true;
if (channel instanceof Discord.User) context.ephemerate = false;
else if (typeof context.ephemerate === 'undefined') context.ephemerate = true;
else context.ephemerate = context.ephemerate === '1';

if (context.modRole && channel.guild) {
context.modRole = await channel.guild.roles.fetch(context.modRole);
if (context.modRole && channel?.guild) {
context.modRole = await channel?.guild.roles.fetch(context.modRole);
}
} else {
context = {
Expand Down

0 comments on commit 9f772e0

Please sign in to comment.