Merge branch 'main' into main

This commit is contained in:
Anthony Berg
2023-11-13 22:00:24 +00:00
committed by GitHub
10 changed files with 576 additions and 397 deletions

View File

@@ -38,7 +38,7 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL

View File

@@ -27,7 +27,7 @@ jobs:
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install ESLint
run: |

792
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -29,33 +29,33 @@
},
"homepage": "https://github.com/veganhacktivists/arabot#readme",
"dependencies": {
"@prisma/client": "^5.0.0",
"@sapphire/discord.js-utilities": "^7.0.1",
"@sapphire/framework": "^4.5.1",
"@sapphire/plugin-logger": "^3.0.5",
"@sapphire/plugin-scheduled-tasks": "^7.1.1",
"@sapphire/plugin-subcommands": "^4.0.2",
"@prisma/client": "^5.5.2",
"@sapphire/discord.js-utilities": "^7.0.2",
"@sapphire/framework": "^4.7.2",
"@sapphire/plugin-logger": "^3.0.6",
"@sapphire/plugin-scheduled-tasks": "^8.0.0",
"@sapphire/plugin-subcommands": "^5.0.0",
"@sapphire/stopwatch": "^1.5.0",
"@sapphire/time-utilities": "^1.7.10",
"@sapphire/ts-config": "^4.0.1",
"@sapphire/ts-config": "^5.0.0",
"@sapphire/utilities": "^3.13.0",
"@types/node": "^20.4.4",
"bullmq": "^4.6.0",
"discord.js": "^14.11.0",
"@types/node": "^20.8.9",
"bullmq": "^4.12.7",
"discord.js": "^14.13.0",
"dotenv": "^16.3.1",
"redis": "^4.6.7",
"redis": "^4.6.10",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
"typescript": "^5.2.2"
},
"devDependencies": {
"@types/ioredis": "^5.0.0",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"eslint": "8.51.0",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"eslint": "8.53.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",
"prisma": "^5.0.0"
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.0",
"prisma": "^5.5.2"
}
}

View File

@@ -0,0 +1,11 @@
-- CreateTable
CREATE TABLE "Counting" (
"id" SERIAL NOT NULL,
"userId" TEXT NOT NULL,
"number" INTEGER NOT NULL,
CONSTRAINT "Counting_pkey" PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "Counting" ADD CONSTRAINT "Counting_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -47,6 +47,7 @@ model User {
ModRoleLog RoleLog[] @relation("modRoleLog")
FunLogSender FunLog[] @relation("sendFunLog")
FunLogReciever FunLog[] @relation("receiveFunLog")
Counting Counting[] @relation("counting")
EventLeader Event[] @relation("eventLeader")
StatLeader Stat[] @relation("statLeader")
OutreachParticipation ParticipantStat[] @relation("participantUser")
@@ -179,6 +180,13 @@ model FunType {
FunLog FunLog[]
}
model Counting {
id Int @id @default(autoincrement())
user User @relation("counting", fields: [userId], references: [id])
userId String
number Int // This is the number that the user has counted, if the count failed, the number should be 0
}
// Outreach
model Event {

86
src/listeners/counting.ts Normal file
View File

@@ -0,0 +1,86 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
Animal Rights Advocates Discord Bot
Copyright (C) 2023 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/>.
I developed this whilst I was on holiday in Norway for some reason
*/
import { Listener } from '@sapphire/framework';
import type { Message } from 'discord.js';
import { getLastCount, addCount } from '#utils/database/counting';
import IDs from '#utils/ids';
export class XpListener extends Listener {
public constructor(context: Listener.Context, options: Listener.Options) {
super(context, {
...options,
event: 'messageCreate',
});
}
public async run(message: Message) {
if (message.channelId !== IDs.channels.misc.counting) return;
const user = message.author;
if (user.bot) {
return;
}
let lastCount = await getLastCount();
// If no counts exist on the database, then create the first count from the bot
if (lastCount === null) {
if (this.container.client.id === null) {
message.channel.send('An unexpected error occurred trying to set up the counting channel, please contact a developer!');
return;
}
const countUserId = this.container.client.id;
const countNumber = 0;
// Adds the bot as the first person with the count
await addCount(countUserId, countNumber);
lastCount = await getLastCount();
if (lastCount === null) {
message.channel.send('An unexpected error occurred, please contact a developer!');
return;
}
}
// Checks if it is the same user that counted since last time
if (message.author.id === lastCount.userId) {
return;
}
const regex = new RegExp(`^${lastCount.number + 1}\\b`);
// Checks if the count was correct
if (regex.test(message.content)) {
await addCount(message.author.id, lastCount.number + 1);
await message.react('✅');
return;
}
// If the count was not correct, restart it
await addCount(message.author.id, 0);
await message.react('❌');
await message.reply(`${message.author} counted incorrectly! The count got up to ${lastCount.number}! `
+ 'The count has been reset and the next number is 1');
}
}

View File

@@ -0,0 +1,30 @@
import { container } from '@sapphire/framework';
import type { Snowflake } from 'discord.js';
export async function getLastCount() {
const count = await container.database.counting.findFirst({
orderBy: {
id: 'desc',
},
});
return count;
}
export async function addCount(userId: Snowflake, number: number) {
await container.database.counting.create({
data: {
number,
user: {
connectOrCreate: {
where: {
id: userId,
},
create: {
id: userId,
},
},
},
},
});
}

View File

@@ -110,6 +110,9 @@ const devIDs = {
potgm: '999431679053660189',
disabilities: '999431679527628810',
},
misc: {
counting: '1172905446227595314',
},
restricted: {
welcome: '999431679812845655',
moderators: '999431679812845656',

View File

@@ -113,6 +113,9 @@ let IDs = {
potgm: '956224095509442600',
disabilities: '933078769365823518',
},
misc: {
counting: '1172995918828666941',
},
restricted: {
welcome: '992060036312481874',
moderators: '928349536395604029',