Compare commits

..

No commits in common. "976445fa0d34bb4adc108385d8425c65bb9f70ed" and "75315b3db2ff7be098418f644f9ed89c23c4621e" have entirely different histories.

5 changed files with 80 additions and 82 deletions

View file

@ -7,7 +7,7 @@
# any secret values. # any secret values.
BOT_TOKEN= BOT_TOKEN=
BOT_VER=0.6.3 BOT_VER=0.6.2
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.3", "version": "0.6.2",
"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 user1UserId = interaction.customId.split(" ")[2]; const giveUserId = interaction.customId.split(" ")[2];
const user2UserId = interaction.customId.split(" ")[3]; const receiveUserId = interaction.customId.split(" ")[3];
const user1CardNumber = interaction.customId.split(" ")[4]; const giveCardNumber = interaction.customId.split(" ")[4];
const user2CardNumber = interaction.customId.split(" ")[5]; const receiveCardNumber = 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: user1UserId=${user1UserId}, user2UserId=${user2UserId}, user1CardNumber=${user1CardNumber}, user2CardNumber=${user2CardNumber}, expiry=${expiry}, timeoutId=${timeoutId}`); AppLogger.LogSilly("Button/Trade/AcceptTrade", `Parameters: giveUserId=${giveUserId}, receiveUserId=${receiveUserId}, giveCardNumber=${giveCardNumber}, receiveCardNumber=${receiveCardNumber}, 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 !== user2UserId) { if (interaction.user.id !== receiveUserId) {
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 user1Item = CoreClient.Cards const giveItem = CoreClient.Cards
.flatMap(x => x.cards) .flatMap(x => x.cards)
.find(x => x.id === user1CardNumber); .find(x => x.id === giveCardNumber);
const user2Item = CoreClient.Cards const receiveItem = CoreClient.Cards
.flatMap(x => x.cards) .flatMap(x => x.cards)
.find(x => x.id === user2CardNumber); .find(x => x.id === receiveCardNumber);
if (!user1Item || !user2Item) { if (!giveItem || !receiveItem) {
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 user1User = interaction.client.users.cache.get(user1UserId) || await interaction.client.users.fetch(user1UserId); const giveUser = interaction.client.users.cache.get(giveUserId) || await interaction.client.users.fetch(giveUserId);
const user2User = interaction.client.users.cache.get(user2UserId) || await interaction.client.users.fetch(user2UserId); const receiveUser = interaction.client.users.cache.get(receiveUserId) || await interaction.client.users.fetch(receiveUserId);
const user1UserInventory1 = await Inventory.FetchOneByCardNumberAndUserId(user1UserId, user1CardNumber); const giveUserInventory1 = await Inventory.FetchOneByCardNumberAndUserId(giveUserId, giveCardNumber);
const user2UserInventory1 = await Inventory.FetchOneByCardNumberAndUserId(user2UserId, user2CardNumber); const receiveUserInventory1 = await Inventory.FetchOneByCardNumberAndUserId(receiveUserId, receiveCardNumber);
if (!user1UserInventory1 || !user2UserInventory1) { if (!giveUserInventory1 || !receiveUserInventory1) {
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 (user1UserInventory1.Quantity < 1 || user2UserInventory1.Quantity < 1) { if (giveUserInventory1.Quantity < 1 || receiveUserInventory1.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;
} }
user1UserInventory1.SetQuantity(user1UserInventory1.Quantity - 1); giveUserInventory1.SetQuantity(giveUserInventory1.Quantity - 1);
user2UserInventory1.SetQuantity(user2UserInventory1.Quantity - 1); receiveUserInventory1.SetQuantity(receiveUserInventory1.Quantity - 1);
await user1UserInventory1.Save(Inventory, user1UserInventory1); await giveUserInventory1.Save(Inventory, giveUserInventory1);
await user2UserInventory1.Save(Inventory, user2UserInventory1); await receiveUserInventory1.Save(Inventory, receiveUserInventory1);
let user1UserInventory2 = await Inventory.FetchOneByCardNumberAndUserId(user1UserId, user2CardNumber); let giveUserInventory2 = await Inventory.FetchOneByCardNumberAndUserId(receiveUserId, giveCardNumber);
let user2UserInventory2 = await Inventory.FetchOneByCardNumberAndUserId(user2UserId, user1CardNumber); let receiveUserInventory2 = await Inventory.FetchOneByCardNumberAndUserId(giveUserId, receiveCardNumber);
if (!user1UserInventory2) { if (!giveUserInventory2) {
user1UserInventory2 = new Inventory(user1UserId, user1CardNumber, 1); giveUserInventory2 = new Inventory(receiveUserId, giveCardNumber, 1);
} else { } else {
user1UserInventory2.SetQuantity(user1UserInventory2.Quantity + 1); giveUserInventory2.SetQuantity(giveUserInventory2.Quantity + 1);
} }
if (!user2UserInventory2) { if (!receiveUserInventory2) {
user2UserInventory2 = new Inventory(user2UserId, user2CardNumber, 1); receiveUserInventory2 = new Inventory(giveUserId, receiveCardNumber, 1);
} else { } else {
user2UserInventory2.SetQuantity(user2UserInventory2.Quantity + 1); receiveUserInventory2.SetQuantity(receiveUserInventory2.Quantity + 1);
} }
await user1UserInventory2.Save(Inventory, user1UserInventory2); await giveUserInventory2.Save(Inventory, giveUserInventory2);
await user2UserInventory2.Save(Inventory, user2UserInventory2); await receiveUserInventory2.Save(Inventory, receiveUserInventory2);
clearTimeout(timeoutId); clearTimeout(timeoutId);
const tradeEmbed = new EmbedBuilder() const tradeEmbed = new EmbedBuilder()
.setTitle("Trade Accepted") .setTitle("Trade Accepted")
.setDescription(`Trade initiated between ${user1User.username} and ${user2User.username}`) .setDescription(`Trade initiated between ${receiveUser.username} and ${giveUser.username}`)
.setColor(EmbedColours.Success) .setColor(EmbedColours.Success)
.setImage("https://i.imgur.com/9w5f1ls.gif") .setImage("https://i.imgur.com/9w5f1ls.gif")
.addFields([ .addFields([
{ {
name: `${user1User.username} Receives`, name: "I receieve",
value: `${user2Item.id}: ${user2Item.name}`, value: `${receiveItem.id}: ${receiveItem.name}`,
inline: true, inline: true,
}, },
{ {
name: `${user2User.username} Receives`, name: "You receieve",
value: `${user1Item.id}: ${user1Item.name}`, value: `${giveItem.id}: ${giveItem.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 user1UserId = interaction.customId.split(" ")[2]; const giveUserId = interaction.customId.split(" ")[2];
const user2UserId = interaction.customId.split(" ")[3]; const receiveUserId = interaction.customId.split(" ")[3];
const user1CardNumber = interaction.customId.split(" ")[4]; const giveCardNumber = interaction.customId.split(" ")[4];
const user2CardNumber = interaction.customId.split(" ")[5]; const receiveCardNumber = 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: user1UserId=${user1UserId}, user2UserId=${user2UserId}, user1CardNumber=${user1CardNumber}, user2CardNumber=${user2CardNumber}, timeoutId=${timeoutId}`); AppLogger.LogSilly("Button/Trade/DeclineTrade", `Parameters: giveUserId=${giveUserId}, receiveUserId=${receiveUserId}, giveCardNumber=${giveCardNumber}, receiveCardNumber=${receiveCardNumber}, timeoutId=${timeoutId}`);
if (interaction.user.id != user1UserId && interaction.user.id !== user2UserId) { if (interaction.user.id != receiveUserId && interaction.user.id !==giveUserId) {
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 user1User = interaction.client.users.cache.get(user1UserId) || await interaction.client.users.fetch(user1UserId); const giveUser = interaction.client.users.cache.get(giveUserId) || await interaction.client.users.fetch(giveUserId);
const user2User = interaction.client.users.cache.get(user2UserId) || await interaction.client.users.fetch(user2UserId); const receiveUser = interaction.client.users.cache.get(receiveUserId) || await interaction.client.users.fetch(receiveUserId);
const user1Item = CoreClient.Cards const giveItem = CoreClient.Cards
.flatMap(x => x.cards) .flatMap(x => x.cards)
.find(x => x.id === user1CardNumber); .find(x => x.id === giveCardNumber);
const user2Item = CoreClient.Cards const receiveItem = CoreClient.Cards
.flatMap(x => x.cards) .flatMap(x => x.cards)
.find(x => x.id === user2CardNumber); .find(x => x.id === receiveCardNumber);
if (!user1Item || !user2Item) { if (!giveItem || !receiveItem) {
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 ${user1User.username} and ${user2User.username}`) .setDescription(`Trade initiated between ${receiveUser.username} and ${giveUser.username}`)
.setColor(EmbedColours.Error) .setColor(EmbedColours.Error)
.setImage("https://i.imgur.com/9w5f1ls.gif") .setImage("https://i.imgur.com/9w5f1ls.gif")
.addFields([ .addFields([
{ {
name: `${user1User.username} Receives`, name: "I Receive",
value: `${user2Item.id}: ${user2Item.name}`, value: `${receiveItem.id}: ${receiveItem.name}`,
inline: true, inline: true,
}, },
{ {
name: `${user2User.username} Receives`, name: "You Receive",
value: `${user1Item.id}: ${user1Item.name}`, value: `${giveItem.id}: ${giveItem.name}`,
inline: true, inline: true,
}, },
{ {

View file

@ -41,28 +41,28 @@ export default class Trade extends Command {
return; return;
} }
const user1ItemEntity = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, give.value!.toString()); const giveItemEntity = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, give.value!.toString());
const user2ItemEntity = await Inventory.FetchOneByCardNumberAndUserId(user.id, receive.value!.toString()); const receiveItemEntity = await Inventory.FetchOneByCardNumberAndUserId(user.id, receive.value!.toString());
if (!user1ItemEntity) { if (!giveItemEntity) {
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 (!user2ItemEntity) { if (!receiveItemEntity) {
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 user1Item = CoreClient.Cards const giveItem = 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 user2Item = CoreClient.Cards const receiveItem = 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 (!user1Item || !user2Item) { if (!giveItem || !receiveItem) {
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: `${interaction.user.username} Receives`, name: "I Receive",
value: `${user2Item.id}: ${user2Item.name}`, value: `${receiveItem.id}: ${receiveItem.name}`,
inline: true, inline: true,
}, },
{ {
name: `${user.username} Receives`, name: "You Receive",
value: `${user1Item.id}: ${user1Item.name}`, value: `${giveItem.id}: ${giveItem.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, user1Item.id, user2Item.id, user1Item.name, user2Item.name), 1000 * 60 * 15); // 15 minutes 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 row = new ActionRowBuilder<ButtonBuilder>() const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents([ .addComponents([
new ButtonBuilder() new ButtonBuilder()
.setCustomId(`trade accept ${interaction.user.id} ${user.id} ${user1Item.id} ${user2Item.id} ${expiry} ${timeoutId}`) .setCustomId(`trade accept ${interaction.user.id} ${user.id} ${giveItem.id} ${receiveItem.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} ${user1Item.id} ${user2Item.id} ${expiry} ${timeoutId}`) .setCustomId(`trade decline ${interaction.user.id} ${user.id} ${giveItem.id} ${receiveItem.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, user1Username: string, user2Username: string, user1CardNumber: string, user2CardNumber: string, user1CardName: string, user2CardName: string) { 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 ${user1Username} and ${user2Username}`); AppLogger.LogSilly("Commands/Trade/AutoDecline", `Auto declining trade between ${giveUsername} and ${receiveUsername}`);
const tradeEmbed = new EmbedBuilder() const tradeEmbed = new EmbedBuilder()
.setTitle("Trade Expired") .setTitle("Trade Expired")
.setDescription(`Trade initiated between ${user1Username} and ${user2Username}`) .setDescription(`Trade initiated between ${receiveUsername} and ${giveUsername}`)
.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: `${user1Username} Receives`, name: "I Receive",
value: `${user2CardNumber}: ${user2CardName}`, value: `${receiveCardNumber}: ${receiveCardName}`,
inline: true, inline: true,
}, },
{ {
name: `${user2Username} Receives`, name: "You Receive",
value: `${user1CardNumber}: ${user1CardName}`, value: `${giveCardNumber}: ${giveCardName}`,
inline: true, inline: true,
}, },
{ {

View file

@ -3,17 +3,15 @@ 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.LogDebug("Timers/GiveCurrency", "Giving currency to every known user"); AppLogger.LogInfo("Timers/GiveCurrency", "Giving currency to every known user");
const users = await User.FetchAll(User); const users = await User.FetchAll(User);
const usersFiltered = users.filter(x => x.Currency < 1000); for (const user of users) {
for (const user of usersFiltered) {
user.AddCurrency(CardConstants.TimerGiveAmount); user.AddCurrency(CardConstants.TimerGiveAmount);
} }
User.SaveAll(User, users); User.SaveAll(User, users);
AppLogger.LogDebug("Timers/GiveCurrency", `Successfully gave +${CardConstants.TimerGiveAmount} currency to ${usersFiltered.length} users`); AppLogger.LogInfo("Timers/GiveCurrency", `Successfully gave +${CardConstants.TimerGiveAmount} currency to ${users.length} users`);
} }