Compare commits

...

5 commits

Author SHA1 Message Date
9d8107d318 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
2024-06-07 18:13:12 +01:00
976445fa0d v0.6.3
All checks were successful
Deploy To Production / build (push) Successful in 8s
Deploy To Production / deploy (push) Successful in 14s
2024-06-07 18:12:38 +01:00
27a4019f00 0.6.3 2024-06-07 18:12:13 +01:00
f6c744cdcf Update the give currency timer to only give currency to those with less than 1000 currency
All checks were successful
Test / build (push) Successful in 7s
2024-06-07 18:11:27 +01:00
a03a62277d Update trade command so the usernames are more obvious
All checks were successful
Test / build (push) Successful in 8s
2024-06-05 19:25:27 +01:00
5 changed files with 82 additions and 80 deletions

View file

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

View file

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

View file

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

View file

@ -41,28 +41,28 @@ export default class Trade extends Command {
return;
}
const giveItemEntity = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, give.value!.toString());
const receiveItemEntity = await Inventory.FetchOneByCardNumberAndUserId(user.id, receive.value!.toString());
const user1ItemEntity = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, give.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.");
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.");
return;
}
const giveItem = CoreClient.Cards
const user1Item = CoreClient.Cards
.flatMap(x => x.cards)
.find(x => x.id === give.value!.toString());
const receiveItem = CoreClient.Cards
const user2Item = CoreClient.Cards
.flatMap(x => x.cards)
.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.");
return;
}
@ -77,13 +77,13 @@ export default class Trade extends Command {
.setImage("https://media1.tenor.com/m/KkZwKl2AQ2QAAAAd/trade-offer.gif")
.addFields([
{
name: "I Receive",
value: `${receiveItem.id}: ${receiveItem.name}`,
name: `${interaction.user.username} Receives`,
value: `${user2Item.id}: ${user2Item.name}`,
inline: true,
},
{
name: "You Receive",
value: `${giveItem.id}: ${giveItem.name}`,
name: `${user.username} Receives`,
value: `${user1Item.id}: ${user1Item.name}`,
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>()
.addComponents([
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")
.setStyle(ButtonStyle.Success),
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")
.setStyle(ButtonStyle.Danger),
]);
@ -109,23 +109,23 @@ export default class Trade extends Command {
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) {
AppLogger.LogSilly("Commands/Trade/AutoDecline", `Auto declining trade between ${giveUsername} and ${receiveUsername}`);
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 ${user1Username} and ${user2Username}`);
const tradeEmbed = new EmbedBuilder()
.setTitle("Trade Expired")
.setDescription(`Trade initiated between ${receiveUsername} and ${giveUsername}`)
.setDescription(`Trade initiated between ${user1Username} and ${user2Username}`)
.setColor(EmbedColours.Error)
.setImage("https://media1.tenor.com/m/KkZwKl2AQ2QAAAAd/trade-offer.gif")
.addFields([
{
name: "I Receive",
value: `${receiveCardNumber}: ${receiveCardName}`,
name: `${user1Username} Receives`,
value: `${user2CardNumber}: ${user2CardName}`,
inline: true,
},
{
name: "You Receive",
value: `${giveCardNumber}: ${giveCardName}`,
name: `${user2Username} Receives`,
value: `${user1CardNumber}: ${user1CardName}`,
inline: true,
},
{

View file

@ -3,15 +3,17 @@ import CardConstants from "../constants/CardConstants";
import User from "../database/entities/app/User";
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);
for (const user of users) {
const usersFiltered = users.filter(x => x.Currency < 1000);
for (const user of usersFiltered) {
user.AddCurrency(CardConstants.TimerGiveAmount);
}
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`);
}