refactor(db): rename functions for better readability

This commit is contained in:
smyalygames 2023-02-16 16:09:56 +00:00
parent f3fa1398e8
commit 319049bc2b
6 changed files with 14 additions and 14 deletions

View File

@ -27,7 +27,7 @@ import type {
} from 'discord.js';
import { EmbedBuilder } from 'discord.js';
import IDs from '#utils/ids';
import { addBan, checkActive } from '#utils/database/ban';
import { addBan, checkBan } from '#utils/database/ban';
import { addEmptyUser, updateUser, userExists } from '#utils/database/dbExistingUser';
export class BanCommand extends Command {
@ -149,7 +149,7 @@ export class BanCommand extends Command {
return info;
}
if (await checkActive(userId)) {
if (await checkBan(userId)) {
info.message = `${user} is already banned!`;
return info;
}

View File

@ -28,7 +28,7 @@ import type {
} from 'discord.js';
import { EmbedBuilder } from 'discord.js';
import IDs from '#utils/ids';
import { removeBan, checkActive, addBan } from '#utils/database/ban';
import { removeBan, checkBan, addBan } from '#utils/database/ban';
import { addEmptyUser, addExistingUser, userExists } from '#utils/database/dbExistingUser';
export class UnbanCommand extends Command {
@ -138,7 +138,7 @@ export class UnbanCommand extends Command {
user = await guild.client.users.fetch(userId) as User;
}
if (!await checkActive(userId)) {
if (!await checkBan(userId)) {
let ban: GuildBan;
try {
ban = await guild.bans.fetch(userId);

View File

@ -20,7 +20,7 @@
import { Listener } from '@sapphire/framework';
import type { GuildBan } from 'discord.js';
import { AuditLogEvent, EmbedBuilder, TextChannel } from 'discord.js';
import { addBan, checkActive } from '#utils/database/ban';
import { addBan, checkBan } from '#utils/database/ban';
import IDs from '#utils/ids';
import { addEmptyUser, addExistingUser, userExists } from '#utils/database/dbExistingUser';
@ -33,7 +33,7 @@ export class BanListener extends Listener {
}
public async run(ban: GuildBan) {
if (await checkActive(ban.user.id)) {
if (await checkBan(ban.user.id)) {
return;
}
@ -94,7 +94,7 @@ export class BanListener extends Listener {
await addExistingUser(mod);
}
if (await checkActive(user.id)) {
if (await checkBan(user.id)) {
this.container.logger.error('BanListener: got past the checkActive at the start.');
return;
}

View File

@ -19,7 +19,7 @@
import { Listener } from '@sapphire/framework';
import type { GuildMember } from 'discord.js';
import { checkActive, getReason } from '#utils/database/ban';
import { checkBan, getBanReason } from '#utils/database/ban';
export class BanJoinListener extends Listener {
public constructor(context: Listener.Context, options: Listener.Options) {
@ -31,12 +31,12 @@ export class BanJoinListener extends Listener {
public async run(user: GuildMember) {
// Check if the user is banned
if (!await checkActive(user.id)) {
if (!await checkBan(user.id)) {
return;
}
// Get reason from database
const reason = await getReason(user.id);
const reason = await getBanReason(user.id);
// Send DM for ban reason
await user.send(`You have been banned from ARA for: ${reason}`

View File

@ -20,7 +20,7 @@
import { Listener } from '@sapphire/framework';
import type { GuildBan } from 'discord.js';
import { AuditLogEvent, EmbedBuilder, TextChannel } from 'discord.js';
import { addBan, checkActive, removeBan } from '#utils/database/ban';
import { addBan, checkBan, removeBan } from '#utils/database/ban';
import IDs from '#utils/ids';
import { addEmptyUser, addExistingUser, userExists } from '#utils/database/dbExistingUser';
@ -86,7 +86,7 @@ export class UnbanListener extends Listener {
}
// Check for missing ban on database
if (!await checkActive(user.id)) {
if (!await checkBan(user.id)) {
// Check if user and mod are on the database
if (!await userExists(user.id)) {
await addEmptyUser(user.id);

View File

@ -46,7 +46,7 @@ export async function removeBan(userId: string, modId: string) {
});
}
export async function checkActive(userId: string) {
export async function checkBan(userId: string) {
const ban = await container.database.ban.findFirst({
where: {
userId,
@ -63,7 +63,7 @@ export async function checkActive(userId: string) {
return ban.active;
}
export async function getReason(userId: string) {
export async function getBanReason(userId: string) {
const ban = await container.database.ban.findFirst({
where: {
userId,