Differentiate between checking if a user is banned by user or id
This commit is contained in:
parent
7fbc7f4308
commit
aec01905b5
|
@ -54,7 +54,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
|||
// instead because all of this is used in src/main.ts
|
||||
try {
|
||||
// If the user is banned in this guild, don't let them post
|
||||
if (dt.isBanned(interaction.guild?.id!, interaction.user.id)) {
|
||||
if (dt.isBannedByUser(interaction.guild?.id!, interaction.user.id)) {
|
||||
return interaction.reply({
|
||||
content: "You are banned from confessions in this server!",
|
||||
ephemeral: true
|
||||
|
|
|
@ -67,7 +67,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
|||
if (interaction.options.getSubcommand() === "ban") {
|
||||
const confessionId = interaction.options.getString("id")!;
|
||||
|
||||
if (dt.isBanned(guildId, confessionId)) {
|
||||
if (dt.isBannedById(guildId, confessionId)) {
|
||||
try {
|
||||
return interaction.reply({
|
||||
content: "That user is already banned!",
|
||||
|
|
|
@ -97,7 +97,7 @@ BotClient.on(Events.InteractionCreate, async interaction => {
|
|||
|
||||
if (requestSubmit) {
|
||||
// Check if the user is banned from confessions before showing the modal
|
||||
dt.isBanned(interaction.guild?.id!, interaction.user.id)
|
||||
dt.isBannedByUser(interaction.guild?.id!, interaction.user.id)
|
||||
? interaction.reply({
|
||||
content: "You are banned from confessions in this server!",
|
||||
ephemeral: true
|
||||
|
@ -118,7 +118,7 @@ BotClient.on(Events.InteractionCreate, async interaction => {
|
|||
);
|
||||
|
||||
try {
|
||||
if (dt.isBanned(interaction.guild?.id!, interaction.user.id)) {
|
||||
if (dt.isBannedByUser(interaction.guild?.id!, interaction.user.id)) {
|
||||
return interaction.reply({
|
||||
content: "You are banned from confessions in this server!",
|
||||
ephemeral: true
|
||||
|
|
|
@ -135,7 +135,7 @@ export class StoreMan {
|
|||
for (const guild of this.data) {
|
||||
if (guild.id === guildId) {
|
||||
// If the author's user ID is in the ban list, don't let them post a confession.
|
||||
if (this.isBanned(guildId, author)) {
|
||||
if (this.isBannedByUser(guildId, author)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ export class StoreMan {
|
|||
}
|
||||
|
||||
// Check if a certain user is banned within a guild.
|
||||
public isBanned(guildId: string, userId: string): boolean {
|
||||
public isBannedByUser(guildId: string, userId: string): boolean {
|
||||
for (const guild of this.data) {
|
||||
if (guild.id === guildId) {
|
||||
for (const ban of guild.settings.bans) {
|
||||
|
@ -229,6 +229,20 @@ export class StoreMan {
|
|||
return false;
|
||||
}
|
||||
|
||||
public isBannedById(guildId: string, confessionId: string): boolean {
|
||||
for (const guild of this.data) {
|
||||
if (guild.id === guildId) {
|
||||
for (const ban of guild.settings.bans) {
|
||||
if (ban.confessionId === confessionId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public getBans(guildId: string): ConfessionBan[] {
|
||||
for (const guild of this.data) {
|
||||
if (guild.id === guildId) {
|
||||
|
@ -247,7 +261,7 @@ export class StoreMan {
|
|||
if (guild.id === guildId) {
|
||||
if (confession) {
|
||||
// Only add the user to the ban list if they aren't banned already
|
||||
!this.isBanned(guildId, confession.authorId) &&
|
||||
!this.isBannedByUser(guildId, confession.authorId) &&
|
||||
guild.settings.bans.push({
|
||||
user: confession.authorId,
|
||||
confessionId: confessionId
|
||||
|
|
Loading…
Reference in a new issue