mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-11-02 08:27:40 +01:00
perf(arabot): remove unnecessary userExists checks
This commit is contained in:
parent
1870f75517
commit
c7af73cec2
@ -28,7 +28,7 @@ import type {
|
||||
import { EmbedBuilder } from 'discord.js';
|
||||
import IDs from '#utils/ids';
|
||||
import { addBan, checkBan } from '#utils/database/ban';
|
||||
import { addEmptyUser, updateUser, userExists } from '#utils/database/dbExistingUser';
|
||||
import { addEmptyUser, updateUser } from '#utils/database/dbExistingUser';
|
||||
import { checkTempBan, removeTempBan } from '#utils/database/tempBan';
|
||||
|
||||
export class BanCommand extends Command {
|
||||
@ -184,7 +184,7 @@ export class BanCommand extends Command {
|
||||
|
||||
// Ban the user
|
||||
await member.ban({ reason });
|
||||
} else if (!await userExists(userId)) {
|
||||
} else {
|
||||
await addEmptyUser(userId);
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ import type {
|
||||
import { EmbedBuilder, Message } from 'discord.js';
|
||||
import IDs from '#utils/ids';
|
||||
import { addTempBan, checkTempBan } from '#utils/database/tempBan';
|
||||
import { addEmptyUser, updateUser, userExists } from '#utils/database/dbExistingUser';
|
||||
import { addEmptyUser, updateUser } from '#utils/database/dbExistingUser';
|
||||
|
||||
export class TempBanCommand extends Command {
|
||||
public constructor(context: Command.Context, options: Command.Options) {
|
||||
@ -247,7 +247,7 @@ export class TempBanCommand extends Command {
|
||||
|
||||
// Ban the user
|
||||
await member.ban({ reason });
|
||||
} else if (!await userExists(userId)) {
|
||||
} else {
|
||||
await addEmptyUser(userId);
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ import { EmbedBuilder } from 'discord.js';
|
||||
import IDs from '#utils/ids';
|
||||
import { removeBan, checkBan, addBan } from '#utils/database/ban';
|
||||
import { checkTempBan, removeTempBan } from '#utils/database/tempBan';
|
||||
import { addEmptyUser, addExistingUser, userExists } from '#utils/database/dbExistingUser';
|
||||
import { addEmptyUser, addExistingUser } from '#utils/database/dbExistingUser';
|
||||
|
||||
export class UnbanCommand extends Command {
|
||||
public constructor(context: Command.Context, options: Command.Options) {
|
||||
@ -131,9 +131,7 @@ export class UnbanCommand extends Command {
|
||||
}
|
||||
|
||||
// Check if mod is in database
|
||||
if (!await userExists(modId)) {
|
||||
await addExistingUser(mod);
|
||||
}
|
||||
await addExistingUser(mod);
|
||||
|
||||
let user = guild.client.users.cache.get(userId);
|
||||
|
||||
@ -167,9 +165,7 @@ export class UnbanCommand extends Command {
|
||||
}
|
||||
|
||||
// Check if user and mod are on the database
|
||||
if (!await userExists(user.id)) {
|
||||
await addEmptyUser(user.id);
|
||||
}
|
||||
await addEmptyUser(user.id);
|
||||
|
||||
// Add missing ban
|
||||
await addBan(userId, modId, `(Mod who banned is not accurate) - ${reason}`);
|
||||
|
||||
@ -37,12 +37,7 @@ import type {
|
||||
Snowflake,
|
||||
} from 'discord.js';
|
||||
import IDs from '#utils/ids';
|
||||
import {
|
||||
addEmptyUser,
|
||||
updateUser,
|
||||
userExists,
|
||||
fetchRoles,
|
||||
} from '#utils/database/dbExistingUser';
|
||||
import { addEmptyUser, updateUser, fetchRoles } from '#utils/database/dbExistingUser';
|
||||
import { restrict, checkActive } from '#utils/database/restriction';
|
||||
import { randint } from '#utils/maths';
|
||||
|
||||
@ -220,9 +215,8 @@ export async function restrictRun(
|
||||
IDs.roles.nonvegan.convinced,
|
||||
IDs.roles.nonvegan.vegCurious,
|
||||
]);
|
||||
} else if (!await userExists(userId)) {
|
||||
await addEmptyUser(userId);
|
||||
} else {
|
||||
await addEmptyUser(userId);
|
||||
const dbRoles = await fetchRoles(userId);
|
||||
if (dbRoles.includes(IDs.roles.vegan.vegan)) {
|
||||
section = 5;
|
||||
|
||||
@ -27,7 +27,7 @@ import type {
|
||||
Snowflake,
|
||||
} from 'discord.js';
|
||||
import IDs from '#utils/ids';
|
||||
import { fetchRoles, addExistingUser, userExists } from '#utils/database/dbExistingUser';
|
||||
import { fetchRoles, addExistingUser } from '#utils/database/dbExistingUser';
|
||||
import { unRestrict, checkActive, unRestrictLegacy } from '#utils/database/restriction';
|
||||
|
||||
export class UnRestrictCommand extends Command {
|
||||
@ -151,9 +151,7 @@ export class UnRestrictCommand extends Command {
|
||||
}
|
||||
|
||||
// Check if mod is in database
|
||||
if (!await userExists(modId)) {
|
||||
await addExistingUser(mod);
|
||||
}
|
||||
await addExistingUser(mod);
|
||||
|
||||
// Gets guildMember
|
||||
let member = guild.members.cache.get(userId);
|
||||
@ -169,9 +167,7 @@ export class UnRestrictCommand extends Command {
|
||||
}
|
||||
|
||||
// Check if mod is in database
|
||||
if (!await userExists(userId)) {
|
||||
await addExistingUser(member);
|
||||
}
|
||||
await addExistingUser(member);
|
||||
|
||||
const restrictRoles = IDs.roles.restrictions.restricted;
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ import {
|
||||
} from 'discord.js';
|
||||
import type { Message, GuildMember, TextChannel } from 'discord.js';
|
||||
import { isMessageInstance } from '@sapphire/discord.js-utilities';
|
||||
import { addExistingUser, userExists } from '#utils/database/dbExistingUser';
|
||||
import { addExistingUser } from '#utils/database/dbExistingUser';
|
||||
import {
|
||||
addToDatabase,
|
||||
findNotes,
|
||||
@ -143,12 +143,9 @@ export class SusCommand extends Subcommand {
|
||||
}
|
||||
|
||||
// Check if user and mod are on the database
|
||||
if (!await userExists(member.id)) {
|
||||
await addExistingUser(member);
|
||||
}
|
||||
if (!await userExists(modMember.id)) {
|
||||
await addExistingUser(modMember);
|
||||
}
|
||||
await addExistingUser(member);
|
||||
await addExistingUser(modMember);
|
||||
|
||||
await addToDatabase(user.id, mod.id, note);
|
||||
|
||||
// Give the user the sus role they don't already have the sus note
|
||||
@ -499,12 +496,9 @@ export class SusCommand extends Subcommand {
|
||||
}
|
||||
|
||||
// Check if user and mod are on the database
|
||||
if (!await userExists(user.id)) {
|
||||
await addExistingUser(user);
|
||||
}
|
||||
if (!await userExists(mod.id)) {
|
||||
await addExistingUser(mod);
|
||||
}
|
||||
await addExistingUser(user);
|
||||
await addExistingUser(mod);
|
||||
|
||||
await addToDatabase(user.id, mod.id, note);
|
||||
|
||||
// Give the user the sus role they don't already have the sus note
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
import { Args, Command, RegisterBehavior } from '@sapphire/framework';
|
||||
import type { GuildMember, Message } from 'discord.js';
|
||||
import { addMute, removeMute, checkActive } from '#utils/database/vcMute';
|
||||
import { addExistingUser, userExists } from '#utils/database/dbExistingUser';
|
||||
import { addExistingUser } from '#utils/database/dbExistingUser';
|
||||
|
||||
export class VCMuteCommand extends Command {
|
||||
public constructor(context: Command.Context, options: Command.Options) {
|
||||
@ -98,9 +98,7 @@ export class VCMuteCommand extends Command {
|
||||
}
|
||||
|
||||
// Check if mod is in database
|
||||
if (!await userExists(mod.id)) {
|
||||
await addExistingUser(mod);
|
||||
}
|
||||
await addExistingUser(mod);
|
||||
|
||||
// Add VC Mute
|
||||
if (member.voice.channel !== null) {
|
||||
@ -147,9 +145,7 @@ export class VCMuteCommand extends Command {
|
||||
}
|
||||
|
||||
// Check if mod is in database
|
||||
if (!await userExists(mod.id)) {
|
||||
await addExistingUser(mod);
|
||||
}
|
||||
await addExistingUser(mod);
|
||||
|
||||
// Add VC Mute
|
||||
if (member.voice.channel !== null) {
|
||||
|
||||
@ -24,7 +24,7 @@ import type {
|
||||
Snowflake,
|
||||
Guild,
|
||||
} from 'discord.js';
|
||||
import { addExistingUser, updateUser, userExists } from '#utils/database/dbExistingUser';
|
||||
import { addExistingUser, updateUser } from '#utils/database/dbExistingUser';
|
||||
import { addWarn } from '#utils/database/warnings';
|
||||
|
||||
/*
|
||||
@ -115,9 +115,7 @@ export class WarnCommand extends Command {
|
||||
return info;
|
||||
}
|
||||
|
||||
if (!(await userExists(userId))) {
|
||||
await addExistingUser(member);
|
||||
}
|
||||
await addExistingUser(member);
|
||||
|
||||
await addWarn(userId, modId, reason);
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ import type { GuildBan } from 'discord.js';
|
||||
import { AuditLogEvent, EmbedBuilder, TextChannel } from 'discord.js';
|
||||
import { addBan, checkBan } from '#utils/database/ban';
|
||||
import IDs from '#utils/ids';
|
||||
import { addEmptyUser, addExistingUser, userExists } from '#utils/database/dbExistingUser';
|
||||
import { addEmptyUser, addExistingUser } from '#utils/database/dbExistingUser';
|
||||
|
||||
export class BanListener extends Listener {
|
||||
public constructor(context: Listener.Context, options: Listener.Options) {
|
||||
@ -90,9 +90,7 @@ export class BanListener extends Listener {
|
||||
}
|
||||
|
||||
// Check if mod is in database
|
||||
if (!await userExists(mod.id)) {
|
||||
await addExistingUser(mod);
|
||||
}
|
||||
await addExistingUser(mod);
|
||||
|
||||
if (await checkBan(user.id)) {
|
||||
this.container.logger.error('BanListener: got past the checkActive at the start.');
|
||||
@ -100,9 +98,7 @@ export class BanListener extends Listener {
|
||||
}
|
||||
|
||||
// Check if user and mod are on the database
|
||||
if (!await userExists(user.id)) {
|
||||
await addEmptyUser(user.id);
|
||||
}
|
||||
await addEmptyUser(user.id);
|
||||
|
||||
let { reason } = banLog;
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ import type { GuildBan } from 'discord.js';
|
||||
import { AuditLogEvent, EmbedBuilder, TextChannel } from 'discord.js';
|
||||
import { addBan, checkBan, removeBan } from '#utils/database/ban';
|
||||
import IDs from '#utils/ids';
|
||||
import { addEmptyUser, addExistingUser, userExists } from '#utils/database/dbExistingUser';
|
||||
import { addEmptyUser, addExistingUser } from '#utils/database/dbExistingUser';
|
||||
|
||||
export class UnbanListener extends Listener {
|
||||
public constructor(context: Listener.Context, options: Listener.Options) {
|
||||
@ -81,16 +81,13 @@ export class UnbanListener extends Listener {
|
||||
}
|
||||
|
||||
// Check if mod is in database
|
||||
if (!await userExists(mod.id)) {
|
||||
await addExistingUser(mod);
|
||||
}
|
||||
await addExistingUser(mod);
|
||||
|
||||
// Check for missing ban on database
|
||||
if (!await checkBan(user.id)) {
|
||||
// Check if user and mod are on the database
|
||||
if (!await userExists(user.id)) {
|
||||
await addEmptyUser(user.id);
|
||||
}
|
||||
await addEmptyUser(user.id);
|
||||
|
||||
// Add missing ban
|
||||
await addBan(user.id, mod.id, '(Mod who banned is not accurate) - ');
|
||||
}
|
||||
|
||||
@ -20,12 +20,7 @@
|
||||
import { Listener } from '@sapphire/framework';
|
||||
import type { GuildMember } from 'discord.js';
|
||||
import IDs from '#utils/ids';
|
||||
import {
|
||||
addEmptyUser,
|
||||
logLeaving,
|
||||
updateUser,
|
||||
userExists,
|
||||
} from '#utils/database/dbExistingUser';
|
||||
import { addEmptyUser, logLeaving, updateUser } from '#utils/database/dbExistingUser';
|
||||
|
||||
export class DbLeaveServerListener extends Listener {
|
||||
public constructor(context: Listener.Context, options: Listener.Options) {
|
||||
@ -41,7 +36,7 @@ export class DbLeaveServerListener extends Listener {
|
||||
IDs.roles.nonvegan.nonvegan,
|
||||
)) {
|
||||
await updateUser(member);
|
||||
} else if (!await userExists(member.id)) {
|
||||
} else {
|
||||
await addEmptyUser(member.id);
|
||||
}
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ import {
|
||||
import { maxVCs, questionInfo, serverFind } from '#utils/verificationConfig';
|
||||
import { joinVerification, startVerification, finishVerification } from '#utils/database/verification';
|
||||
import { findNotes } from '#utils/database/sus';
|
||||
import { userExists, addExistingUser } from '#utils/database/dbExistingUser';
|
||||
import { addExistingUser } from '#utils/database/dbExistingUser';
|
||||
import { rolesToString } from '#utils/formatter';
|
||||
import IDs from '#utils/ids';
|
||||
|
||||
@ -449,9 +449,7 @@ export class VerificationJoinVCListener extends Listener {
|
||||
return;
|
||||
}
|
||||
// Add verifier to database if they're not on the database
|
||||
if (!(await userExists(verifierGuildMember.id))) {
|
||||
await addExistingUser(verifierGuildMember);
|
||||
}
|
||||
await addExistingUser(verifierGuildMember);
|
||||
|
||||
// Add verification data to database
|
||||
await finishVerification(verId, button.user.id, info);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user