Compare commits

..

No commits in common. "3d7d058de4e6aef4ff9957783486ef10ac407b8f" and "981acefcf638e6ce797aaac68f13621030577eaf" have entirely different histories.

11 changed files with 9 additions and 99 deletions

View file

@ -1,2 +0,0 @@
ALTER TABLE `user`
ADD LastUsedDaily datetime null;

View file

@ -8,7 +8,6 @@ import CardDropHelperMetadata from "../helpers/CardDropHelperMetadata";
import { readFileSync } from "fs"; import { readFileSync } from "fs";
import path from "path"; import path from "path";
import User from "../database/entities/app/User"; import User from "../database/entities/app/User";
import CardConstants from "../constants/CardConstants";
export default class Claim extends ButtonEvent { export default class Claim extends ButtonEvent {
public override async execute(interaction: ButtonInteraction) { public override async execute(interaction: ButtonInteraction) {
@ -43,11 +42,11 @@ export default class Claim extends ButtonEvent {
await inventory.Save(Inventory, inventory); await inventory.Save(Inventory, inventory);
const user = await User.FetchOneById(User, userId) || new User(userId, CardConstants.StartingCurrency); 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`);
if (!user.RemoveCurrency(CardConstants.ClaimCost)) { if (!user.RemoveCurrency(10)) {
await interaction.reply(`Not enough currency! You need 10 currency, you have ${user.Currency}`); await interaction.reply(`Not enough currency! You need 10 currency, you have ${user.Currency}`);
return; return;
} }

View file

@ -24,11 +24,6 @@ export default class Sacrifice extends ButtonEvent {
const userId = interaction.customId.split(" ")[2]; const userId = interaction.customId.split(" ")[2];
const cardNumber = interaction.customId.split(" ")[3]; const cardNumber = interaction.customId.split(" ")[3];
if (userId != interaction.user.id) {
await interaction.reply("Only the user who created this sacrifice can confirm it.");
return;
}
const cardInInventory = await Inventory.FetchOneByCardNumberAndUserId(userId, cardNumber); const cardInInventory = await Inventory.FetchOneByCardNumberAndUserId(userId, cardNumber);
if (!cardInInventory) { if (!cardInInventory) {
@ -72,8 +67,8 @@ export default class Sacrifice extends ButtonEvent {
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle("Card Sacrificed") .setTitle("Card Sacrificed")
.setDescription(description.join("\n")) .setDescription(description.join("\n"))
.setColor(EmbedColours.Green) .setColor(EmbedColours.Ok)
.setFooter({ text: `${interaction.user.username}` }); .setFooter({ text: `${interaction.user.username} · ${cardData.card.name}` });
const row = new ActionRowBuilder<ButtonBuilder>() const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents([ .addComponents([
@ -99,11 +94,6 @@ export default class Sacrifice extends ButtonEvent {
const userId = interaction.customId.split(" ")[2]; const userId = interaction.customId.split(" ")[2];
const cardNumber = interaction.customId.split(" ")[3]; const cardNumber = interaction.customId.split(" ")[3];
if (userId != interaction.user.id) {
await interaction.reply("Only the user who created this sacrifice can cancel it.");
return;
}
const cardInInventory = await Inventory.FetchOneByCardNumberAndUserId(userId, cardNumber); const cardInInventory = await Inventory.FetchOneByCardNumberAndUserId(userId, cardNumber);
if (!cardInInventory) { if (!cardInInventory) {
@ -132,8 +122,8 @@ export default class Sacrifice extends ButtonEvent {
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle("Sacrifice Cancelled") .setTitle("Sacrifice Cancelled")
.setDescription(description.join("\n")) .setDescription(description.join("\n"))
.setColor(EmbedColours.Grey) .setColor(EmbedColours.Error)
.setFooter({ text: `${interaction.user.username}` }); .setFooter({ text: `${interaction.user.username} · ${cardData.card.name}` });
const row = new ActionRowBuilder<ButtonBuilder>() const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents([ .addComponents([

View file

@ -1,43 +0,0 @@
import { CommandInteraction, SlashCommandBuilder } from "discord.js";
import { Command } from "../type/command";
import User from "../database/entities/app/User";
import CardConstants from "../constants/CardConstants";
import TimeLengthInput from "../helpers/TimeLengthInput";
export default class Daily extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName("daily")
.setDescription("Gain bonus currency, once a day");
}
public override async execute(interaction: CommandInteraction) {
const user = await User.FetchOneById(User, interaction.user.id) ?? new User(interaction.user.id, CardConstants.StartingCurrency);
const dayAgo = new Date(Date.now() - (1000 * 60 * 60 * 24));
if (user.LastUsedDaily && user.LastUsedDaily > dayAgo) {
const timeNow = Date.now();
const timeLength = 24 * 60 * 60 * 1000; // 1 day
const timeLeft = Math.ceil(((timeLength - (timeNow - user.LastUsedDaily.getTime()))) / 1000 / 60);
const timeLeftHours = Math.floor(timeLeft / 60);
const timeLeftMinutes = timeLeft % 60;
const timeLeftString = new TimeLengthInput(`${timeLeftHours}h ${timeLeftMinutes}m`);
await interaction.reply(`You have already used the daily command! You can use it again in **${timeLeftString.GetLength()}**.`);
return;
}
user.AddCurrency(CardConstants.DailyCurrency);
user.UpdateLastUsedDaily(new Date());
await user.Save(User, user);
await interaction.reply(`Given ${CardConstants.DailyCurrency} currency to ${interaction.user.username}`);
}
}

View file

@ -50,8 +50,8 @@ export default class Sacrifice extends Command {
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle("Sacrifice") .setTitle("Sacrifice")
.setDescription(description.join("\n")) .setDescription(description.join("\n"))
.setColor(EmbedColours.Error) .setColor(EmbedColours.Grey)
.setFooter({ text: `${interaction.user.username}` }); .setFooter({ text: `${interaction.user.username} · ${cardData.card.name}` });
const row = new ActionRowBuilder<ButtonBuilder>() const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents([ .addComponents([

View file

@ -1,6 +1,3 @@
export default class CardConstants { export default class CardConstants {
public static readonly ClaimCost = 10;
public static readonly TimerGiveAmount = 10; public static readonly TimerGiveAmount = 10;
public static readonly DailyCurrency = 100;
public static readonly StartingCurrency = 300;
} }

View file

@ -1,14 +1,8 @@
export default class EmbedColours { export default class EmbedColours {
// General
public static readonly Ok = 0x3050ba; public static readonly Ok = 0x3050ba;
public static readonly Success = 0x50c878; public static readonly Success = 0x50c878;
public static readonly Error = 0xff0000; public static readonly Error = 0xff0000;
// Colours
public static readonly Grey = 0xd3d3d3; public static readonly Grey = 0xd3d3d3;
public static readonly Green = 0x228B22;
// Card Types
public static readonly BronzeCard = 0xcd7f32; public static readonly BronzeCard = 0xcd7f32;
public static readonly SilverCard = 0xc0c0c0; public static readonly SilverCard = 0xc0c0c0;
public static readonly GoldCard = 0xffd700; public static readonly GoldCard = 0xffd700;

View file

@ -13,9 +13,6 @@ export default class User extends AppBaseEntity {
@Column() @Column()
Currency: number; Currency: number;
@Column()
LastUsedDaily?: Date;
public AddCurrency(amount: number) { public AddCurrency(amount: number) {
this.Currency += amount; this.Currency += amount;
} }
@ -27,8 +24,4 @@ export default class User extends AppBaseEntity {
return true; return true;
} }
public UpdateLastUsedDaily(lastUsedDaily: Date) {
this.LastUsedDaily = lastUsedDaily;
}
} }

View file

@ -1,15 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import MigrationHelper from "../../../../helpers/MigrationHelper";
export class Daily1715967355818 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
MigrationHelper.Up("1715967355818-daily", "0.6", [
"01-table/User",
], queryRunner);
}
public async down(): Promise<void> {
}
}

View file

@ -35,8 +35,7 @@ export default class InventoryHelper {
.filter(x => { .filter(x => {
x.cards = x.cards x.cards = x.cards
.sort((a, b) => b.type - a.type) .sort((a, b) => b.type - a.type)
.filter(y => inventory.find(z => z.CardNumber == y.id)) .filter(y => inventory.find(z => z.CardNumber == y.id));
.filter(y => inventory.find(z => z.CardNumber == y.id)!.Quantity > 0);
return x; return x;
}); });

View file

@ -3,7 +3,6 @@ import { Environment } from "./constants/Environment";
// Global Command Imports // Global Command Imports
import About from "./commands/about"; import About from "./commands/about";
import Daily from "./commands/daily";
import Drop from "./commands/drop"; import Drop from "./commands/drop";
import Gdrivesync from "./commands/gdrivesync"; import Gdrivesync from "./commands/gdrivesync";
import Give from "./commands/give"; import Give from "./commands/give";
@ -30,7 +29,6 @@ export default class Registry {
public static RegisterCommands() { public static RegisterCommands() {
// Global Commands // Global Commands
CoreClient.RegisterCommand("about", new About()); CoreClient.RegisterCommand("about", new About());
CoreClient.RegisterCommand("daily", new Daily());
CoreClient.RegisterCommand("drop", new Drop()); CoreClient.RegisterCommand("drop", new Drop());
CoreClient.RegisterCommand("gdrivesync", new Gdrivesync()); CoreClient.RegisterCommand("gdrivesync", new Gdrivesync());
CoreClient.RegisterCommand("give", new Give()); CoreClient.RegisterCommand("give", new Give());