Skip to content

Commit

Permalink
[PATCH] filter user/channel/role if deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Larsundso committed Dec 28, 2023
1 parent e0cc273 commit 4ba71ff
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "module",
"version": "2.0.13",
"version": "2.0.14",
"scripts": {
"start": "node --max-old-space-size=8192 ./dist/index.js",
"build": "npx tsc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default <T extends keyof typeof CT.SettingsName2TableName>(
id: string;
type: Discord.SelectMenuDefaultValueType;
}[],
guild: Discord.Guild,
channelType?: 'text' | 'voice' | 'category',
) => {
const menu:
Expand All @@ -26,7 +27,20 @@ export default <T extends keyof typeof CT.SettingsName2TableName>(
custom_id: `settings/${type}_${fieldName}_${String(settingName)}${
uniquetimestamp ? `_${uniquetimestamp}` : ''
}`,
default_values: values.filter((v) => !!v.id) as never,
default_values: values.filter((v) => {
if (!v.id) return false;

switch (v.type) {
case Discord.SelectMenuDefaultValueType.Channel:
return guild.channels.cache.has(v.id);
case Discord.SelectMenuDefaultValueType.Role:
return guild.roles.cache.has(v.id);
case Discord.SelectMenuDefaultValueType.User:
return guild.members.cache.has(v.id);
default:
return true;
}
}) as never,
type: getChangeSelectType(type),
placeholder: getPlaceholder(type, language),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default async (cmd: Discord.ButtonInteraction, args: string[]) => {
},
]
: [],
cmd.guild,
),
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default async (cmd: Discord.ButtonInteraction, args: string[]) => {
rule.exemptChannels
.map((c) => c.id)
.map((o) => ({ id: o, type: Discord.SelectMenuDefaultValueType.Channel })),
cmd.guild,
),
],
},
Expand Down
1 change: 1 addition & 0 deletions src/Commands/ButtonCommands/settings/autoModRule/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default async (cmd: Discord.ButtonInteraction, args: string[]) => {
rule.exemptRoles
.map((c) => c.id)
.map((o) => ({ id: o, type: Discord.SelectMenuDefaultValueType.Role })),
cmd.guild,
),
],
},
Expand Down
1 change: 1 addition & 0 deletions src/Commands/ButtonCommands/settings/editors/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default async (
id: o,
type: Discord.SelectMenuDefaultValueType.Channel,
})),
cmd.guild,
channelTypes,
),
],
Expand Down
1 change: 1 addition & 0 deletions src/Commands/ButtonCommands/settings/editors/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default async (cmd: Discord.ButtonInteraction, args: string[]) => {
id: o,
type: Discord.SelectMenuDefaultValueType.Channel,
})),
cmd.guild,
),
],
},
Expand Down
1 change: 1 addition & 0 deletions src/Commands/ButtonCommands/settings/editors/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default async (cmd: Discord.ButtonInteraction, args: string[]) => {
id: o,
type: Discord.SelectMenuDefaultValueType.Channel,
})),
cmd.guild,
),
],
},
Expand Down
1 change: 1 addition & 0 deletions src/Commands/ButtonCommands/settings/editors/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default async (cmd: Discord.ButtonInteraction, args: string[]) => {
id: o,
type: Discord.SelectMenuDefaultValueType.Channel,
})),
cmd.guild,
),
],
},
Expand Down
1 change: 1 addition & 0 deletions src/Commands/ButtonCommands/settings/editors/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default async (cmd: Discord.ButtonInteraction, args: string[]) => {
id: o,
type: Discord.SelectMenuDefaultValueType.Channel,
})),
cmd.guild,
),
],
},
Expand Down
1 change: 1 addition & 0 deletions src/Commands/ButtonCommands/settings/editors/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default async (cmd: Discord.ButtonInteraction, args: string[]) => {
id: o,
type: Discord.SelectMenuDefaultValueType.Channel,
})),
cmd.guild,
),
],
},
Expand Down
1 change: 1 addition & 0 deletions src/Commands/ButtonCommands/settings/editors/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default async (cmd: Discord.ButtonInteraction, args: string[]) => {
id: o,
type: Discord.SelectMenuDefaultValueType.Channel,
})),
cmd.guild,
),
],
},
Expand Down

0 comments on commit 4ba71ff

Please sign in to comment.