From 9ab588468e89cc73cd9243dd7614f7acb1083631 Mon Sep 17 00:00:00 2001 From: WatDuhHekBro <44940783+WatDuhHekBro@users.noreply.github.com> Date: Wed, 16 Dec 2020 01:24:26 -0600 Subject: [PATCH] Added eco monday --- src/commands/fun/eco.ts | 4 ++- src/commands/fun/subcommands/eco-extras.ts | 34 ++++++++++++++++++++++ src/core/structures.ts | 2 ++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/commands/fun/subcommands/eco-extras.ts diff --git a/src/commands/fun/eco.ts b/src/commands/fun/eco.ts index 555f1de..5be316f 100644 --- a/src/commands/fun/eco.ts +++ b/src/commands/fun/eco.ts @@ -2,6 +2,7 @@ import Command from "../../core/command"; import {isAuthorized, getMoneyEmbed} from "./subcommands/eco-utils"; import {DailyCommand, PayCommand, GuildCommand, LeaderboardCommand} from "./subcommands/eco-core"; import {BuyCommand, ShopCommand} from "./subcommands/eco-shop"; +import {MondayCommand} from "./subcommands/eco-extras"; export default new Command({ description: "Economy command for Monika.", @@ -14,7 +15,8 @@ export default new Command({ guild: GuildCommand, leaderboard: LeaderboardCommand, buy: BuyCommand, - shop: ShopCommand + shop: ShopCommand, + monday: MondayCommand }, user: new Command({ description: "See how much money someone else has by using their user ID or pinging them.", diff --git a/src/commands/fun/subcommands/eco-extras.ts b/src/commands/fun/subcommands/eco-extras.ts new file mode 100644 index 0000000..274bb16 --- /dev/null +++ b/src/commands/fun/subcommands/eco-extras.ts @@ -0,0 +1,34 @@ +import Command from "../../../core/command"; +import {Storage} from "../../../core/structures"; +import {isAuthorized, getMoneyEmbed} from "./eco-utils"; + +const WEEKDAY = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; + +export const MondayCommand = new Command({ + description: "Use this on a UTC Monday to get an extra Mon. Does not affect your 22 hour timer for `eco daily`.", + async run({guild, channel, author}) { + if (isAuthorized(guild, channel)) { + const user = Storage.getUser(author.id); + const now = new Date(); + const weekday = now.getUTCDay(); + + // If it's a UTC Monday + if (weekday === 1) { + // If the user hasn't already claimed their Monday reward (checks the last 24 hours because that'll block up the entire day) + if (now.getTime() - user.lastMonday >= 86400000) { + user.money++; + user.lastMonday = now.getTime(); + Storage.save(); + channel.send("It is **Mon**day, my dudes.", getMoneyEmbed(author)); + } else channel.send("You've already claimed your **Mon**day reward for this week."); + } else { + const weekdayName = WEEKDAY[weekday]; + const hourText = now.getUTCHours().toString().padStart(2, "0"); + const minuteText = now.getUTCMinutes().toString().padStart(2, "0"); + channel.send( + `Come back when it's **Mon**day. Right now, it's ${weekdayName}, ${hourText}:${minuteText} (UTC).` + ); + } + } + } +}); diff --git a/src/core/structures.ts b/src/core/structures.ts index 818fb85..1513d0b 100644 --- a/src/core/structures.ts +++ b/src/core/structures.ts @@ -23,10 +23,12 @@ class ConfigStructure extends GenericStructure { class User { public money: number; public lastReceived: number; + public lastMonday: number; constructor(data?: GenericJSON) { this.money = select(data?.money, 0, Number); this.lastReceived = select(data?.lastReceived, -1, Number); + this.lastMonday = select(data?.lastMonday, -1, Number); } }