Merge branch 'main' into develop
All checks were successful
Deploy To Stage / build (push) Successful in 8s
Deploy To Stage / deploy (push) Successful in 16s

This commit is contained in:
Ethan Lane 2024-06-07 18:13:12 +01:00
commit 9d8107d318
5 changed files with 82 additions and 80 deletions

View file

@ -7,7 +7,7 @@
# any secret values. # any secret values.
BOT_TOKEN= BOT_TOKEN=
BOT_VER=0.6.2 BOT_VER=0.6.3
BOT_AUTHOR=Vylpes BOT_AUTHOR=Vylpes
BOT_OWNERID=147392775707426816 BOT_OWNERID=147392775707426816
BOT_CLIENTID=682942374040961060 BOT_CLIENTID=682942374040961060

View file

@ -1,6 +1,6 @@
{ {
"name": "card-drop", "name": "card-drop",
"version": "0.6.2", "version": "0.6.3",
"main": "./dist/bot.js", "main": "./dist/bot.js",
"typings": "./dist", "typings": "./dist",
"scripts": { "scripts": {

View file

@ -22,14 +22,14 @@ export default class Trade extends ButtonEvent {
} }
private async AcceptTrade(interaction: ButtonInteraction) { private async AcceptTrade(interaction: ButtonInteraction) {
const giveUserId = interaction.customId.split(" ")[2]; const user1UserId = interaction.customId.split(" ")[2];
const receiveUserId = interaction.customId.split(" ")[3]; const user2UserId = interaction.customId.split(" ")[3];
const giveCardNumber = interaction.customId.split(" ")[4]; const user1CardNumber = interaction.customId.split(" ")[4];
const receiveCardNumber = interaction.customId.split(" ")[5]; const user2CardNumber = interaction.customId.split(" ")[5];
const expiry = interaction.customId.split(" ")[6]; const expiry = interaction.customId.split(" ")[6];
const timeoutId = interaction.customId.split(" ")[7]; const timeoutId = interaction.customId.split(" ")[7];
AppLogger.LogSilly("Button/Trade/AcceptTrade", `Parameters: giveUserId=${giveUserId}, receiveUserId=${receiveUserId}, giveCardNumber=${giveCardNumber}, receiveCardNumber=${receiveCardNumber}, expiry=${expiry}, timeoutId=${timeoutId}`); AppLogger.LogSilly("Button/Trade/AcceptTrade", `Parameters: user1UserId=${user1UserId}, user2UserId=${user2UserId}, user1CardNumber=${user1CardNumber}, user2CardNumber=${user2CardNumber}, expiry=${expiry}, timeoutId=${timeoutId}`);
const expiryDate = new Date(expiry); const expiryDate = new Date(expiry);
@ -38,80 +38,80 @@ export default class Trade extends ButtonEvent {
return; return;
} }
if (interaction.user.id !== receiveUserId) { if (interaction.user.id !== user2UserId) {
await interaction.reply("You are not the user who the trade is intended for"); await interaction.reply("You are not the user who the trade is intended for");
return; return;
} }
const giveItem = CoreClient.Cards const user1Item = CoreClient.Cards
.flatMap(x => x.cards) .flatMap(x => x.cards)
.find(x => x.id === giveCardNumber); .find(x => x.id === user1CardNumber);
const receiveItem = CoreClient.Cards const user2Item = CoreClient.Cards
.flatMap(x => x.cards) .flatMap(x => x.cards)
.find(x => x.id === receiveCardNumber); .find(x => x.id === user2CardNumber);
if (!giveItem || !receiveItem) { if (!user1Item || !user2Item) {
await interaction.reply("One or more of the items you are trying to trade does not exist."); await interaction.reply("One or more of the items you are trying to trade does not exist.");
return; return;
} }
const giveUser = interaction.client.users.cache.get(giveUserId) || await interaction.client.users.fetch(giveUserId); const user1User = interaction.client.users.cache.get(user1UserId) || await interaction.client.users.fetch(user1UserId);
const receiveUser = interaction.client.users.cache.get(receiveUserId) || await interaction.client.users.fetch(receiveUserId); const user2User = interaction.client.users.cache.get(user2UserId) || await interaction.client.users.fetch(user2UserId);
const giveUserInventory1 = await Inventory.FetchOneByCardNumberAndUserId(giveUserId, giveCardNumber); const user1UserInventory1 = await Inventory.FetchOneByCardNumberAndUserId(user1UserId, user1CardNumber);
const receiveUserInventory1 = await Inventory.FetchOneByCardNumberAndUserId(receiveUserId, receiveCardNumber); const user2UserInventory1 = await Inventory.FetchOneByCardNumberAndUserId(user2UserId, user2CardNumber);
if (!giveUserInventory1 || !receiveUserInventory1) { if (!user1UserInventory1 || !user2UserInventory1) {
await interaction.reply("One or more of the items you are trying to trade does not exist."); await interaction.reply("One or more of the items you are trying to trade does not exist.");
return; return;
} }
if (giveUserInventory1.Quantity < 1 || receiveUserInventory1.Quantity < 1) { if (user1UserInventory1.Quantity < 1 || user2UserInventory1.Quantity < 1) {
await interaction.reply("One or more of the items you are trying to trade does not exist."); await interaction.reply("One or more of the items you are trying to trade does not exist.");
return; return;
} }
giveUserInventory1.SetQuantity(giveUserInventory1.Quantity - 1); user1UserInventory1.SetQuantity(user1UserInventory1.Quantity - 1);
receiveUserInventory1.SetQuantity(receiveUserInventory1.Quantity - 1); user2UserInventory1.SetQuantity(user2UserInventory1.Quantity - 1);
await giveUserInventory1.Save(Inventory, giveUserInventory1); await user1UserInventory1.Save(Inventory, user1UserInventory1);
await receiveUserInventory1.Save(Inventory, receiveUserInventory1); await user2UserInventory1.Save(Inventory, user2UserInventory1);
let giveUserInventory2 = await Inventory.FetchOneByCardNumberAndUserId(receiveUserId, giveCardNumber); let user1UserInventory2 = await Inventory.FetchOneByCardNumberAndUserId(user1UserId, user2CardNumber);
let receiveUserInventory2 = await Inventory.FetchOneByCardNumberAndUserId(giveUserId, receiveCardNumber); let user2UserInventory2 = await Inventory.FetchOneByCardNumberAndUserId(user2UserId, user1CardNumber);
if (!giveUserInventory2) { if (!user1UserInventory2) {
giveUserInventory2 = new Inventory(receiveUserId, giveCardNumber, 1); user1UserInventory2 = new Inventory(user1UserId, user1CardNumber, 1);
} else { } else {
giveUserInventory2.SetQuantity(giveUserInventory2.Quantity + 1); user1UserInventory2.SetQuantity(user1UserInventory2.Quantity + 1);
} }
if (!receiveUserInventory2) { if (!user2UserInventory2) {
receiveUserInventory2 = new Inventory(giveUserId, receiveCardNumber, 1); user2UserInventory2 = new Inventory(user2UserId, user2CardNumber, 1);
} else { } else {
receiveUserInventory2.SetQuantity(receiveUserInventory2.Quantity + 1); user2UserInventory2.SetQuantity(user2UserInventory2.Quantity + 1);
} }
await giveUserInventory2.Save(Inventory, giveUserInventory2); await user1UserInventory2.Save(Inventory, user1UserInventory2);
await receiveUserInventory2.Save(Inventory, receiveUserInventory2); await user2UserInventory2.Save(Inventory, user2UserInventory2);
clearTimeout(timeoutId); clearTimeout(timeoutId);
const tradeEmbed = new EmbedBuilder() const tradeEmbed = new EmbedBuilder()
.setTitle("Trade Accepted") .setTitle("Trade Accepted")
.setDescription(`Trade initiated between ${receiveUser.username} and ${giveUser.username}`) .setDescription(`Trade initiated between ${user1User.username} and ${user2User.username}`)
.setColor(EmbedColours.Success) .setColor(EmbedColours.Success)
.setImage("https://i.imgur.com/9w5f1ls.gif") .setImage("https://i.imgur.com/9w5f1ls.gif")
.addFields([ .addFields([
{ {
name: "I receieve", name: `${user1User.username} Receives`,
value: `${receiveItem.id}: ${receiveItem.name}`, value: `${user2Item.id}: ${user2Item.name}`,
inline: true, inline: true,
}, },
{ {
name: "You receieve", name: `${user2User.username} Receives`,
value: `${giveItem.id}: ${giveItem.name}`, value: `${user1Item.id}: ${user1Item.name}`,
inline: true, inline: true,
}, },
{ {
@ -138,32 +138,32 @@ export default class Trade extends ButtonEvent {
} }
private async DeclineTrade(interaction: ButtonInteraction) { private async DeclineTrade(interaction: ButtonInteraction) {
const giveUserId = interaction.customId.split(" ")[2]; const user1UserId = interaction.customId.split(" ")[2];
const receiveUserId = interaction.customId.split(" ")[3]; const user2UserId = interaction.customId.split(" ")[3];
const giveCardNumber = interaction.customId.split(" ")[4]; const user1CardNumber = interaction.customId.split(" ")[4];
const receiveCardNumber = interaction.customId.split(" ")[5]; const user2CardNumber = interaction.customId.split(" ")[5];
// No need to get expiry date // No need to get expiry date
const timeoutId = interaction.customId.split(" ")[7]; const timeoutId = interaction.customId.split(" ")[7];
AppLogger.LogSilly("Button/Trade/DeclineTrade", `Parameters: giveUserId=${giveUserId}, receiveUserId=${receiveUserId}, giveCardNumber=${giveCardNumber}, receiveCardNumber=${receiveCardNumber}, timeoutId=${timeoutId}`); AppLogger.LogSilly("Button/Trade/DeclineTrade", `Parameters: user1UserId=${user1UserId}, user2UserId=${user2UserId}, user1CardNumber=${user1CardNumber}, user2CardNumber=${user2CardNumber}, timeoutId=${timeoutId}`);
if (interaction.user.id != receiveUserId && interaction.user.id !==giveUserId) { if (interaction.user.id != user1UserId && interaction.user.id !== user2UserId) {
await interaction.reply("You are not the user who the trade is intended for"); await interaction.reply("You are not the user who the trade is intended for");
return; return;
} }
const giveUser = interaction.client.users.cache.get(giveUserId) || await interaction.client.users.fetch(giveUserId); const user1User = interaction.client.users.cache.get(user1UserId) || await interaction.client.users.fetch(user1UserId);
const receiveUser = interaction.client.users.cache.get(receiveUserId) || await interaction.client.users.fetch(receiveUserId); const user2User = interaction.client.users.cache.get(user2UserId) || await interaction.client.users.fetch(user2UserId);
const giveItem = CoreClient.Cards const user1Item = CoreClient.Cards
.flatMap(x => x.cards) .flatMap(x => x.cards)
.find(x => x.id === giveCardNumber); .find(x => x.id === user1CardNumber);
const receiveItem = CoreClient.Cards const user2Item = CoreClient.Cards
.flatMap(x => x.cards) .flatMap(x => x.cards)
.find(x => x.id === receiveCardNumber); .find(x => x.id === user2CardNumber);
if (!giveItem || !receiveItem) { if (!user1Item || !user2Item) {
await interaction.reply("One or more of the items you are trying to trade does not exist."); await interaction.reply("One or more of the items you are trying to trade does not exist.");
return; return;
} }
@ -172,18 +172,18 @@ export default class Trade extends ButtonEvent {
const tradeEmbed = new EmbedBuilder() const tradeEmbed = new EmbedBuilder()
.setTitle("Trade Declined") .setTitle("Trade Declined")
.setDescription(`Trade initiated between ${receiveUser.username} and ${giveUser.username}`) .setDescription(`Trade initiated between ${user1User.username} and ${user2User.username}`)
.setColor(EmbedColours.Error) .setColor(EmbedColours.Error)
.setImage("https://i.imgur.com/9w5f1ls.gif") .setImage("https://i.imgur.com/9w5f1ls.gif")
.addFields([ .addFields([
{ {
name: "I Receive", name: `${user1User.username} Receives`,
value: `${receiveItem.id}: ${receiveItem.name}`, value: `${user2Item.id}: ${user2Item.name}`,
inline: true, inline: true,
}, },
{ {
name: "You Receive", name: `${user2User.username} Receives`,
value: `${giveItem.id}: ${giveItem.name}`, value: `${user1Item.id}: ${user1Item.name}`,
inline: true, inline: true,
}, },
{ {

View file

@ -41,28 +41,28 @@ export default class Trade extends Command {
return; return;
} }
const giveItemEntity = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, give.value!.toString()); const user1ItemEntity = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, give.value!.toString());
const receiveItemEntity = await Inventory.FetchOneByCardNumberAndUserId(user.id, receive.value!.toString()); const user2ItemEntity = await Inventory.FetchOneByCardNumberAndUserId(user.id, receive.value!.toString());
if (!giveItemEntity) { if (!user1ItemEntity) {
await interaction.reply("You do not have the item you are trying to trade."); await interaction.reply("You do not have the item you are trying to trade.");
return; return;
} }
if (!receiveItemEntity) { if (!user2ItemEntity) {
await interaction.reply("The user you are trying to trade with does not have the item you are trying to trade for."); await interaction.reply("The user you are trying to trade with does not have the item you are trying to trade for.");
return; return;
} }
const giveItem = CoreClient.Cards const user1Item = CoreClient.Cards
.flatMap(x => x.cards) .flatMap(x => x.cards)
.find(x => x.id === give.value!.toString()); .find(x => x.id === give.value!.toString());
const receiveItem = CoreClient.Cards const user2Item = CoreClient.Cards
.flatMap(x => x.cards) .flatMap(x => x.cards)
.find(x => x.id === receive.value!.toString()); .find(x => x.id === receive.value!.toString());
if (!giveItem || !receiveItem) { if (!user1Item || !user2Item) {
await interaction.reply("One or more of the items you are trying to trade does not exist."); await interaction.reply("One or more of the items you are trying to trade does not exist.");
return; return;
} }
@ -77,13 +77,13 @@ export default class Trade extends Command {
.setImage("https://media1.tenor.com/m/KkZwKl2AQ2QAAAAd/trade-offer.gif") .setImage("https://media1.tenor.com/m/KkZwKl2AQ2QAAAAd/trade-offer.gif")
.addFields([ .addFields([
{ {
name: "I Receive", name: `${interaction.user.username} Receives`,
value: `${receiveItem.id}: ${receiveItem.name}`, value: `${user2Item.id}: ${user2Item.name}`,
inline: true, inline: true,
}, },
{ {
name: "You Receive", name: `${user.username} Receives`,
value: `${giveItem.id}: ${giveItem.name}`, value: `${user1Item.id}: ${user1Item.name}`,
inline: true, inline: true,
}, },
{ {
@ -92,16 +92,16 @@ export default class Trade extends Command {
} }
]); ]);
const timeoutId = setTimeout(async () => this.autoDecline(interaction, interaction.user.username, user.username, giveItem.id, receiveItem.id, giveItem.name, receiveItem.name), 1000 * 60 * 15); // 15 minutes const timeoutId = setTimeout(async () => this.autoDecline(interaction, interaction.user.username, user.username, user1Item.id, user2Item.id, user1Item.name, user2Item.name), 1000 * 60 * 15); // 15 minutes
const row = new ActionRowBuilder<ButtonBuilder>() const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents([ .addComponents([
new ButtonBuilder() new ButtonBuilder()
.setCustomId(`trade accept ${interaction.user.id} ${user.id} ${giveItem.id} ${receiveItem.id} ${expiry} ${timeoutId}`) .setCustomId(`trade accept ${interaction.user.id} ${user.id} ${user1Item.id} ${user2Item.id} ${expiry} ${timeoutId}`)
.setLabel("Accept") .setLabel("Accept")
.setStyle(ButtonStyle.Success), .setStyle(ButtonStyle.Success),
new ButtonBuilder() new ButtonBuilder()
.setCustomId(`trade decline ${interaction.user.id} ${user.id} ${giveItem.id} ${receiveItem.id} ${expiry} ${timeoutId}`) .setCustomId(`trade decline ${interaction.user.id} ${user.id} ${user1Item.id} ${user2Item.id} ${expiry} ${timeoutId}`)
.setLabel("Decline") .setLabel("Decline")
.setStyle(ButtonStyle.Danger), .setStyle(ButtonStyle.Danger),
]); ]);
@ -109,23 +109,23 @@ export default class Trade extends Command {
await interaction.reply({ content: `${user}`, embeds: [ tradeEmbed ], components: [ row ] }); await interaction.reply({ content: `${user}`, embeds: [ tradeEmbed ], components: [ row ] });
} }
private async autoDecline(interaction: CommandInteraction, giveUsername: string, receiveUsername: string, giveCardNumber: string, receiveCardNumber: string, giveCardName: string, receiveCardName: string) { private async autoDecline(interaction: CommandInteraction, user1Username: string, user2Username: string, user1CardNumber: string, user2CardNumber: string, user1CardName: string, user2CardName: string) {
AppLogger.LogSilly("Commands/Trade/AutoDecline", `Auto declining trade between ${giveUsername} and ${receiveUsername}`); AppLogger.LogSilly("Commands/Trade/AutoDecline", `Auto declining trade between ${user1Username} and ${user2Username}`);
const tradeEmbed = new EmbedBuilder() const tradeEmbed = new EmbedBuilder()
.setTitle("Trade Expired") .setTitle("Trade Expired")
.setDescription(`Trade initiated between ${receiveUsername} and ${giveUsername}`) .setDescription(`Trade initiated between ${user1Username} and ${user2Username}`)
.setColor(EmbedColours.Error) .setColor(EmbedColours.Error)
.setImage("https://media1.tenor.com/m/KkZwKl2AQ2QAAAAd/trade-offer.gif") .setImage("https://media1.tenor.com/m/KkZwKl2AQ2QAAAAd/trade-offer.gif")
.addFields([ .addFields([
{ {
name: "I Receive", name: `${user1Username} Receives`,
value: `${receiveCardNumber}: ${receiveCardName}`, value: `${user2CardNumber}: ${user2CardName}`,
inline: true, inline: true,
}, },
{ {
name: "You Receive", name: `${user2Username} Receives`,
value: `${giveCardNumber}: ${giveCardName}`, value: `${user1CardNumber}: ${user1CardName}`,
inline: true, inline: true,
}, },
{ {

View file

@ -3,15 +3,17 @@ import CardConstants from "../constants/CardConstants";
import User from "../database/entities/app/User"; import User from "../database/entities/app/User";
export default async function GiveCurrency() { export default async function GiveCurrency() {
AppLogger.LogInfo("Timers/GiveCurrency", "Giving currency to every known user"); AppLogger.LogDebug("Timers/GiveCurrency", "Giving currency to every known user");
const users = await User.FetchAll(User); const users = await User.FetchAll(User);
for (const user of users) { const usersFiltered = users.filter(x => x.Currency < 1000);
for (const user of usersFiltered) {
user.AddCurrency(CardConstants.TimerGiveAmount); user.AddCurrency(CardConstants.TimerGiveAmount);
} }
User.SaveAll(User, users); User.SaveAll(User, users);
AppLogger.LogInfo("Timers/GiveCurrency", `Successfully gave +${CardConstants.TimerGiveAmount} currency to ${users.length} users`); AppLogger.LogDebug("Timers/GiveCurrency", `Successfully gave +${CardConstants.TimerGiveAmount} currency to ${usersFiltered.length} users`);
} }