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