mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-18 17:04:15 +02:00
feat(db): add checking previous warns/restrictions
This commit is contained in:
parent
3009a0f923
commit
ae0afa02db
55
src/utils/database/memberMod.ts
Normal file
55
src/utils/database/memberMod.ts
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
/*
|
||||||
|
Animal Rights Advocates Discord Bot
|
||||||
|
Copyright (C) 2024 Anthony Berg
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Snowflake } from 'discord.js';
|
||||||
|
import { countWarnings } from '#utils/database/moderation/warnings';
|
||||||
|
import { countRestrictions } from '#utils/database/moderation/restriction';
|
||||||
|
import { container } from '@sapphire/framework';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the user has
|
||||||
|
* @param userId Discord Snowflake of the user to check
|
||||||
|
* @return Boolean true if no prior moderation action
|
||||||
|
*/
|
||||||
|
export async function noModHistory(userId: Snowflake) {
|
||||||
|
const warnCount = await countWarnings(userId);
|
||||||
|
const restrictCount = await countRestrictions(userId);
|
||||||
|
|
||||||
|
return warnCount === 0 && restrictCount === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the user has previously had a role given or taken away by a moderator.
|
||||||
|
* @param userId Discord Snowflake of the user to check
|
||||||
|
* @param roleId Snowflake of the role being checked for the user
|
||||||
|
* @return Boolean true if the user has had a moderator give/remove the specified role
|
||||||
|
*/
|
||||||
|
export async function userPreviouslyHadRole(
|
||||||
|
userId: Snowflake,
|
||||||
|
roleId: Snowflake,
|
||||||
|
) {
|
||||||
|
const count = await container.database.roleLog.count({
|
||||||
|
where: {
|
||||||
|
userId,
|
||||||
|
roleId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return count !== 0;
|
||||||
|
}
|
@ -114,6 +114,19 @@ export async function getSection(userId: Snowflake) {
|
|||||||
return restriction.section;
|
return restriction.section;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the amount of restrictions a user has.
|
||||||
|
* @param userId Discord Snowflake of the user to check
|
||||||
|
* @return number The amount of restrictions the user has
|
||||||
|
*/
|
||||||
|
export async function countRestrictions(userId: Snowflake) {
|
||||||
|
return container.database.restrict.count({
|
||||||
|
where: {
|
||||||
|
userId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// This is only for restrictions created with the old bot
|
// This is only for restrictions created with the old bot
|
||||||
export async function unRestrictLegacy(
|
export async function unRestrictLegacy(
|
||||||
userId: Snowflake,
|
userId: Snowflake,
|
||||||
|
@ -61,3 +61,16 @@ export async function deleteWarning(warningId: number) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the amount of warnings a user has.
|
||||||
|
* @param userId Discord Snowflake of the user to check
|
||||||
|
* @return number The amount of warnings the user has
|
||||||
|
*/
|
||||||
|
export async function countWarnings(userId: Snowflake) {
|
||||||
|
return container.database.warning.count({
|
||||||
|
where: {
|
||||||
|
userId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user