diff --git a/.env.example b/.env.example index 00a861f..009d99c 100644 --- a/.env.example +++ b/.env.example @@ -7,7 +7,7 @@ # any secret values. BOT_TOKEN= -BOT_VER=0.8.0 +BOT_VER=0.7.0 BOT_AUTHOR=Vylpes BOT_OWNERID=147392775707426816 BOT_CLIENTID=682942374040961060 diff --git a/.forgejo/workflows/production.yml b/.forgejo/workflows/production.yml index 1dd774e..1bbf28f 100644 --- a/.forgejo/workflows/production.yml +++ b/.forgejo/workflows/production.yml @@ -30,7 +30,7 @@ jobs: needs: build runs-on: node steps: - - uses: https://github.com/appleboy/ssh-action@v1.0.3 + - uses: https://github.com/appleboy/ssh-action@v1.0.0 env: DB_NAME: ${{ secrets.PROD_DB_NAME }} DB_AUTH_USER: ${{ secrets.PROD_DB_AUTH_USER }} diff --git a/.forgejo/workflows/stage.yml b/.forgejo/workflows/stage.yml index 8903a70..b245d95 100644 --- a/.forgejo/workflows/stage.yml +++ b/.forgejo/workflows/stage.yml @@ -30,7 +30,7 @@ jobs: needs: build runs-on: node steps: - - uses: https://github.com/appleboy/ssh-action@v1.0.3 + - uses: https://github.com/appleboy/ssh-action@v1.0.0 env: DB_NAME: ${{ secrets.STAGE_DB_NAME }} DB_AUTH_USER: ${{ secrets.STAGE_DB_AUTH_USER }} diff --git a/README.md b/README.md index ca4b03f..94f0c9c 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,2 @@ -# Card Drop - -Card Drop is a Discord Bot designed to allow users to "drop" random cards into -a channel and have the ability to claim them for themselves or let others if -they so choose. - -The cards are randomly chosen based on weights of their card type (i.e. Bronze -is more common than Gold). The user who ran the drop command has 5 minutes to -choose if they want the card to themselves before its claimable by anyone, or -until the drop command is ran again. - -## Installation - -Downloads of the latest version can be found from the [GitHub Releases](https://github.com/vylpes/card-drop/releases) -or [Forgejo Releases](https://git.vylpes.xyz/external/card-drop/releases) page. - -Copy the config template file and fill in the strings. - -## Requirements - -- NodeJS -- Yarn -- Docker - -## Usage - -Install the dependencies and build the app: - -```bash -yarn Install -yarn build -``` - -Setup the database (Recommended to use the docker-compose file - -```bash -docker compose up -d -``` - -Copy and edit the settings file - -```bash -cp .env.template .env -``` - -> **NOTE:** Make sure you do *not* check in these files! These contain -sensitive information and should be treated as private. - -If you're not using `DB_SYNC=true` in `.env`, make sure to migrate the database - -```bash -yarn db:up -``` - -Start the bot - -```bash -yarn start -``` +# card-drop diff --git a/docs/cards.md b/docs/cards.md deleted file mode 100644 index f0be28f..0000000 --- a/docs/cards.md +++ /dev/null @@ -1,120 +0,0 @@ -# Cards - -This document will describe how to add cards to the bot. This is from the -perspective of the development side and doesn't go into details of syncing -from an external place such as with the Google Drive Sync function. - -The cards will be put into the `$DATA_DIR/cards` folder. `$DATA_DIR` is -configured in the `.env` file. - -## Folder Structure - -The general structure of the cards folder is as follows: - -``` -cards # The main cards folder -| Series 1 # Series folder -| | BRONZE # Type folder -| | | 1000.jpg # Card image -| | | 1001.jpg -| | 1.json # Card metadata file -| Series 2 -| | SILVER -| | | 2000.jpg -| | 2.json -``` - -- The root of the cards folder will have a folder foor each series -- Each series will contain folders for each of the card types containing the - card images. -- The series folder will also contain a metadata JSON folder containing the - metadata of the cards within that series. - -The bot when loading will search the cards folder recursively for each json, -and then read them to determine what cards should be used for the bot. - -## Series Metadata - -An example of what the metadata files could look like are as follows: - -```json -[ - { - "id": 1, - "name": "Series 1", - "cards": [ - { - "id": "1000", - "name": "Card 1000 of Series 1", - "type": 1, - "path": "Series 1/BRONZE/1000.jpg" - }, - { - "id": "1001", - "name": "Card 1001 of Series 1", - "type": 1, - "path": "Series 2/BRONZE?1001.jpg", - "subseries": "Custom Series Name" - } - ] - } -] -``` - -This file will load a series called "Series 1" with the id of 1, containing 2 -cards: -- Card 1000, with type 1 (Bronze), with its image located at (from root) - "Series 1/BRONZE/1000.jpg" -- Card 1001 is the same, except has a custom "subseries" name which will - override the main series name if shown, helpful for an "other" category. - -### Card Type - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NumberNameChanceSacrifice Cost (Coins)
0Unknown--
1Bronze62%5
2Silver31%10
3Gold4.4%30
4Manga2%40
5Legendary0.6%100
diff --git a/package.json b/package.json index 9126a28..f37eae6 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "card-drop", - "version": "0.8.0", + "version": "0.7.0", "main": "./dist/bot.js", "typings": "./dist", "scripts": { "clean": "rm -rf node_modules/ dist/", "build": "tsc", "start": "node ./dist/bot.js", - "test": "echo true", + "test": "jest --passWithNoTests", "lint": "eslint .", "lint:fix": "eslint . --fix", "db:up": "typeorm migration:run -d dist/database/dataSources/appDataSource.js", @@ -15,11 +15,11 @@ "db:create": "typeorm migration:create ./src/database/migrations/app/new", "release": "np --no-publish" }, - "repository": "https://git.vylpes.xyz/External/card-drop.git", + "repository": "https://gitea.vylpes.xyz/External/card-drop.git", "author": "Ethan Lane ", "license": "MIT", "bugs": { - "url": "https//git.vylpes.xyz/External/card-drop/issues", + "url": "https//gitea.vylpes.xyz/External/card-drop/issues", "email": "helpdesk@vylpes.com" }, "homepage": "https://gitea.vylpes.xyz/External/card-drop", @@ -49,8 +49,8 @@ "winston-daily-rotate-file": "^5.0.0", "winston-discord-transport": "^1.3.0" }, - "resolutions": { - "**/ws": "^8.17.1" + "overrides": { + "undici": "^5.28.3" }, "devDependencies": { "@types/node": "^20.0.0", diff --git a/src/commands/allbalance.ts b/src/commands/allbalance.ts deleted file mode 100644 index 0874e54..0000000 --- a/src/commands/allbalance.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js"; -import EmbedColours from "../constants/EmbedColours"; -import { Command } from "../type/command"; -import User from "../database/entities/app/User"; - -export default class AllBalance extends Command { - constructor() { - super(); - - this.CommandBuilder = new SlashCommandBuilder() - .setName("allbalance") - .setDescription("Get everyone's currency balance") - .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator); - } - - public override async execute(interaction: CommandInteraction) { - const users = await User.FetchAll(User); - - const filteredUsers = users.filter(x => x.Currency > 0) - .sort((a, b) => b.Currency - a.Currency); - - const embed = new EmbedBuilder() - .setColor(EmbedColours.Ok) - .setTitle("All Balances") - .setDescription(filteredUsers.map(x => `<@${x.Id}> ${x.Currency}`).join("\n")); - - await interaction.reply({ embeds: [ embed ], ephemeral: true }); - } -} \ No newline at end of file diff --git a/src/contracts/SeriesMetadata.ts b/src/contracts/SeriesMetadata.ts index 4a989bc..c363028 100644 --- a/src/contracts/SeriesMetadata.ts +++ b/src/contracts/SeriesMetadata.ts @@ -11,7 +11,6 @@ export interface CardMetadata { name: string, type: CardRarity, path: string, - subseries?: string, } export interface DropResult { diff --git a/src/helpers/CardDropHelperMetadata.ts b/src/helpers/CardDropHelperMetadata.ts index 84bcdfa..982661e 100644 --- a/src/helpers/CardDropHelperMetadata.ts +++ b/src/helpers/CardDropHelperMetadata.ts @@ -81,7 +81,7 @@ export default class CardDropHelperMetadata { public static GenerateDropEmbed(drop: DropResult, quantityClaimed: number, imageFileName: string, claimedBy?: string, currency?: number): EmbedBuilder { AppLogger.LogSilly("CardDropHelperMetadata/GenerateDropEmbed", `Parameters: drop=${drop.card.id}, quantityClaimed=${quantityClaimed}, imageFileName=${imageFileName}`); - const description = drop.card.subseries ?? drop.series.name; + const description = drop.series.name; const embed = new EmbedBuilder() .setTitle(drop.card.name) diff --git a/src/registry.ts b/src/registry.ts index 86b2b68..182418e 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -3,7 +3,6 @@ import { Environment } from "./constants/Environment"; // Global Command Imports import About from "./commands/about"; -import AllBalance from "./commands/allbalance"; import Balance from "./commands/balance"; import Daily from "./commands/daily"; import Drop from "./commands/drop"; @@ -32,7 +31,6 @@ export default class Registry { public static RegisterCommands() { // Global Commands CoreClient.RegisterCommand("about", new About()); - CoreClient.RegisterCommand("allbalance", new AllBalance()); CoreClient.RegisterCommand("balance", new Balance()); CoreClient.RegisterCommand("daily", new Daily()); CoreClient.RegisterCommand("drop", new Drop()); diff --git a/tests/registry.test.ts b/tests/registry.test.ts deleted file mode 100644 index 71d80db..0000000 --- a/tests/registry.test.ts +++ /dev/null @@ -1,66 +0,0 @@ -import {CoreClient} from "../src/client/client"; -import Registry from "../src/registry"; -import fs from "fs"; -import path from "path"; - -describe("RegisterCommands", () => { - test("EXPECT every command in the commands folder to be registered", () => { - const registeredCommands: string[] = []; - - CoreClient.RegisterCommand = jest.fn().mockImplementation((name: string) => { - registeredCommands.push(name); - }); - - Registry.RegisterCommands(); - - const commandFiles = getFilesInDirectory(path.join(process.cwd(), "src", "commands")) - .filter(x => x.endsWith(".ts")); - - for (const file of commandFiles) { - expect(registeredCommands).toContain(file.split("/").pop()!.split(".")[0]); - } - - expect(commandFiles.length).toBe(registeredCommands.length); - }); -}); - -describe("RegisterButtonEvents", () => { - test("EXEPCT every button event in the button events folder to be registered", () => { - const registeredButtonEvents: string[] = []; - - CoreClient.RegisterButtonEvent = jest.fn().mockImplementation((name: string) => { - registeredButtonEvents.push(name); - }); - - Registry.RegisterButtonEvents(); - - const eventFiles = getFilesInDirectory(path.join(process.cwd(), "src", "buttonEvents")) - .filter(x => x.endsWith(".ts")); - - for (const file of eventFiles) { - expect(registeredButtonEvents).toContain(file.split("/").pop()!.split(".")[0].toLowerCase()); - } - - expect(eventFiles.length).toBe(registeredButtonEvents.length); - }); -}); - -function getFilesInDirectory(dir: string): string[] { - let results: string[] = []; - const list = fs.readdirSync(dir); - - list.forEach(file => { - file = path.join(dir, file); - const stat = fs.statSync(file); - - if (stat && stat.isDirectory()) { - /* recurse into a subdirectory */ - results = results.concat(getFilesInDirectory(file)); - } else { - /* is a file */ - results.push(file); - } - }); - - return results; -} diff --git a/yarn.lock b/yarn.lock index b953c94..04ff1b7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1259,9 +1259,9 @@ integrity sha512-QpLcX9ZSsq3YYUUnD3nFDY8H7wctAhQj/TFKL8Ya8v5fMm3CFXxo8zStsLAl780ltoYoo1WvKUVGBQK+1ifr7g== "@types/node@^20.0.0": - version "20.14.11" - resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.11.tgz#09b300423343460455043ddd4d0ded6ac579b74b" - integrity sha512-kprQpL8MMeszbz6ojB5/tU8PLN4kesnN8Gjzw349rDlNgsSzg90lAVj3llK99Dh7JON+t9AuscPPFW6mPbTnSA== + version "20.14.10" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.10.tgz#a1a218290f1b6428682e3af044785e5874db469a" + integrity sha512-MdiXf+nDuMvY0gJKxyfZ7/6UFsETO7mGKF54MVD/ekJS6HdFtpZFBgrh6Pseu64XTb2MLyFPlbW6hj8HYRQNOQ== dependencies: undici-types "~5.26.4" @@ -3217,9 +3217,9 @@ glob-parent@^6.0.2: is-glob "^4.0.3" glob@^10.3.10: - version "10.4.5" - resolved "https://registry.yarnpkg.com/glob/-/glob-10.4.5.tgz#f4d9f0b90ffdbab09c9d77f5f29b4262517b0956" - integrity sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg== + version "10.4.3" + resolved "https://registry.yarnpkg.com/glob/-/glob-10.4.3.tgz#e0ba2253dd21b3d0acdfb5d507c59a29f513fc7a" + integrity sha512-Q38SGlYRpVtDBPSWEylRyctn7uDeTp4NQERTLiCT1FqA9JXPYWqAVmQU6qh4r/zMM5ehxTcbaO8EjhWnvEhmyg== dependencies: foreground-child "^3.1.0" jackspeak "^3.1.2" @@ -3942,9 +3942,9 @@ istanbul-reports@^3.1.3: istanbul-lib-report "^3.0.0" jackspeak@^3.1.2: - version "3.4.3" - resolved "https://registry.yarnpkg.com/jackspeak/-/jackspeak-3.4.3.tgz#8833a9d89ab4acde6188942bd1c53b6390ed5a8a" - integrity sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw== + version "3.4.1" + resolved "https://registry.yarnpkg.com/jackspeak/-/jackspeak-3.4.1.tgz#145422416740568e9fc357bf60c844b3c1585f09" + integrity sha512-U23pQPDnmYybVkYjObcuYMk43VRlMLLqLI+RdZy8s8WV8WsxO9SnqSroKaluuvcNOdCAlauKszDwd+umbot5Mg== dependencies: "@isaacs/cliui" "^8.0.2" optionalDependencies: @@ -4582,10 +4582,10 @@ logform@2.1.2: ms "^2.1.1" triple-beam "^1.3.0" -logform@^2.6.0, logform@^2.6.1: - version "2.6.1" - resolved "https://registry.yarnpkg.com/logform/-/logform-2.6.1.tgz#71403a7d8cae04b2b734147963236205db9b3df0" - integrity sha512-CdaO738xRapbKIMVn2m4F6KTj4j7ooJ8POVnebSgKo3KBz5axNXRAL7ZdRjIV6NOr2Uf4vjtRkxrFETOioCqSA== +logform@^2.3.2, logform@^2.4.0: + version "2.6.0" + resolved "https://registry.yarnpkg.com/logform/-/logform-2.6.0.tgz#8c82a983f05d6eaeb2d75e3decae7a768b2bf9b5" + integrity sha512-1ulHeNPp6k/LD8H91o7VYFBng5i1BDE7HoKxVbZiGFidS1Rj65qcywLxX+pVfAPoQJEjRdvKcusKwOupHCVOVQ== dependencies: "@colors/colors" "1.6.0" "@types/triple-beam" "^1.3.2" @@ -4610,9 +4610,9 @@ lru-cache@^10.0.1: integrity sha512-9hp3Vp2/hFQUiIwKo8XCeFVnrg8Pk3TYNPIR7tJADKi5YfcF7vEaK7avFHTlSy3kOKYaJQaalfEo6YuXdceBOQ== lru-cache@^10.2.0: - version "10.4.3" - resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119" - integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ== + version "10.3.1" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.3.1.tgz#a37050586f84ccfdb570148a253bf1632a29ef44" + integrity sha512-9/8QXrtbGeMB6LxwQd4x1tIMnsmUxMvIH/qWGsccz6bt9Uln3S+sgAaqfQNhbGA8ufzs2fHuP/yqapGgP9Hh2g== lru-cache@^5.1.1: version "5.1.1" @@ -5650,7 +5650,7 @@ readable-stream@^2.3.6: string_decoder "~1.1.1" util-deprecate "~1.0.1" -readable-stream@^3.4.0, readable-stream@^3.6.0, readable-stream@^3.6.2: +readable-stream@^3.4.0, readable-stream@^3.6.0: version "3.6.2" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.2.tgz#56a9b36ea965c00c5a93ef31eb111a0f11056967" integrity sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA== @@ -6741,24 +6741,24 @@ winston-transport@4.3.0: triple-beam "^1.2.0" winston-transport@^4.7.0: - version "4.7.1" - resolved "https://registry.yarnpkg.com/winston-transport/-/winston-transport-4.7.1.tgz#52ff1bcfe452ad89991a0aaff9c3b18e7f392569" - integrity sha512-wQCXXVgfv/wUPOfb2x0ruxzwkcZfxcktz6JIMUaPLmcNhO4bZTwA/WtDWK74xV3F2dKu8YadrFv0qhwYjVEwhA== + version "4.7.0" + resolved "https://registry.yarnpkg.com/winston-transport/-/winston-transport-4.7.0.tgz#e302e6889e6ccb7f383b926df6936a5b781bd1f0" + integrity sha512-ajBj65K5I7denzer2IYW6+2bNIVqLGDHqDw3Ow8Ohh+vdW+rv4MZ6eiDvHoKhfJFZ2auyN8byXieDDJ96ViONg== dependencies: - logform "^2.6.1" - readable-stream "^3.6.2" + logform "^2.3.2" + readable-stream "^3.6.0" triple-beam "^1.3.0" winston@^3.11.0: - version "3.13.1" - resolved "https://registry.yarnpkg.com/winston/-/winston-3.13.1.tgz#53ddadb9c2332eb12cff8306413b3480dc82b6c3" - integrity sha512-SvZit7VFNvXRzbqGHsv5KSmgbEYR5EiQfDAL9gxYkRqa934Hnk++zze0wANKtMHcy/gI4W/3xmSDwlhf865WGw== + version "3.13.0" + resolved "https://registry.yarnpkg.com/winston/-/winston-3.13.0.tgz#e76c0d722f78e04838158c61adc1287201de7ce3" + integrity sha512-rwidmA1w3SE4j0E5MuIufFhyJPBDG7Nu71RkZor1p2+qHvJSZ9GYDA81AyleQcZbh/+V6HjeBdfnTZJm9rSeQQ== dependencies: "@colors/colors" "^1.6.0" "@dabh/diagnostics" "^2.0.2" async "^3.2.3" is-stream "^2.0.0" - logform "^2.6.0" + logform "^2.4.0" one-time "^1.0.0" readable-stream "^3.4.0" safe-stable-stringify "^2.3.1" @@ -6838,10 +6838,10 @@ write-file-atomic@^4.0.2: imurmurhash "^0.1.4" signal-exit "^3.0.7" -ws@^8.16.0, ws@^8.17.1: - version "8.18.0" - resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.0.tgz#0d7505a6eafe2b0e712d232b42279f53bc289bbc" - integrity sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw== +ws@^8.16.0: + version "8.17.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.17.0.tgz#d145d18eca2ed25aaf791a183903f7be5e295fea" + integrity sha512-uJq6108EgZMAl20KagGkzCKfMEjxmKvZHG7Tlq0Z6nOky7YF7aq4mOx6xK8TJ/i1LeK4Qus7INktacctDgY8Ow== xdg-basedir@^5.0.1, xdg-basedir@^5.1.0: version "5.1.0"