From 2b96d507eb692b8d9256ad58dfa831745272f900 Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 23 Aug 2022 02:05:13 +0100 Subject: [PATCH] fix(verification): fix multiple eslint issues --- .eslintrc.json | 1 + package-lock.json | 19 ++-- package.json | 3 +- src/commands/fun/1984.ts | 4 +- src/commands/fun/happy.ts | 4 +- src/commands/fun/hug.ts | 5 +- src/commands/fun/kill.ts | 5 +- src/commands/fun/poke.ts | 4 +- src/commands/fun/sad.ts | 4 +- src/commands/fun/shrug.ts | 4 +- src/commands/mod/diversityToggleOpen.ts | 22 +++-- src/commands/mod/sus.ts | 49 ++++++----- src/commands/roles/stagehost.ts | 4 +- src/commands/roles/vegcurious.ts | 4 +- src/commands/utils/ping.ts | 4 +- src/commands/verification/purgeVerifying.ts | 4 +- src/listeners/deniedPermission.ts | 4 +- src/listeners/ready.ts | 4 +- src/preconditions/CoordinatorOnly.ts | 4 +- src/preconditions/DevCoordinatorOnly.ts | 4 +- src/preconditions/DiversityCoordinatorOnly.ts | 4 +- src/preconditions/EventCoordinatorOnly.ts | 4 +- src/preconditions/MentorCoordinatorOnly.ts | 4 +- src/preconditions/ModOnly.ts | 4 +- src/preconditions/PatreonOnly.ts | 4 +- src/preconditions/VerifierCoordinatorOnly.ts | 4 +- src/preconditions/VerifierOnly.ts | 4 +- src/scheduled-tasks/appleWarning.ts | 50 +++++++++++ src/scheduled-tasks/standup.ts | 4 +- src/utils/dbExistingUser.ts | 87 +++++++++++++++++++ src/utils/devIDs.ts | 6 ++ src/utils/ids.ts | 7 ++ 32 files changed, 273 insertions(+), 65 deletions(-) create mode 100644 src/scheduled-tasks/appleWarning.ts create mode 100644 src/utils/dbExistingUser.ts diff --git a/.eslintrc.json b/.eslintrc.json index 06613cf..0269b34 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -17,5 +17,6 @@ "@typescript-eslint" ], "rules": { + "class-methods-use-this": "off" } } diff --git a/package-lock.json b/package-lock.json index 5cc1f51..f9d49d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "GPL-3.0-or-later", "dependencies": { "@prisma/client": "^4.0.0", + "@sapphire/discord.js-utilities": "^5.0.0", "@sapphire/framework": "^3.0.0", "@sapphire/plugin-scheduled-tasks": "^4.0.0", "@sapphire/plugin-subcommands": "^3.0.0", @@ -18,7 +19,7 @@ "@types/node": "^18.0.3", "bullmq": "^1.89.1", "discord-api-types": "^0.33.3", - "discord.js": "^13.10.2", + "discord.js": "^13.10.3", "dotenv": "^16.0.1", "prisma": "^4.2.1", "ts-node": "^10.8.2", @@ -1114,13 +1115,13 @@ "integrity": "sha512-dvO5M52v7m7Dy96+XUnzXNsQ/0npsYpU6dL205kAtEDueswoz3aU3bh1UMoK4cQmcGtB1YRyLKqp+DXi05lzFg==" }, "node_modules/discord.js": { - "version": "13.10.2", - "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.10.2.tgz", - "integrity": "sha512-zPhPaUvJRCqmsqMBmQ8gJ8k/O0rcuLj8tn/mOaJEiDPkpb5aFULHarOfqND6jRuLrKXd2to/bc0mjXTOgRW1MA==", + "version": "13.10.3", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.10.3.tgz", + "integrity": "sha512-cIARuxfpQDeqA9Zw3fz4IL20xAhtMsjwJIf7/K82R3n2xROG9/fAx+7qjX8ysp9BfflYqMu2ZskyWq1EAmL5BA==", "dependencies": { "@discordjs/builders": "^0.16.0", "@discordjs/collection": "^0.7.0", - "@sapphire/async-queue": "^1.3.2", + "@sapphire/async-queue": "^1.5.0", "@types/node-fetch": "^2.6.2", "@types/ws": "^8.5.3", "discord-api-types": "^0.33.3", @@ -4069,13 +4070,13 @@ "integrity": "sha512-dvO5M52v7m7Dy96+XUnzXNsQ/0npsYpU6dL205kAtEDueswoz3aU3bh1UMoK4cQmcGtB1YRyLKqp+DXi05lzFg==" }, "discord.js": { - "version": "13.10.2", - "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.10.2.tgz", - "integrity": "sha512-zPhPaUvJRCqmsqMBmQ8gJ8k/O0rcuLj8tn/mOaJEiDPkpb5aFULHarOfqND6jRuLrKXd2to/bc0mjXTOgRW1MA==", + "version": "13.10.3", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.10.3.tgz", + "integrity": "sha512-cIARuxfpQDeqA9Zw3fz4IL20xAhtMsjwJIf7/K82R3n2xROG9/fAx+7qjX8ysp9BfflYqMu2ZskyWq1EAmL5BA==", "requires": { "@discordjs/builders": "^0.16.0", "@discordjs/collection": "^0.7.0", - "@sapphire/async-queue": "^1.3.2", + "@sapphire/async-queue": "^1.5.0", "@types/node-fetch": "^2.6.2", "@types/ws": "^8.5.3", "discord-api-types": "^0.33.3", diff --git a/package.json b/package.json index f52553c..77430ba 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "homepage": "https://github.com/veganhacktivists/arabot#readme", "dependencies": { "@prisma/client": "^4.0.0", + "@sapphire/discord.js-utilities": "^5.0.0", "@sapphire/framework": "^3.0.0", "@sapphire/plugin-scheduled-tasks": "^4.0.0", "@sapphire/plugin-subcommands": "^3.0.0", @@ -35,7 +36,7 @@ "@types/node": "^18.0.3", "bullmq": "^1.89.1", "discord-api-types": "^0.33.3", - "discord.js": "^13.10.2", + "discord.js": "^13.10.3", "dotenv": "^16.0.1", "prisma": "^4.2.1", "ts-node": "^10.8.2", diff --git a/src/commands/fun/1984.ts b/src/commands/fun/1984.ts index a7f5ee8..d486633 100644 --- a/src/commands/fun/1984.ts +++ b/src/commands/fun/1984.ts @@ -21,7 +21,7 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import { MessageEmbed } from 'discord.js'; import { N1984 } from '../../utils/gifs'; -export class N1984Command extends Command { +class N1984Command extends Command { public constructor(context: Command.Context, options: Command.Options) { super(context, { ...options, @@ -63,3 +63,5 @@ export class N1984Command extends Command { await interaction.reply({ embeds: [n1984Embed], fetchReply: true }); } } + +export default N1984Command; diff --git a/src/commands/fun/happy.ts b/src/commands/fun/happy.ts index 3cde127..7d62023 100644 --- a/src/commands/fun/happy.ts +++ b/src/commands/fun/happy.ts @@ -21,7 +21,7 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import { MessageEmbed } from 'discord.js'; import { Happy } from '../../utils/gifs'; -export class HappyCommand extends Command { +class HappyCommand extends Command { public constructor(context: Command.Context, options: Command.Options) { super(context, { ...options, @@ -61,3 +61,5 @@ export class HappyCommand extends Command { await interaction.reply({ embeds: [happyEmbed], fetchReply: true }); } } + +export default HappyCommand; diff --git a/src/commands/fun/hug.ts b/src/commands/fun/hug.ts index 84a0a42..d305450 100644 --- a/src/commands/fun/hug.ts +++ b/src/commands/fun/hug.ts @@ -21,13 +21,12 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import { MessageEmbed } from 'discord.js'; import { Hugs } from '../../utils/gifs'; -export class HugCommand extends Command { +class HugCommand extends Command { public constructor(context: Command.Context, options: Command.Options) { super(context, { ...options, name: 'hug', description: 'Hug a user', - preconditions: [['CoordinatorOnly', 'PatreonOnly']], }); } @@ -65,3 +64,5 @@ export class HugCommand extends Command { await interaction.reply({ content: `<@${user.id}>`, embeds: [hugEmbed], fetchReply: true }); } } + +export default HugCommand; diff --git a/src/commands/fun/kill.ts b/src/commands/fun/kill.ts index a584c23..7c35ab4 100644 --- a/src/commands/fun/kill.ts +++ b/src/commands/fun/kill.ts @@ -21,13 +21,12 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import { MessageEmbed } from 'discord.js'; import { Kill } from '../../utils/gifs'; -export class KillCommand extends Command { +class KillCommand extends Command { public constructor(context: Command.Context, options: Command.Options) { super(context, { ...options, name: 'kill', description: 'Kill a user', - preconditions: [['CoordinatorOnly', 'PatreonOnly']], }); } @@ -65,3 +64,5 @@ export class KillCommand extends Command { await interaction.reply({ content: `<@${user.id}>`, embeds: [killEmbed], fetchReply: true }); } } + +export default KillCommand; diff --git a/src/commands/fun/poke.ts b/src/commands/fun/poke.ts index 5f8af92..3981714 100644 --- a/src/commands/fun/poke.ts +++ b/src/commands/fun/poke.ts @@ -21,7 +21,7 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import { MessageEmbed } from 'discord.js'; import { Poke } from '../../utils/gifs'; -export class PokeCommand extends Command { +class PokeCommand extends Command { public constructor(context: Command.Context, options: Command.Options) { super(context, { ...options, @@ -65,3 +65,5 @@ export class PokeCommand extends Command { await interaction.reply({ content: `<@${user.id}>`, embeds: [pokeEmbed], fetchReply: true }); } } + +export default PokeCommand; diff --git a/src/commands/fun/sad.ts b/src/commands/fun/sad.ts index d73183c..a5e8811 100644 --- a/src/commands/fun/sad.ts +++ b/src/commands/fun/sad.ts @@ -21,7 +21,7 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import { MessageEmbed } from 'discord.js'; import { Sad } from '../../utils/gifs'; -export class SadCommand extends Command { +class SadCommand extends Command { public constructor(context: Command.Context, options: Command.Options) { super(context, { ...options, @@ -61,3 +61,5 @@ export class SadCommand extends Command { await interaction.reply({ embeds: [sadEmbed], fetchReply: true }); } } + +export default SadCommand; diff --git a/src/commands/fun/shrug.ts b/src/commands/fun/shrug.ts index b4f6c1a..18909d5 100644 --- a/src/commands/fun/shrug.ts +++ b/src/commands/fun/shrug.ts @@ -21,7 +21,7 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import { MessageEmbed } from 'discord.js'; import { Shrug } from '../../utils/gifs'; -export class ShrugCommand extends Command { +class ShrugCommand extends Command { public constructor(context: Command.Context, options: Command.Options) { super(context, { ...options, @@ -61,3 +61,5 @@ export class ShrugCommand extends Command { await interaction.reply({ embeds: [shrugEmbed], fetchReply: true }); } } + +export default ShrugCommand; diff --git a/src/commands/mod/diversityToggleOpen.ts b/src/commands/mod/diversityToggleOpen.ts index c1f564c..bd49301 100644 --- a/src/commands/mod/diversityToggleOpen.ts +++ b/src/commands/mod/diversityToggleOpen.ts @@ -21,7 +21,7 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import type { TextChannel } from 'discord.js'; import IDs from '../../utils/ids'; -export class ToggleOpenCommand extends Command { +class ToggleOpenCommand extends Command { public constructor(context: Command.Context, options: Command.Options) { super(context, { ...options, @@ -52,16 +52,18 @@ export class ToggleOpenCommand extends Command { // Checks what subcommand was run switch (subcommand) { case 'toggleopen': { - return await this.toggleOpen(interaction); + await this.toggleOpen(interaction); + return; + } + default: { + // If subcommand is invalid + await interaction.reply({ + content: 'Invalid sub command!', + ephemeral: true, + fetchReply: true, + }); } } - - // If subcommand is invalid - await interaction.reply({ - content: 'Invalid sub command!', - ephemeral: true, - fetchReply: true, - }); } // Command run @@ -123,3 +125,5 @@ export class ToggleOpenCommand extends Command { }); } } + +export default ToggleOpenCommand; diff --git a/src/commands/mod/sus.ts b/src/commands/mod/sus.ts index d91fc70..fb2d9d7 100644 --- a/src/commands/mod/sus.ts +++ b/src/commands/mod/sus.ts @@ -59,7 +59,7 @@ async function findNotes(userId: string, active: boolean) { const prisma = new PrismaClient(); // Query to get the specific user's sus notes - const getNote = await prisma.sus.findMany({ + const note = await prisma.sus.findMany({ where: { userId, active, @@ -68,7 +68,7 @@ async function findNotes(userId: string, active: boolean) { // Close the database connection await prisma.$disconnect(); - return getNote; + return note; } // Get one note from the id @@ -77,7 +77,7 @@ async function getNote(noteId: number) { const prisma = new PrismaClient(); // Query to get the specific user's sus notes - const getNote = await prisma.sus.findUnique({ + const note = await prisma.sus.findUnique({ where: { id: noteId, }, @@ -85,7 +85,7 @@ async function getNote(noteId: number) { // Close the database connection await prisma.$disconnect(); - return getNote; + return note; } async function deactivateNote(noteId: number) { @@ -127,7 +127,7 @@ async function deactivateAllNotes(userId: string) { } // Main command -export class SusCommand extends Command { +class SusCommand extends Command { public constructor(context: Command.Context) { super(context, { name: 'sus', @@ -182,29 +182,34 @@ export class SusCommand extends Command { // Checks what subcommand was run switch (subcommand) { case 'add': { - return await this.addNote(interaction); + await this.addNote(interaction); + return; } case 'view': { - return await this.listNote(interaction); + await this.listNote(interaction); + return; } case 'remove': { - return await this.removeNote(interaction); + await this.removeNote(interaction); + return; } case 'purge': { - return await this.removeAllNotes(interaction); + await this.removeAllNotes(interaction); + return; + } + default: { + // If subcommand is invalid + await interaction.reply({ + content: 'Invalid sub command!', + ephemeral: true, + fetchReply: true, + }); } } - - // If subcommand is invalid - await interaction.reply({ - content: 'Invalid sub command!', - ephemeral: true, - fetchReply: true, - }); } // Subcommand to add sus note - public async addNote(interaction: Command.ChatInputInteraction) { + private async addNote(interaction: Command.ChatInputInteraction) { // Get the arguments let user = interaction.options.getUser('user'); let note = interaction.options.getString('note'); @@ -261,7 +266,7 @@ export class SusCommand extends Command { }); } - public async listNote(interaction: Command.ChatInputInteraction) { + private async listNote(interaction: Command.ChatInputInteraction) { // Get the arguments let user = interaction.options.getUser('user'); const { guild } = interaction; @@ -321,7 +326,7 @@ export class SusCommand extends Command { }); } - public async removeNote(interaction: Command.ChatInputInteraction) { + private async removeNote(interaction: Command.ChatInputInteraction) { // Get the arguments let noteId = interaction.options.getInteger('id'); const { guild, channel } = interaction; @@ -375,7 +380,7 @@ export class SusCommand extends Command { .setThumbnail(user!.avatarURL()!) // TODO avatar does not show when run .addField( `ID: ${noteId} | Moderator: ${modName} | Date: `, - note!.note, + note!.note, ); // Create buttons to delete or cancel the deletion @@ -439,7 +444,7 @@ export class SusCommand extends Command { }); } - public async removeAllNotes(interaction: Command.ChatInputInteraction) { + private async removeAllNotes(interaction: Command.ChatInputInteraction) { // Get the arguments const user = interaction.options.getUser('user'); const { guild, channel } = interaction; @@ -557,3 +562,5 @@ export class SusCommand extends Command { await userGuildMember!.roles.remove(IDs.roles.restrictions.sus); } } + +export default SusCommand; diff --git a/src/commands/roles/stagehost.ts b/src/commands/roles/stagehost.ts index a4da8d8..95e4c8b 100644 --- a/src/commands/roles/stagehost.ts +++ b/src/commands/roles/stagehost.ts @@ -20,7 +20,7 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import IDs from '../../utils/ids'; -export class StageHostCommand extends Command { +class StageHostCommand extends Command { public constructor(context: Command.Context, options: Command.Options) { super(context, { ...options, @@ -98,3 +98,5 @@ export class StageHostCommand extends Command { }); } } + +export default StageHostCommand; diff --git a/src/commands/roles/vegcurious.ts b/src/commands/roles/vegcurious.ts index 7832fe1..44a9d84 100644 --- a/src/commands/roles/vegcurious.ts +++ b/src/commands/roles/vegcurious.ts @@ -20,7 +20,7 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import IDs from '../../utils/ids'; -export class VegCuriousCommand extends Command { +class VegCuriousCommand extends Command { public constructor(context: Command.Context, options: Command.Options) { super(context, { ...options, @@ -109,3 +109,5 @@ export class VegCuriousCommand extends Command { }); } } + +export default VegCuriousCommand; diff --git a/src/commands/utils/ping.ts b/src/commands/utils/ping.ts index 7055331..7a342ae 100644 --- a/src/commands/utils/ping.ts +++ b/src/commands/utils/ping.ts @@ -20,7 +20,7 @@ import { isMessageInstance } from '@sapphire/discord.js-utilities'; import { Command } from '@sapphire/framework'; -export class PingCommand extends Command { +class PingCommand extends Command { public constructor(context: Command.Context, options: Command.Options) { super(context, { ...options, @@ -49,3 +49,5 @@ export class PingCommand extends Command { return interaction.editReply('Failed to retrieve ping :('); } } + +export default PingCommand; diff --git a/src/commands/verification/purgeVerifying.ts b/src/commands/verification/purgeVerifying.ts index 50c883f..7e0bc10 100644 --- a/src/commands/verification/purgeVerifying.ts +++ b/src/commands/verification/purgeVerifying.ts @@ -21,7 +21,7 @@ import { Command, RegisterBehavior } from '@sapphire/framework'; import { isMessageInstance } from '@sapphire/discord.js-utilities'; import IDs from '../../utils/ids'; -export class purgeVerifyingCommand extends Command { +class PurgeVerifyingCommand extends Command { public constructor(context: Command.Context, options: Command.Options) { super(context, { ...options, @@ -129,3 +129,5 @@ export class purgeVerifyingCommand extends Command { */ } } + +export default PurgeVerifyingCommand; diff --git a/src/listeners/deniedPermission.ts b/src/listeners/deniedPermission.ts index e8952ef..fcbb1ad 100644 --- a/src/listeners/deniedPermission.ts +++ b/src/listeners/deniedPermission.ts @@ -20,7 +20,7 @@ import type { UserError, ChatInputCommandDeniedPayload } from '@sapphire/framework'; import { Listener } from '@sapphire/framework'; -export class CommandDeniedListener extends Listener { +class CommandDeniedListener extends Listener { public constructor(context: Listener.Context, options: Listener.Options) { super(context, { ...options, @@ -33,3 +33,5 @@ export class CommandDeniedListener extends Listener { return interaction.reply(error.message); } } + +export default CommandDeniedListener; diff --git a/src/listeners/ready.ts b/src/listeners/ready.ts index 4befaf1..dc8415a 100644 --- a/src/listeners/ready.ts +++ b/src/listeners/ready.ts @@ -23,7 +23,7 @@ import { Listener } from '@sapphire/framework'; import type { Client } from 'discord.js'; -export class ReadyListener extends Listener { +class ReadyListener extends Listener { public constructor(context: Listener.Context, options: Listener.Options) { super(context, { ...options, @@ -37,3 +37,5 @@ export class ReadyListener extends Listener { this.container.logger.info(`Successfully logged in as ${username} (${id})`); } } + +export default ReadyListener; diff --git a/src/preconditions/CoordinatorOnly.ts b/src/preconditions/CoordinatorOnly.ts index c067410..5a77f45 100644 --- a/src/preconditions/CoordinatorOnly.ts +++ b/src/preconditions/CoordinatorOnly.ts @@ -26,7 +26,7 @@ import type { } from 'discord.js'; import IDs from '../utils/ids'; -export class CoordinatorOnlyPrecondition extends AllFlowsPrecondition { +class CoordinatorOnlyPrecondition extends AllFlowsPrecondition { public override async messageRun(message: Message) { // for message command return this.checkCoordinator(message.member!); @@ -54,3 +54,5 @@ declare module '@sapphire/framework' { CoordinatorOnly: never; } } + +export default CoordinatorOnlyPrecondition; diff --git a/src/preconditions/DevCoordinatorOnly.ts b/src/preconditions/DevCoordinatorOnly.ts index aeeb3cd..fcd997b 100644 --- a/src/preconditions/DevCoordinatorOnly.ts +++ b/src/preconditions/DevCoordinatorOnly.ts @@ -26,7 +26,7 @@ import type { } from 'discord.js'; import IDs from '../utils/ids'; -export class DevCoordinatorOnlyPrecondition extends AllFlowsPrecondition { +class DevCoordinatorOnlyPrecondition extends AllFlowsPrecondition { public override async messageRun(message: Message) { // for message command return this.checkDevCoordinator(message.member!); @@ -54,3 +54,5 @@ declare module '@sapphire/framework' { DevCoordinatorOnly: never; } } + +export default DevCoordinatorOnlyPrecondition; diff --git a/src/preconditions/DiversityCoordinatorOnly.ts b/src/preconditions/DiversityCoordinatorOnly.ts index 4e3ebbb..101db76 100644 --- a/src/preconditions/DiversityCoordinatorOnly.ts +++ b/src/preconditions/DiversityCoordinatorOnly.ts @@ -26,7 +26,7 @@ import type { } from 'discord.js'; import IDs from '../utils/ids'; -export class DiversityCoordinatorOnlyPrecondition extends AllFlowsPrecondition { +class DiversityCoordinatorOnlyPrecondition extends AllFlowsPrecondition { public override async messageRun(message: Message) { // for message command return this.checkDiversityCoordinator(message.member!); @@ -54,3 +54,5 @@ declare module '@sapphire/framework' { DiversityCoordinatorOnly: never; } } + +export default DiversityCoordinatorOnlyPrecondition; diff --git a/src/preconditions/EventCoordinatorOnly.ts b/src/preconditions/EventCoordinatorOnly.ts index bdc76e0..2b76783 100644 --- a/src/preconditions/EventCoordinatorOnly.ts +++ b/src/preconditions/EventCoordinatorOnly.ts @@ -26,7 +26,7 @@ import type { } from 'discord.js'; import IDs from '../utils/ids'; -export class EventCoordinatorOnlyPrecondition extends AllFlowsPrecondition { +class EventCoordinatorOnlyPrecondition extends AllFlowsPrecondition { public override async messageRun(message: Message) { // for message command return this.checkEventCoordinator(message.member!); @@ -54,3 +54,5 @@ declare module '@sapphire/framework' { EventCoordinatorOnly: never; } } + +export default EventCoordinatorOnlyPrecondition; diff --git a/src/preconditions/MentorCoordinatorOnly.ts b/src/preconditions/MentorCoordinatorOnly.ts index d0ebf7e..7a58bc5 100644 --- a/src/preconditions/MentorCoordinatorOnly.ts +++ b/src/preconditions/MentorCoordinatorOnly.ts @@ -26,7 +26,7 @@ import type { } from 'discord.js'; import IDs from '../utils/ids'; -export class MentorCoordinatorOnlyPrecondition extends AllFlowsPrecondition { +class MentorCoordinatorOnlyPrecondition extends AllFlowsPrecondition { public override async messageRun(message: Message) { // for message command return this.checkMentorCoordinator(message.member!); @@ -54,3 +54,5 @@ declare module '@sapphire/framework' { MentorCoordinatorOnly: never; } } + +export default MentorCoordinatorOnlyPrecondition; diff --git a/src/preconditions/ModOnly.ts b/src/preconditions/ModOnly.ts index 3436688..d2618da 100644 --- a/src/preconditions/ModOnly.ts +++ b/src/preconditions/ModOnly.ts @@ -26,7 +26,7 @@ import type { } from 'discord.js'; import IDs from '../utils/ids'; -export class ModOnlyPrecondition extends AllFlowsPrecondition { +class ModOnlyPrecondition extends AllFlowsPrecondition { public override async messageRun(message: Message) { // for message command return this.checkMod(message.member!); @@ -54,3 +54,5 @@ declare module '@sapphire/framework' { ModOnly: never; } } + +export default ModOnlyPrecondition; diff --git a/src/preconditions/PatreonOnly.ts b/src/preconditions/PatreonOnly.ts index 54ddc61..3428c0e 100644 --- a/src/preconditions/PatreonOnly.ts +++ b/src/preconditions/PatreonOnly.ts @@ -26,7 +26,7 @@ import type { } from 'discord.js'; import IDs from '../utils/ids'; -export class PatreonOnlyPrecondition extends AllFlowsPrecondition { +class PatreonOnlyPrecondition extends AllFlowsPrecondition { public override async messageRun(message: Message) { // for message command return this.checkPatreon(message.member!); @@ -54,3 +54,5 @@ declare module '@sapphire/framework' { PatreonOnly: never; } } + +export default PatreonOnlyPrecondition; diff --git a/src/preconditions/VerifierCoordinatorOnly.ts b/src/preconditions/VerifierCoordinatorOnly.ts index bf9a347..c5d1214 100644 --- a/src/preconditions/VerifierCoordinatorOnly.ts +++ b/src/preconditions/VerifierCoordinatorOnly.ts @@ -26,7 +26,7 @@ import type { } from 'discord.js'; import IDs from '../utils/ids'; -export class VerifierCoordinatorOnlyPrecondition extends AllFlowsPrecondition { +class VerifierCoordinatorOnlyPrecondition extends AllFlowsPrecondition { public override async messageRun(message: Message) { // for message command return this.checkVerifierCoordinator(message.member!); @@ -54,3 +54,5 @@ declare module '@sapphire/framework' { VerifierCoordinatorOnly: never; } } + +export default VerifierCoordinatorOnlyPrecondition; diff --git a/src/preconditions/VerifierOnly.ts b/src/preconditions/VerifierOnly.ts index e415bd3..1c5f8ee 100644 --- a/src/preconditions/VerifierOnly.ts +++ b/src/preconditions/VerifierOnly.ts @@ -26,7 +26,7 @@ import type { } from 'discord.js'; import IDs from '../utils/ids'; -export class VerifierOnlyPrecondition extends AllFlowsPrecondition { +class VerifierOnlyPrecondition extends AllFlowsPrecondition { public override async messageRun(message: Message) { // for message command return this.checkVerifier(message.member!); @@ -54,3 +54,5 @@ declare module '@sapphire/framework' { VerifierOnly: never; } } + +export default VerifierOnlyPrecondition; diff --git a/src/scheduled-tasks/appleWarning.ts b/src/scheduled-tasks/appleWarning.ts new file mode 100644 index 0000000..22305ac --- /dev/null +++ b/src/scheduled-tasks/appleWarning.ts @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +/* + Animal Rights Advocates Discord Bot + Copyright (C) 2022 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 . +*/ + +import { ScheduledTask } from '@sapphire/plugin-scheduled-tasks'; +import { container } from '@sapphire/framework'; +import type { TextChannel } from 'discord.js'; +import IDs from '../utils/ids'; + +class AppleWarningTask extends ScheduledTask { + public constructor(context: ScheduledTask.Context, options: ScheduledTask.Options) { + super(context, { + ...options, + cron: '0 */2 * * 2-3', + }); + } + + public async run() { + const { client } = container; + + const channel = client.channels.cache.get(IDs.channels.nonVegan.general) as TextChannel; + + await channel.send('Hiya everyone, this is a warning to all **Apple users**!\n' + + 'Make sure to update your iOS, iPadOS and MacOS as there is a hack that lets anyone get remote access to your device if you click on a malicious link.\n' + + `For more information, read the post in <#${IDs.channels.information.news}>`); + } +} + +declare module '@sapphire/plugin-scheduled-tasks' { + interface ScheduledTasks { + cron: never; + } +} + +export default AppleWarningTask; diff --git a/src/scheduled-tasks/standup.ts b/src/scheduled-tasks/standup.ts index 9aef1bf..5645162 100644 --- a/src/scheduled-tasks/standup.ts +++ b/src/scheduled-tasks/standup.ts @@ -22,7 +22,7 @@ import { container } from '@sapphire/framework'; import type { TextChannel } from 'discord.js'; import IDs from '../utils/ids'; -export class StandupTask extends ScheduledTask { +class StandupTask extends ScheduledTask { public constructor(context: ScheduledTask.Context, options: ScheduledTask.Options) { super(context, { ...options, @@ -45,3 +45,5 @@ declare module '@sapphire/plugin-scheduled-tasks' { cron: never; } } + +export default StandupTask; diff --git a/src/utils/dbExistingUser.ts b/src/utils/dbExistingUser.ts new file mode 100644 index 0000000..14a5892 --- /dev/null +++ b/src/utils/dbExistingUser.ts @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +/* + Animal Rights Advocates Discord Bot + Copyright (C) 2022 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 . +*/ + +import type { GuildMember } from 'discord.js'; +import { PrismaClient } from '@prisma/client'; +import IDs from './ids'; + +// Checks if the user exists on the database +export async function userExists(user: GuildMember) { + // Initialises Prisma Client + const prisma = new PrismaClient(); + + // Counts if the user is on the database by their snowflake + const userQuery = await prisma.user.count({ + where: { + id: user.id, + }, + }); + + // Close the database connection + await prisma.$disconnect(); + + // If the user is found on the database, then return true, otherwise, false. + return userQuery > 0; +} + +// Adds the user to the database if they were already on the server before the bot/database +export async function addExistingUser(user: GuildMember) { + // Initialises Prisma Client + const prisma = new PrismaClient(); + + // Counts if the user is on the database by their snowflake + const userQuery = await prisma.user.count({ + where: { + id: user.id, + }, + }); + + // If the user is already in the database + if (userQuery > 0) { + return; + } + + // Checks what roles the user has + const hasVegan = user.roles.cache.has(IDs.roles.vegan.vegan); + const hasActivist = user.roles.cache.has(IDs.roles.vegan.activist); + const hasPlus = user.roles.cache.has(IDs.roles.vegan.plus); + const hasNotVegan = user.roles.cache.has(IDs.roles.nonvegan.nonvegan); + const hasVegCurious = user.roles.cache.has(IDs.roles.nonvegan.vegCurious); + const hasConvinced = user.roles.cache.has(IDs.roles.nonvegan.convinced); + const hasTrusted = user.roles.cache.has(IDs.roles.trusted); + const hasMuted = user.roles.cache.has(IDs.roles.restrictions.muted); + + // Create the user in the database + await prisma.user.create({ + data: { + id: user.id, + vegan: hasVegan, + trusted: hasTrusted, + activist: hasActivist, + plus: hasPlus, + notVegan: hasNotVegan, + vegCurious: hasVegCurious, + convinced: hasConvinced, + muted: hasMuted, + }, + }); + + // Close the database connection + await prisma.$disconnect(); +} diff --git a/src/utils/devIDs.ts b/src/utils/devIDs.ts index 8c6bf60..9493355 100644 --- a/src/utils/devIDs.ts +++ b/src/utils/devIDs.ts @@ -57,11 +57,17 @@ const devIDs = { verifyBlock: '1007477161835372574', }, channels: { + information: { + news: '999431676058927247', + }, staff: { coordinators: '999431676058927254', standup: '999431676289622183', verifiers: '999431677006860411', }, + nonVegan: { + general: '999431677325615189', + }, diversity: { women: '999431679053660187', lgbtqia: '999431679053660188', diff --git a/src/utils/ids.ts b/src/utils/ids.ts index 15422be..81b9eef 100644 --- a/src/utils/ids.ts +++ b/src/utils/ids.ts @@ -19,6 +19,7 @@ import devIDs from './devIDs'; +// eslint-disable-next-line import/no-mutable-exports let IDs = { roles: { trusted: '731563158011117590', @@ -59,11 +60,17 @@ let IDs = { verifyBlock: '', }, channels: { + information: { + news: '866000393259319306', + }, staff: { coordinators: '1006240682505142354', standup: '996009201237233684', verifiers: '873215538627756072', }, + nonVegan: { + general: '798967615636504657', + }, diversity: { women: '938808963544285324', lgbtqia: '956224226556272670',