Skip to content

Commit

Permalink
Fix DM permission issues
Browse files Browse the repository at this point in the history
  • Loading branch information
SunburntRock89 committed May 21, 2023
1 parent 09d7b13 commit db8cf73
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ src/config/config-*.ts
.env

.vscode/

Git-Exclude/
47 changes: 25 additions & 22 deletions src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,31 +191,34 @@ export default async(client: DTelClient, _interaction: Interaction): Promise<voi
const processorClass = new processorFile(client, interaction, commandData);
try {
const userPermissions = await client.getPerms(interaction.user.id);
switch (permissionLevel) {
case PermissionLevel.maintainer: {
if (userPermissions != PermissionLevel.maintainer) {
processorClass.notMaintainer();
return;
}
break;
}
case PermissionLevel.customerSupport: {
if (userPermissions as number < PermissionLevel.customerSupport) {
processorClass.permCheckFail();
return;
// Bypass checks if ran by a maintainer
if (userPermissions != PermissionLevel.maintainer) {
switch (permissionLevel) {
case PermissionLevel.maintainer: {
if (userPermissions != PermissionLevel.maintainer) {
processorClass.notMaintainer();
return;
}
break;
}
if (interaction.guildId !== config.supportGuild.id && !config.devMode) {
processorClass.notInSupportGuild();
return;
case PermissionLevel.customerSupport: {
if (userPermissions as number < PermissionLevel.customerSupport) {
processorClass.permCheckFail();
return;
}
if (interaction.guildId !== config.supportGuild.id && !config.devMode) {
processorClass.notInSupportGuild();
return;
}
break;
}
break;
}
case PermissionLevel.serverAdmin: {
if (!(interaction.member!.permissions as PermissionsBitField).has(PermissionsBitField.Flags.ManageGuild)) {
processorClass.permCheckFail();
return;
case PermissionLevel.serverAdmin: {
if (!(interaction.member!.permissions as PermissionsBitField).has(PermissionsBitField.Flags.ManageGuild)) {
processorClass.permCheckFail();
return;
}
break;
}
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/internals/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class Processor<T extends ChannelBasedInteraction> {

async getPerms(userID = this.interaction.user.id): Promise<PermissionLevel> {
let userPermissions = await this.client.getPerms(userID) as PermissionLevel;
const isServerAdmin = (this.interaction.member!.permissions as PermissionsBitField).has(PermissionsBitField.Flags.ManageGuild);
const isServerAdmin = this.interaction.channel?.isDMBased() || (this.interaction.member!.permissions as PermissionsBitField).has(PermissionsBitField.Flags.ManageGuild);

if (isServerAdmin && userPermissions as number < PermissionLevel.customerSupport) {
userPermissions = PermissionLevel.serverAdmin;
Expand Down

0 comments on commit db8cf73

Please sign in to comment.