Compare commits

...

5 commits

Author SHA1 Message Date
25d099928f Fix requested changes
Some checks failed
Test / build (push) Failing after 2m28s
2024-05-15 17:55:17 +01:00
facdf066a1 Merge branch 'develop' into feature/204-coins-cron 2024-05-15 17:53:25 +01:00
5a8ec932b4 Update dependency glob to v10.3.15 (#222)
All checks were successful
Deploy To Stage / build (push) Successful in 10s
Deploy To Stage / deploy (push) Successful in 16s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [glob](https://github.com/isaacs/node-glob) | dependencies | patch | [`10.3.12` -> `10.3.15`](https://renovatebot.com/diffs/npm/glob/10.3.12/10.3.15) |

---

### Release Notes

<details>
<summary>isaacs/node-glob (glob)</summary>

### [`v10.3.15`](https://github.com/isaacs/node-glob/compare/v10.3.14...v10.3.15)

[Compare Source](https://github.com/isaacs/node-glob/compare/v10.3.14...v10.3.15)

### [`v10.3.14`](https://github.com/isaacs/node-glob/compare/v10.3.13...v10.3.14)

[Compare Source](https://github.com/isaacs/node-glob/compare/v10.3.13...v10.3.14)

### [`v10.3.13`](https://github.com/isaacs/node-glob/compare/v10.3.12...v10.3.13)

[Compare Source](https://github.com/isaacs/node-glob/compare/v10.3.12...v10.3.13)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->

Reviewed-on: #222
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
2024-05-13 15:18:20 +01:00
b9264e23db Update dependency @types/node to v20.12.11 (#221)
All checks were successful
Deploy To Stage / build (push) Successful in 2m28s
Deploy To Stage / deploy (push) Successful in 14s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node) ([source](https://github.com/DefinitelyTyped/DefinitelyTyped)) | devDependencies | patch | [`20.12.8` -> `20.12.11`](https://renovatebot.com/diffs/npm/@types%2fnode/20.12.8/20.12.11) |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->

Reviewed-on: #221
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
2024-05-13 15:15:21 +01:00
de14723df0 Update give command to allow currency to be given (#220)
All checks were successful
Deploy To Stage / build (push) Successful in 2m31s
Deploy To Stage / deploy (push) Successful in 14s
# Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

- Update the give command to have the existing card functionality moved to a subcommand
- Add a subcommand to the give command to allow currency to be given

#206

## Type of change

Please delete options that are not relevant.

- [x] New feature (non-breaking change which adds functionality)

# How Has This Been Tested?

Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration.

# Checklist

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that provde my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules

Reviewed-on: #220
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2024-05-11 12:48:48 +01:00
7 changed files with 84 additions and 43 deletions

24
package-lock.json generated
View file

@ -1906,9 +1906,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "20.12.8", "version": "20.12.11",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.8.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.11.tgz",
"integrity": "sha512-NU0rJLJnshZWdE/097cdCBbyW1h4hEg0xpovcoAQYHl8dnEyp/NAOiE45pvc+Bd1Dt+2r94v2eGFpQJ4R7g+2w==", "integrity": "sha512-vDg9PZ/zi+Nqp6boSOT7plNuthRugEKixDv5sFTIpkE89MmNtEArAShI4mxuX2+UrLEe9pxC1vm2cjm9YlWbJw==",
"dependencies": { "dependencies": {
"undici-types": "~5.26.4" "undici-types": "~5.26.4"
} }
@ -5169,21 +5169,21 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/glob": { "node_modules/glob": {
"version": "10.3.12", "version": "10.3.15",
"resolved": "https://registry.npmjs.org/glob/-/glob-10.3.12.tgz", "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.15.tgz",
"integrity": "sha512-TCNv8vJ+xz4QiqTpfOJA7HvYv+tNIRHKfUWw/q+v2jdgN4ebz+KY9tGx5J4rHP0o84mNP+ApH66HRX8us3Khqg==", "integrity": "sha512-0c6RlJt1TICLyvJYIApxb8GsXoai0KUP7AxKKAtsYXdgJR1mGEUa7DgwShbdk1nly0PYoZj01xd4hzbq3fsjpw==",
"dependencies": { "dependencies": {
"foreground-child": "^3.1.0", "foreground-child": "^3.1.0",
"jackspeak": "^2.3.6", "jackspeak": "^2.3.6",
"minimatch": "^9.0.1", "minimatch": "^9.0.1",
"minipass": "^7.0.4", "minipass": "^7.0.4",
"path-scurry": "^1.10.2" "path-scurry": "^1.11.0"
}, },
"bin": { "bin": {
"glob": "dist/esm/bin.mjs" "glob": "dist/esm/bin.mjs"
}, },
"engines": { "engines": {
"node": ">=16 || 14 >=14.17" "node": ">=16 || 14 >=14.18"
}, },
"funding": { "funding": {
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
@ -9358,15 +9358,15 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/path-scurry": { "node_modules/path-scurry": {
"version": "1.10.2", "version": "1.11.1",
"resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.2.tgz", "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz",
"integrity": "sha512-7xTavNy5RQXnsjANvVvMkEjvloOinkAjv/Z6Ildz9v2RinZ4SBKTWFOVRbaF8p0vpHnyjV/UwNDdKuUv6M5qcA==", "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==",
"dependencies": { "dependencies": {
"lru-cache": "^10.2.0", "lru-cache": "^10.2.0",
"minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0"
}, },
"engines": { "engines": {
"node": ">=16 || 14 >=14.17" "node": ">=16 || 14 >=14.18"
}, },
"funding": { "funding": {
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"

View file

@ -4,8 +4,6 @@ import { IntentsBitField } from "discord.js";
import Registry from "./registry"; import Registry from "./registry";
import { existsSync } from "fs"; import { existsSync } from "fs";
import { ExecException, exec } from "child_process"; import { ExecException, exec } from "child_process";
import TimerHelper from "./helpers/TimerHelper";
import GiveCurrency from "./timers/GiveCurrency";
dotenv.config(); dotenv.config();
@ -39,7 +37,6 @@ const client = new CoreClient([
]); ]);
Registry.RegisterCommands(); Registry.RegisterCommands();
Registry.RegisterEvents();
Registry.RegisterButtonEvents(); Registry.RegisterButtonEvents();
if (!existsSync(`${process.env.DATA_DIR}/cards`) && process.env.GDRIVESYNC_AUTO && process.env.GDRIVESYNC_AUTO == "true") { if (!existsSync(`${process.env.DATA_DIR}/cards`) && process.env.GDRIVESYNC_AUTO && process.env.GDRIVESYNC_AUTO == "true") {

View file

@ -42,7 +42,7 @@ export default class Claim extends ButtonEvent {
await inventory.Save(Inventory, inventory); await inventory.Save(Inventory, inventory);
let user = await User.FetchOneById(User, userId) || new User(userId, 300); const user = await User.FetchOneById(User, userId) || new User(userId, 300);
AppLogger.LogSilly("Button/Claim", `${user.Id} has ${user.Currency} currency`); AppLogger.LogSilly("Button/Claim", `${user.Id} has ${user.Currency} currency`);

View file

@ -5,6 +5,7 @@ import Config from "../database/entities/app/Config";
import CardDropHelperMetadata from "../helpers/CardDropHelperMetadata"; import CardDropHelperMetadata from "../helpers/CardDropHelperMetadata";
import Inventory from "../database/entities/app/Inventory"; import Inventory from "../database/entities/app/Inventory";
import AppLogger from "../client/appLogger"; import AppLogger from "../client/appLogger";
import User from "../database/entities/app/User";
export default class Give extends Command { export default class Give extends Command {
constructor() { constructor() {
@ -14,19 +15,57 @@ export default class Give extends Command {
.setName("give") .setName("give")
.setDescription("Give a user a card manually, in case bot breaks") .setDescription("Give a user a card manually, in case bot breaks")
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator) .setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator)
.addStringOption(x => .addSubcommand(x =>
x x
.setName("cardnumber") .setName("card")
.setDescription("G") .setDescription("Give a user a card manually")
.setRequired(true)) .addStringOption(x =>
.addUserOption(x => x
.setName("cardnumber")
.setDescription("The card to give")
.setRequired(true))
.addUserOption(x =>
x
.setName("user")
.setDescription("The user to give the card to")
.setRequired(true)))
.addSubcommand(x =>
x x
.setName("user") .setName("currency")
.setDescription("The user to give the card to") .setDescription("Give a user currency manually")
.setRequired(true)); .addNumberOption(x =>
x
.setName("amount")
.setDescription("The amount to give")
.setRequired(true))
.addUserOption(x =>
x
.setName("user")
.setDescription("The user to give the currency to")
.setRequired(true)));
} }
public override async execute(interaction: CommandInteraction<CacheType>) { public override async execute(interaction: CommandInteraction<CacheType>) {
if (!interaction.isChatInputCommand()) return;
const whitelistedUsers = process.env.BOT_ADMINS!.split(",");
if (!whitelistedUsers.find(x => x == interaction.user.id)) {
await interaction.reply("Only whitelisted users can use this command.");
return;
}
switch (interaction.options.getSubcommand()) {
case "card":
await this.GiveCard(interaction);
break;
case "currency":
await this.GiveCurrency(interaction);
break;
}
}
private async GiveCard(interaction: CommandInteraction) {
if (!CoreClient.AllowDrops) { if (!CoreClient.AllowDrops) {
await interaction.reply("Bot is currently syncing, please wait until its done."); await interaction.reply("Bot is currently syncing, please wait until its done.");
return; return;
@ -37,17 +76,10 @@ export default class Give extends Command {
return; return;
} }
const whitelistedUsers = process.env.BOT_ADMINS!.split(",");
if (!whitelistedUsers.find(x => x == interaction.user.id)) {
await interaction.reply("Only whitelisted users can use this command.");
return;
}
const cardNumber = interaction.options.get("cardnumber", true); const cardNumber = interaction.options.get("cardnumber", true);
const user = interaction.options.getUser("user", true); const user = interaction.options.getUser("user", true);
AppLogger.LogSilly("Commands/Give", `Parameters: cardNumber=${cardNumber.value}, user=${user.id}`); AppLogger.LogSilly("Commands/Give/GiveCard", `Parameters: cardNumber=${cardNumber.value}, user=${user.id}`);
const card = CardDropHelperMetadata.GetCardByCardNumber(cardNumber.value!.toString()); const card = CardDropHelperMetadata.GetCardByCardNumber(cardNumber.value!.toString());
@ -66,6 +98,21 @@ export default class Give extends Command {
await inventory.Save(Inventory, inventory); await inventory.Save(Inventory, inventory);
await interaction.reply(`${card.card.name} given to ${user.username}, they now have ${inventory.Quantity}`); await interaction.reply(`Card ${card.card.name} given to ${user.username}, they now have ${inventory.Quantity}`);
}
private async GiveCurrency(interaction: CommandInteraction) {
const amount = interaction.options.get("amount", true);
const user = interaction.options.getUser("user", true);
AppLogger.LogSilly("Commands/Give/GiveCurrency", `Parameters: amount=${amount.value} user=${user.id}`);
const userEntity = await User.FetchOneById(User, user.id) || new User(user.id, 300);
userEntity.AddCurrency(amount.value! as number);
await userEntity.Save(User, userEntity);
await interaction.reply(`${amount.value} currency ${amount.value! as number >= 0 ? "given to" : "taken from"} ${user.username}, they now have ${userEntity.Currency}`);
} }
} }

View file

@ -17,6 +17,10 @@ export default class User extends AppBaseEntity {
this.Currency += amount; this.Currency += amount;
} }
public AddCurrency(amount: number) {
this.Currency += amount;
}
public RemoveCurrency(amount: number): boolean { public RemoveCurrency(amount: number): boolean {
if (this.Currency < amount) return false; if (this.Currency < amount) return false;

View file

@ -41,10 +41,6 @@ export default class Registry {
CoreClient.RegisterCommand("droprarity", new Droprarity(), Environment.Test); CoreClient.RegisterCommand("droprarity", new Droprarity(), Environment.Test);
} }
public static RegisterEvents() {
}
public static RegisterButtonEvents() { public static RegisterButtonEvents() {
CoreClient.RegisterButtonEvent("claim", new Claim()); CoreClient.RegisterButtonEvent("claim", new Claim());
CoreClient.RegisterButtonEvent("inventory", new InventoryButtonEvent()); CoreClient.RegisterButtonEvent("inventory", new InventoryButtonEvent());
@ -52,8 +48,4 @@ export default class Registry {
CoreClient.RegisterButtonEvent("series", new SeriesEvent()); CoreClient.RegisterButtonEvent("series", new SeriesEvent());
CoreClient.RegisterButtonEvent("trade", new TradeButtonEvent()); CoreClient.RegisterButtonEvent("trade", new TradeButtonEvent());
} }
public static RegisterTimers() {
}
} }

View file

@ -1,7 +1,8 @@
import { CommandInteraction, SlashCommandBuilder } from "discord.js"; import { CommandInteraction } from "discord.js";
export abstract class Command { export abstract class Command {
public CommandBuilder: Omit<SlashCommandBuilder, "addSubcommand" | "addSubcommandGroup">; // eslint-disable-next-line @typescript-eslint/no-explicit-any -- CommandBuilder type is dynamic depending on options and can't be strictly typed
public CommandBuilder: any;
abstract execute(interaction: CommandInteraction): Promise<void>; abstract execute(interaction: CommandInteraction): Promise<void>;
} }