Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sloppy gift command #710

Merged
merged 3 commits into from
Nov 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Linting
LunaUrsa committed Nov 19, 2023
commit c53429793a2dfe6491543d7890624933abf32140
99 changes: 48 additions & 51 deletions src/discord/commands/guild/d.rpg.ts
Original file line number Diff line number Diff line change
@@ -3755,75 +3755,72 @@ export async function rpgTown(
}

async function rpgGift(interaction: ChatInputCommandInteraction) {
const commandUser = interaction.user;
const targetUser = interaction.options.getUser('target');
const giftAmount = interaction.options.getInteger('amount') ?? 0;
const commandUser = interaction.user;
const targetUser = interaction.options.getUser('target');
const giftAmount = interaction.options.getInteger('amount') ?? 0;

if (!targetUser) throw new Error('Target user not found');
if (targetUser === commandUser) {
return {
embeds: [embedTemplate()
.setAuthor(null)
.setFooter({ text: `${(interaction.member as GuildMember).displayName}'s TripSit RPG (BETA)`, iconURL: (interaction.member as GuildMember).user.displayAvatarURL() })
.setTitle(`${emojiGet('buttonBetHuge')} Gift Unsuccessful`)
.setDescription(stripIndents`
if (!targetUser) throw new Error('Target user not found');
if (targetUser === commandUser) {
return {
embeds: [embedTemplate()
.setAuthor(null)
.setFooter({ text: `${(interaction.member as GuildMember).displayName}'s TripSit RPG (BETA)`, iconURL: (interaction.member as GuildMember).user.displayAvatarURL() })
.setTitle(`${emojiGet('buttonBetHuge')} Gift Unsuccessful`)
.setDescription(stripIndents`
**You can't gift tokens to yourself!**
`)
.setColor(Colors.Red)],
components: [],
};
}

const targetData = await getPersonaInfo(targetUser.id);
const userData = await getPersonaInfo(commandUser.id);
.setColor(Colors.Red)],
components: [],
};
}

// Get the current token amounts for the command user and the target user
const commandUserTokens = userData.tokens;
const targetUserTokens = targetData.tokens;
const targetData = await getPersonaInfo(targetUser.id);
const userData = await getPersonaInfo(commandUser.id);

// Check if the command user has enough tokens
if (commandUserTokens < giftAmount) {
return {
embeds: [embedTemplate()
.setAuthor(null)
.setFooter({ text: `${(interaction.member as GuildMember).displayName}'s TripSit RPG (BETA)`, iconURL: (interaction.member as GuildMember).user.displayAvatarURL() })
.setTitle(`${emojiGet('buttonBetHuge')} Gift Unsuccessful`)
.setDescription(stripIndents`
**You don't have enough tokens!**

${emojiGet('buttonBetSmall')} **Wallet:** ${userData.tokens}
`)
.setColor(Colors.Red)],
components: [],
}
} else {
// Remove the tokens from the command user
userData.tokens -= giftAmount;
// Add the tokens to the target user
targetData.tokens += giftAmount;
// Save the data
await setPersonaInfo(userData);
await setPersonaInfo(targetData);
}
// Get the current token amounts for the command user and the target user
const commandUserTokens = userData.tokens;
// const targetUserTokens = targetData.tokens;

// Check if the command user has enough tokens
if (commandUserTokens < giftAmount) {
return {
embeds: [embedTemplate()
.setAuthor(null)
.setFooter({ text: `${(interaction.member as GuildMember).displayName}'s TripSit RPG (BETA)`, iconURL: (interaction.member as GuildMember).user.displayAvatarURL() })
.setTitle(`${emojiGet('buttonBetHuge')} Gift Successful`)
.setTitle(`${emojiGet('buttonBetHuge')} Gift Unsuccessful`)
.setDescription(stripIndents`
**You don't have enough tokens!**

${emojiGet('buttonBetSmall')} **Wallet:** ${userData.tokens}
`)
.setColor(Colors.Red)],
components: [],
};
}
// Remove the tokens from the command user
userData.tokens -= giftAmount;
// Add the tokens to the target user
targetData.tokens += giftAmount;
// Save the data
await setPersonaInfo(userData);
await setPersonaInfo(targetData);

return {
embeds: [embedTemplate()
.setAuthor(null)
.setFooter({ text: `${(interaction.member as GuildMember).displayName}'s TripSit RPG (BETA)`, iconURL: (interaction.member as GuildMember).user.displayAvatarURL() })
.setTitle(`${emojiGet('buttonBetHuge')} Gift Successful`)
.setDescription(stripIndents`
**You gifted ${giftAmount} ${giftAmount === 1 ? 'token' : 'tokens'} to ${targetUser?.username}**

${emojiGet('buttonBetSmall')} **${targetUser?.displayName}'s Wallet:** ${targetData.tokens}
${emojiGet('buttonBetSmall')} **Your Wallet:** ${userData.tokens}
`)
.setColor(Colors.Green)],
components: [],
};
.setColor(Colors.Green)],
components: [],
};
}



export async function rpgHelp(
interaction: MessageComponentInteraction | ChatInputCommandInteraction,
):Promise<InteractionEditReplyOptions | InteractionUpdateOptions> {