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 all commits
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
88 changes: 85 additions & 3 deletions src/discord/commands/guild/d.rpg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const items = {
},
fonts: {
AbrilFatFace: {
label: 'Abril Fat Face',
label: 'Abril Fatface',
value: 'AbrilFatFace',
description: 'Font',
quantity: 1,
Expand Down Expand Up @@ -144,7 +144,7 @@ const items = {
emoji: 'itemFont',
},
AudioWide: {
label: 'Audio ide',
label: 'Audio Wide',
value: 'AudioWide',
description: 'Font',
quantity: 1,
Expand Down Expand Up @@ -3754,6 +3754,73 @@ 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;

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);

// 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 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: [],
};
}

export async function rpgHelp(
interaction: MessageComponentInteraction | ChatInputCommandInteraction,
):Promise<InteractionEditReplyOptions | InteractionUpdateOptions> {
Expand Down Expand Up @@ -3827,7 +3894,19 @@ export const dRpg: SlashCommand = {
.setDescription('Go to the roulette game'))
.addSubcommand(subcommand => subcommand
.setName('trivia')
.setDescription('Go to the trivia parlor')),
.setDescription('Go to the trivia parlor'))
.addSubcommand(subcommand => subcommand
.setName('gift')
.setDescription('Gift tokens to another user')
.addUserOption(option => option
.setName('target')
.setDescription('User to gift tokens to')
.setRequired(true))
.addIntegerOption(option => option
.setName('amount')
.setDescription('Amount of tokens to gift')
.setRequired(true))),

async execute(interaction) {
log.info(F, await commandContext(interaction));
const channelRpg = await interaction.guild?.channels.fetch(env.CHANNEL_TRIPTOWN as string) as TextChannel;
Expand Down Expand Up @@ -3889,6 +3968,9 @@ export const dRpg: SlashCommand = {
if (subcommand === 'trivia') {
await interaction.editReply(await rpgTrivia(interaction));
}
if (subcommand === 'gift') {
await interaction.editReply(await rpgGift(interaction));
}

// if (subcommand === 'blackjack') {
// await interaction.editReply(await rpgArcade(interaction));
Expand Down
Loading