TravBot-v3/src/commands/fun/modules/eco-extras.ts

75 lines
3.3 KiB
TypeScript
Raw Normal View History

import {Command, NamedCommand} from "onion-lasers";
2020-12-16 07:24:26 +00:00
import {isAuthorized, getMoneyEmbed} from "./eco-utils";
import {User as DiscordUser} from "discord.js";
import {User, pluralise} from "../../../lib";
2020-12-16 07:24:26 +00:00
const WEEKDAY = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
export const MondayCommand = new NamedCommand({
2020-12-16 07:24:26 +00:00
description: "Use this on a UTC Monday to get an extra Mon. Does not affect your 22 hour timer for `eco daily`.",
2021-04-10 13:34:55 +00:00
async run({send, guild, channel, author}) {
2020-12-16 07:24:26 +00:00
if (isAuthorized(guild, channel)) {
const user = new User(author.id);
2020-12-16 07:24:26 +00:00
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();
2021-11-03 11:18:26 +00:00
send({content: "It is **Mon**day, my dudes.", embeds: [getMoneyEmbed(author, true)]});
2021-04-10 13:34:55 +00:00
} else send("You've already claimed your **Mon**day reward for this week.");
2020-12-16 07:24:26 +00:00
} else {
const weekdayName = WEEKDAY[weekday];
const hourText = now.getUTCHours().toString().padStart(2, "0");
const minuteText = now.getUTCMinutes().toString().padStart(2, "0");
2021-04-10 13:34:55 +00:00
send(
2020-12-16 07:24:26 +00:00
`Come back when it's **Mon**day. Right now, it's ${weekdayName}, ${hourText}:${minuteText} (UTC).`
);
}
}
}
});
2021-04-08 11:37:49 +00:00
export const AwardCommand = new NamedCommand({
description: "Only usable by Mon, awards one or a specified amount of Mons to the user.",
usage: "<user> (<amount>)",
aliases: ["give"],
run: "You need to specify a user!",
user: new Command({
async run({send, author, args}) {
if (author.id === "394808963356688394" || process.env.DEV) {
const target = args[0] as DiscordUser;
const user = new User(target.id);
2021-04-08 11:37:49 +00:00
user.money++;
2021-11-03 11:18:26 +00:00
send({content: `1 Mon given to ${target.username}.`, embeds: [getMoneyEmbed(target, true)]});
2021-04-08 11:37:49 +00:00
} else {
2021-04-10 13:34:55 +00:00
send("This command is restricted to the bean.");
2021-04-08 11:37:49 +00:00
}
},
number: new Command({
async run({send, author, args}) {
if (author.id === "394808963356688394" || process.env.DEV) {
const target = args[0] as DiscordUser;
2021-04-08 11:37:49 +00:00
const amount = Math.floor(args[1]);
if (amount > 0) {
const user = new User(target.id);
2021-04-08 11:37:49 +00:00
user.money += amount;
send({
content: `${pluralise(amount, "Mon", "s")} given to ${target.username}.`,
2021-11-03 11:18:26 +00:00
embeds: [getMoneyEmbed(target, true)]
});
2021-04-08 11:37:49 +00:00
} else {
2021-04-10 13:34:55 +00:00
send("You need to enter a number greater than 0.");
2021-04-08 11:37:49 +00:00
}
} else {
2021-04-10 13:34:55 +00:00
send("This command is restricted to the bean.");
2021-04-08 11:37:49 +00:00
}
}
})
})
});