2021-04-05 04:35:12 +00:00
|
|
|
import {Command, NamedCommand, prompt} from "../../../core";
|
|
|
|
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";
|
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"],
|
2020-12-15 01:44:28 +00:00
|
|
|
async run({author, channel, guild}) {
|
|
|
|
if (isAuthorized(guild, channel)) {
|
|
|
|
const user = Storage.getUser(author.id);
|
|
|
|
const now = Date.now();
|
|
|
|
|
|
|
|
if (now - user.lastReceived >= 79200000) {
|
|
|
|
user.money++;
|
|
|
|
user.lastReceived = now;
|
|
|
|
Storage.save();
|
|
|
|
channel.send({
|
|
|
|
embed: {
|
|
|
|
title: "Daily Reward",
|
|
|
|
description: "You received 1 Mon!",
|
2020-12-15 11:15:28 +00:00
|
|
|
color: ECO_EMBED_COLOR
|
2020-12-15 01:44:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
channel.send({
|
|
|
|
embed: {
|
|
|
|
title: "Daily Reward",
|
2020-12-15 11:15:28 +00:00
|
|
|
description: `It's too soon to pick up your daily Mons. You have about ${(
|
2020-12-15 01:44:28 +00:00
|
|
|
(user.lastReceived + 79200000 - now) /
|
|
|
|
3600000
|
|
|
|
).toFixed(1)} hours to go.`,
|
2020-12-15 11:15:28 +00:00
|
|
|
color: ECO_EMBED_COLOR
|
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 GuildCommand = new NamedCommand({
|
2020-12-15 11:15:28 +00:00
|
|
|
description: "Get info on the guild's economy as a whole.",
|
|
|
|
async run({guild, channel}) {
|
|
|
|
if (isAuthorized(guild, channel)) {
|
|
|
|
const users = Storage.users;
|
|
|
|
let totalAmount = 0;
|
|
|
|
|
|
|
|
for (const ID in users) {
|
|
|
|
const user = users[ID];
|
|
|
|
totalAmount += user.money;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel.send({
|
|
|
|
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"],
|
2020-12-15 01:44:28 +00:00
|
|
|
async run({guild, channel, client}) {
|
|
|
|
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({
|
|
|
|
name: `#${i + 1}. ${user.username}#${user.discriminator}`,
|
2021-03-30 10:25:07 +00:00
|
|
|
value: pluralise(users[id].money, "Mon", "s")
|
2020-12-15 01:44:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
channel.send({
|
|
|
|
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({
|
|
|
|
async run({args, author, channel, guild}): Promise<any> {
|
|
|
|
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);
|
|
|
|
|
2020-12-15 07:56:09 +00:00
|
|
|
if (amount <= 0) return channel.send("You must send at least one Mon!");
|
2020-12-15 01:44:28 +00:00
|
|
|
else if (sender.money < amount)
|
2020-12-15 07:56:09 +00:00
|
|
|
return channel.send("You don't have enough Mons for that.", getMoneyEmbed(author));
|
|
|
|
else if (target.id === author.id) return channel.send("You can't send Mons to yourself!");
|
2020-12-15 01:44:28 +00:00
|
|
|
else if (target.bot && process.argv[2] !== "dev")
|
|
|
|
return channel.send("You can't send Mons to a bot!");
|
|
|
|
|
|
|
|
sender.money -= amount;
|
|
|
|
receiver.money += amount;
|
|
|
|
Storage.save();
|
|
|
|
return channel.send(getSendEmbed(author, target, amount));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}),
|
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
|
|
|
}),
|
2020-12-15 01:44:28 +00:00
|
|
|
any: new Command({
|
2021-03-30 10:25:07 +00:00
|
|
|
async run({args, author, channel, guild}) {
|
2020-12-15 01:44:28 +00:00
|
|
|
if (isAuthorized(guild, channel)) {
|
|
|
|
const last = args.pop();
|
|
|
|
|
|
|
|
if (!/\d+/g.test(last) && args.length === 0)
|
2020-12-15 07:56:09 +00:00
|
|
|
return channel.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);
|
|
|
|
|
2020-12-15 11:15:28 +00:00
|
|
|
if (amount <= 0) return channel.send("You must send at least one Mon!");
|
2020-12-15 01:44:28 +00:00
|
|
|
else if (sender.money < amount)
|
2020-12-15 23:46:03 +00:00
|
|
|
return channel.send("You don't have enough Mons to do that!", getMoneyEmbed(author));
|
2020-12-15 01:44:28 +00:00
|
|
|
else if (!guild)
|
2020-12-15 23:46:03 +00:00
|
|
|
return channel.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
|
|
|
|
|
|
|
const username = args.join(" ");
|
|
|
|
const member = (
|
|
|
|
await guild.members.fetch({
|
|
|
|
query: username,
|
|
|
|
limit: 1
|
|
|
|
})
|
|
|
|
).first();
|
|
|
|
|
|
|
|
if (!member)
|
|
|
|
return channel.send(
|
2020-12-15 23:46:03 +00:00
|
|
|
`Couldn't find a user by the name of \`${username}\`! If you want to send Mons to someone in a different server, you have to use their user ID!`
|
2020-12-15 01:44:28 +00:00
|
|
|
);
|
2020-12-15 23:46:03 +00:00
|
|
|
else if (member.user.id === author.id) return channel.send("You can't send Mons to yourself!");
|
2020-12-15 01:44:28 +00:00
|
|
|
else if (member.user.bot && process.argv[2] !== "dev")
|
2020-12-15 23:46:03 +00:00
|
|
|
return channel.send("You can't send Mons to a bot!");
|
2020-12-15 01:44:28 +00:00
|
|
|
|
|
|
|
const target = member.user;
|
|
|
|
|
|
|
|
return prompt(
|
|
|
|
await channel.send(
|
2021-03-30 10:25:07 +00:00
|
|
|
`Are you sure you want to send ${pluralise(
|
|
|
|
amount,
|
2020-12-15 11:15:28 +00:00
|
|
|
"Mon",
|
2020-12-15 01:44:28 +00:00
|
|
|
"s"
|
|
|
|
)} to this person?\n*(This message will automatically be deleted after 10 seconds.)*`,
|
|
|
|
{
|
|
|
|
embed: {
|
2020-12-15 11:15:28 +00:00
|
|
|
color: ECO_EMBED_COLOR,
|
2020-12-15 01:44:28 +00:00
|
|
|
author: {
|
|
|
|
name: `${target.username}#${target.discriminator}`,
|
|
|
|
icon_url: target.displayAvatarURL({
|
|
|
|
format: "png",
|
|
|
|
dynamic: true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
),
|
|
|
|
author.id,
|
|
|
|
() => {
|
|
|
|
const receiver = Storage.getUser(target.id);
|
|
|
|
sender.money -= amount;
|
|
|
|
receiver.money += amount;
|
|
|
|
Storage.save();
|
|
|
|
channel.send(getSendEmbed(author, target, amount));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2020-11-04 08:04:07 +00:00
|
|
|
});
|