feat(arabot): add fibonacci verification ban lengths

This commit is contained in:
Anthony 2022-08-31 02:51:52 +01:00
parent 35de24399a
commit cae9091aa1
3 changed files with 35 additions and 3 deletions

View File

@ -21,8 +21,9 @@ import { container, Listener } from '@sapphire/framework';
import type {
VoiceState, CategoryChannel, VoiceChannel, TextChannel,
} from 'discord.js';
import { maxVCs } from '../../utils/verificationConfig';
import { getUser, checkFinish } from '../../utils/database/verification';
import { maxVCs, leaveBan } from '../../utils/verificationConfig';
import { getUser, checkFinish, countIncomplete } from '../../utils/database/verification';
import { fibonacci } from '../../utils/mathsSeries';
import IDs from '../../utils/ids';
class VerificationLeaveVCListener extends Listener {
@ -88,8 +89,16 @@ class VerificationLeaveVCListener extends Listener {
IDs.roles.nonvegan.nonvegan,
IDs.roles.verifyBlock,
]);
// Create timeout block for user
// Counts the recent times they have incomplete verifications
const incompleteCount = await countIncomplete(user.id) % (leaveBan + 1);
// Creates the length of the time for the ban
const banLength = fibonacci(incompleteCount) * 10000; // * 3600 commented because development
console.log(incompleteCount);
console.log(fibonacci(incompleteCount));
// @ts-ignore
this.container.tasks.create('verifyUnblock', { userId: user.id, guildId: guild.id }, 30000);
this.container.tasks.create('verifyUnblock', { userId: user.id, guildId: guild.id }, banLength);
}
}

View File

@ -168,3 +168,22 @@ export async function checkFinish(channelId: string) {
// Return if a finish time has been set meaning verification is complete
return finish.finishTime !== null;
}
// Counts how many times the user has not had a verifier join their VC before leaving
export async function countIncomplete(userId: string) {
// Initialises Prisma Client
const prisma = new PrismaClient();
// Count how many times the user has not completed a verification
const incompleteCount = await prisma.verify.count({
where: {
userId,
finishTime: null,
},
});
// Close the database connection
await prisma.$disconnect();
return incompleteCount;
}

View File

@ -17,8 +17,12 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// The maximum amount of verification VCs there can be
export const maxVCs = 10;
// The maximum amount of leaving bans before time resets
export const leaveBan = 8;
export const questionInfo = [
{
question: 'Welcome to Animal Rights Advocates! How did you find the server?',