2021-04-17 15:21:17 +00:00
|
|
|
import {Command, getUserByNickname, NamedCommand, confirm, RestCommand} from "onion-lasers";
|
2021-07-13 16:20:04 +00:00
|
|
|
import moment from "moment";
|
2021-04-05 04:35:12 +00:00
|
|
|
import {pluralise} from "../../../lib";
|
|
|
|
import {Storage} from "../../../structures";
|
2020-12-15 11:15:28 +00:00
|
|
|
import {isAuthorized, getMoneyEmbed, getSendEmbed, ECO_EMBED_COLOR} from "./eco-utils";
|
2021-07-13 16:20:04 +00:00
|
|
|
import {Collection} from "discord.js";
|
|
|
|
|
|
|
|
const lastUsedTimestamps = new Collection<string, number>();
|
2020-11-04 08:04:07 +00:00
|
|
|
|
2021-04-05 04:35:12 +00:00
|
|
|
export const DailyCommand = new NamedCommand({
|
2020-12-15 07:56:09 +00:00
|
|
|
description: "Pick up your daily Mons. The cooldown is per user and every 22 hours to allow for some leeway.",
|
2020-12-15 23:29:40 +00:00
|
|
|
aliases: ["get"],
|
2021-04-10 13:34:55 +00:00
|
|
|
async run({send, author, channel, guild}) {
|
2020-12-15 01:44:28 +00:00
|
|
|
if (isAuthorized(guild, channel)) {
|
|
|
|
const user = Storage.getUser(author.id);
|
|
|
|
const now = Date.now();
|
|
|
|
|
2021-07-13 16:20:04 +00:00
|
|
|
const startTime = Date.now();
|
|
|
|
const cooldown = 3600000;
|
|
|
|
const lastUsedTimestamp = lastUsedTimestamps.get(guild!.id) ?? 0;
|
|
|
|
const difference = startTime - lastUsedTimestamp;
|
|
|
|
const howLong = moment(startTime).to(lastUsedTimestamp + cooldown);
|
|
|
|
|
|
|
|
if (difference < cooldown) {
|
|
|
|
await send(
|
|
|
|
`This command requires half an hour to cooldown. You'll be able to use this command ${howLong}.`
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
} else lastUsedTimestamps.set(guild!.id, startTime);
|
|
|
|
|
2020-12-15 01:44:28 +00:00
|
|
|
if (now - user.lastReceived >= 79200000) {
|
|
|
|
user.money++;
|
|
|
|
user.lastReceived = now;
|
|
|
|
Storage.save();
|
2021-07-13 16:20:04 +00:00
|
|
|
await send({
|
2020-12-15 01:44:28 +00:00
|
|
|
embed: {
|
|
|
|
title: "Daily Reward",
|
|
|
|
description: "You received 1 Mon!",
|
2021-06-23 02:13:56 +00:00
|
|
|
color: ECO_EMBED_COLOR,
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
name: "New balance:",
|
|
|
|
value: pluralise(user.money, "Mon", "s")
|
|
|
|
}
|
|
|
|
]
|
2020-12-15 01:44:28 +00:00
|
|
|
}
|
|
|
|
});
|
2021-07-13 16:20:04 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
await send({
|
2020-12-15 01:44:28 +00:00
|
|
|
embed: {
|
|
|
|
title: "Daily Reward",
|
2021-07-03 22:53:30 +00:00
|
|
|
description: `It's too soon to pick up your daily Mons. Try again at <t:${Math.floor(
|
2021-07-03 22:56:53 +00:00
|
|
|
(user.lastReceived + 79200000) / 1000
|
2021-07-03 22:53:30 +00:00
|
|
|
)}:t>.`,
|
2020-12-15 11:15:28 +00:00
|
|
|
color: ECO_EMBED_COLOR
|
2020-12-15 01:44:28 +00:00
|
|
|
}
|
|
|
|
});
|
2021-07-13 16:20:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-12-15 01:44:28 +00:00
|
|
|
}
|
2021-07-13 16:20:04 +00:00
|
|
|
},
|
|
|
|
subcommands: {
|
|
|
|
cooldown: new NamedCommand({
|
|
|
|
description: "Forces the cooldown timer to reset.",
|
|
|
|
permission: PERMISSIONS.BOT_SUPPORT,
|
|
|
|
async run({send, guild}) {
|
|
|
|
lastUsedTimestamps.set(guild!.id, 0);
|
|
|
|
send("Reset the cooldown on `.eco daily`.");
|
|
|
|
}
|
|
|
|
})
|
2020-11-04 08:04:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-05 04:35:12 +00:00
|
|
|
export const GuildCommand = new NamedCommand({
|
2020-12-15 11:15:28 +00:00
|
|
|
description: "Get info on the guild's economy as a whole.",
|
2021-04-10 13:34:55 +00:00
|
|
|
async run({send, guild, channel}) {
|
2020-12-15 11:15:28 +00:00
|
|
|
if (isAuthorized(guild, channel)) {
|
|
|
|
const users = Storage.users;
|
|
|
|
let totalAmount = 0;
|
|
|
|
|
|
|
|
for (const ID in users) {
|
|
|
|
const user = users[ID];
|
|
|
|
totalAmount += user.money;
|
|
|
|
}
|
|
|
|
|
2021-04-10 13:34:55 +00:00
|
|
|
send({
|
2020-12-15 11:15:28 +00:00
|
|
|
embed: {
|
|
|
|
title: `The Bank of ${guild!.name}`,
|
|
|
|
color: ECO_EMBED_COLOR,
|
|
|
|
fields: [
|
|
|
|
{
|
|
|
|
name: "Accounts",
|
|
|
|
value: Object.keys(users).length,
|
|
|
|
inline: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Total Mons",
|
|
|
|
value: totalAmount,
|
|
|
|
inline: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
thumbnail: {
|
|
|
|
url: guild?.iconURL() ?? ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-05 04:35:12 +00:00
|
|
|
export const LeaderboardCommand = new NamedCommand({
|
2020-12-15 01:44:28 +00:00
|
|
|
description: "See the richest players.",
|
2020-12-15 23:29:40 +00:00
|
|
|
aliases: ["top"],
|
2021-04-10 13:34:55 +00:00
|
|
|
async run({send, guild, channel, client}) {
|
2020-12-15 01:44:28 +00:00
|
|
|
if (isAuthorized(guild, channel)) {
|
|
|
|
const users = Storage.users;
|
|
|
|
const ids = Object.keys(users);
|
|
|
|
ids.sort((a, b) => users[b].money - users[a].money);
|
|
|
|
const fields = [];
|
|
|
|
|
|
|
|
for (let i = 0, limit = Math.min(10, ids.length); i < limit; i++) {
|
|
|
|
const id = ids[i];
|
|
|
|
const user = await client.users.fetch(id);
|
|
|
|
|
|
|
|
fields.push({
|
2021-04-11 08:02:56 +00:00
|
|
|
name: `#${i + 1}. ${user.tag}`,
|
2021-03-30 10:25:07 +00:00
|
|
|
value: pluralise(users[id].money, "Mon", "s")
|
2020-12-15 01:44:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-10 13:34:55 +00:00
|
|
|
send({
|
2020-12-15 01:44:28 +00:00
|
|
|
embed: {
|
|
|
|
title: "Top 10 Richest Players",
|
2020-12-15 11:15:28 +00:00
|
|
|
color: ECO_EMBED_COLOR,
|
|
|
|
fields: fields,
|
|
|
|
thumbnail: {
|
|
|
|
url: guild?.iconURL() ?? ""
|
|
|
|
}
|
2020-12-15 01:44:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-11-04 08:04:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-05 04:35:12 +00:00
|
|
|
export const PayCommand = new NamedCommand({
|
2020-12-15 01:44:28 +00:00
|
|
|
description: "Send money to someone.",
|
|
|
|
usage: "<user> <amount>",
|
|
|
|
run: "Who are you sending this money to?",
|
2021-04-06 06:15:17 +00:00
|
|
|
id: "user",
|
2020-12-15 01:44:28 +00:00
|
|
|
user: new Command({
|
|
|
|
run: "You need to enter an amount you're sending!",
|
|
|
|
number: new Command({
|
2021-04-10 13:34:55 +00:00
|
|
|
async run({send, args, author, channel, guild}): Promise<any> {
|
2020-12-15 01:44:28 +00:00
|
|
|
if (isAuthorized(guild, channel)) {
|
|
|
|
const amount = Math.floor(args[1]);
|
|
|
|
const sender = Storage.getUser(author.id);
|
|
|
|
const target = args[0];
|
|
|
|
const receiver = Storage.getUser(target.id);
|
|
|
|
|
2021-04-10 13:34:55 +00:00
|
|
|
if (amount <= 0) return send("You must send at least one Mon!");
|
2020-12-15 01:44:28 +00:00
|
|
|
else if (sender.money < amount)
|
2021-04-10 13:34:55 +00:00
|
|
|
return send("You don't have enough Mons for that.", getMoneyEmbed(author));
|
|
|
|
else if (target.id === author.id) return send("You can't send Mons to yourself!");
|
2021-04-10 19:08:36 +00:00
|
|
|
else if (target.bot && !IS_DEV_MODE) return send("You can't send Mons to a bot!");
|
2020-12-15 01:44:28 +00:00
|
|
|
|
|
|
|
sender.money -= amount;
|
|
|
|
receiver.money += amount;
|
|
|
|
Storage.save();
|
2021-04-10 13:34:55 +00:00
|
|
|
return send(getSendEmbed(author, target, amount));
|
2020-12-15 01:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}),
|
2020-11-04 08:04:07 +00:00
|
|
|
number: new Command({
|
2020-12-15 23:46:03 +00:00
|
|
|
run: "You must use the format `eco pay <user> <amount>`!"
|
2020-11-04 08:04:07 +00:00
|
|
|
}),
|
2021-04-10 17:07:55 +00:00
|
|
|
any: new RestCommand({
|
2021-05-06 13:30:51 +00:00
|
|
|
async run({send, args, author, channel, guild}) {
|
2020-12-15 01:44:28 +00:00
|
|
|
if (isAuthorized(guild, channel)) {
|
|
|
|
const last = args.pop();
|
|
|
|
|
2021-04-10 13:34:55 +00:00
|
|
|
if (!/\d+/g.test(last) && args.length === 0) return send("You need to enter an amount you're sending!");
|
2020-12-15 01:44:28 +00:00
|
|
|
|
|
|
|
const amount = Math.floor(last);
|
|
|
|
const sender = Storage.getUser(author.id);
|
|
|
|
|
2021-04-10 13:34:55 +00:00
|
|
|
if (amount <= 0) return send("You must send at least one Mon!");
|
2020-12-15 01:44:28 +00:00
|
|
|
else if (sender.money < amount)
|
2021-04-10 13:34:55 +00:00
|
|
|
return send("You don't have enough Mons to do that!", getMoneyEmbed(author));
|
2020-12-15 01:44:28 +00:00
|
|
|
else if (!guild)
|
2021-04-10 13:34:55 +00:00
|
|
|
return send("You have to use this in a server if you want to send Mons with a username!");
|
2020-12-15 01:44:28 +00:00
|
|
|
|
2021-05-06 13:30:51 +00:00
|
|
|
// Do NOT use the combined parameter here, it won't account for args.pop() at the start.
|
|
|
|
const user = await getUserByNickname(args.join(" "), guild);
|
2021-04-17 15:21:17 +00:00
|
|
|
if (typeof user === "string") return send(user);
|
|
|
|
else if (user.id === author.id) return send("You can't send Mons to yourself!");
|
|
|
|
else if (user.bot && !IS_DEV_MODE) return send("You can't send Mons to a bot!");
|
2020-12-15 01:44:28 +00:00
|
|
|
|
2021-04-17 15:21:17 +00:00
|
|
|
const confirmed = await confirm(
|
2021-04-11 08:02:56 +00:00
|
|
|
await send(`Are you sure you want to send ${pluralise(amount, "Mon", "s")} to this person?`, {
|
|
|
|
embed: {
|
|
|
|
color: ECO_EMBED_COLOR,
|
|
|
|
author: {
|
2021-04-17 15:21:17 +00:00
|
|
|
name: user.tag,
|
|
|
|
icon_url: user.displayAvatarURL({
|
2021-04-11 08:02:56 +00:00
|
|
|
format: "png",
|
|
|
|
dynamic: true
|
|
|
|
})
|
2020-12-15 01:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-11 08:02:56 +00:00
|
|
|
}),
|
|
|
|
author.id
|
2020-12-15 01:44:28 +00:00
|
|
|
);
|
2021-04-11 08:02:56 +00:00
|
|
|
|
2021-04-17 15:21:17 +00:00
|
|
|
if (confirmed) {
|
|
|
|
const receiver = Storage.getUser(user.id);
|
2021-04-11 08:02:56 +00:00
|
|
|
sender.money -= amount;
|
|
|
|
receiver.money += amount;
|
|
|
|
Storage.save();
|
2021-04-17 15:21:17 +00:00
|
|
|
send(getSendEmbed(author, user, amount));
|
2021-04-11 08:02:56 +00:00
|
|
|
}
|
2020-12-15 01:44:28 +00:00
|
|
|
}
|
2021-04-11 08:02:56 +00:00
|
|
|
|
|
|
|
return;
|
2020-12-15 01:44:28 +00:00
|
|
|
}
|
|
|
|
})
|
2020-11-04 08:04:07 +00:00
|
|
|
});
|