Skip to content

Commit

Permalink
Remove option to claim league patreon benefits (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
psikoi authored Feb 2, 2024
1 parent 150ede8 commit 6007a56
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 130 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wise-old-man-bot",
"version": "1.4.2",
"version": "1.4.3",
"description": "A Discord bot for the Wise Old Man projects (https://github.com/wise-old-man/wise-old-man/)",
"author": "Psikoi",
"license": "ISC",
Expand Down
14 changes: 0 additions & 14 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import { Client, Guild, Intents, Interaction, MessageEmbed, TextChannel } from '
import config from './config';
import * as router from './commands/router';
import {
PATREON_LEAGUE_MODAL_ID,
PATREON_LEAGUE_TRIGGER_ID,
PATREON_MODAL_ID,
PATREON_TRIGGER_ID,
handlePatreonLeagueModalSubmit,
handlePatreonLeagueTrigger,
handlePatreonModalSubmit,
handlePatreonTrigger,
setupPatreonTrigger
Expand Down Expand Up @@ -43,21 +39,11 @@ class Bot {
return;
}

if (interaction.isButton() && interaction.customId === PATREON_LEAGUE_TRIGGER_ID) {
handlePatreonLeagueTrigger(interaction);
return;
}

if (interaction.isModalSubmit() && interaction.customId === PATREON_MODAL_ID) {
handlePatreonModalSubmit(interaction);
return;
}

if (interaction.isModalSubmit() && interaction.customId === PATREON_LEAGUE_MODAL_ID) {
handlePatreonLeagueModalSubmit(interaction);
return;
}

router.onInteractionReceived(interaction);
});

Expand Down
2 changes: 0 additions & 2 deletions src/content/patreon-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@ With this generous pledge, you'll be literally keeping the lights on. As a rewar
After subscribing to our [Patreon](https://wiseoldman.net/patreon), you should connect your Discord account on Patreon (
see a guide [here](https://support.patreon.com/hc/en-us/articles/212052266-Getting-Discord-access>)), and then you can click the button below to claim your benefits.

Note: If you'd like to also claim these benefits for your Leagues website group, click the Leagues button below, and make sure to insert the correct (league) group ID.

** **
95 changes: 2 additions & 93 deletions src/patreon-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ import {
} from 'discord.js';
import config from './config';
import { hasRole, sendModLog } from './utils';
import { claimBenefits, claimLeagueBenefits } from './services/wiseoldman';
import { claimBenefits } from './services/wiseoldman';

export const PATREON_MODAL_ID = 'patreon-benefits-modal';
export const PATREON_LEAGUE_MODAL_ID = 'patreon-league-benefits-modal';

export const PATREON_TRIGGER_ID = 'patreon-benefits-trigger';
export const PATREON_LEAGUE_TRIGGER_ID = 'patreon-league-benefits-trigger';

const NOT_A_PATRON_ERROR_MESSAGE = `Only Patreon supporters can claim benefits, please consider helping fund the project at https://wiseoldman.net/patreon.\n\nIf you already are a Patreon supporter, make sure to connect your Discord account to your Patreon account.`;

Expand All @@ -40,11 +38,7 @@ export async function setupPatreonTrigger(client: Client) {
new MessageButton()
.setCustomId(PATREON_TRIGGER_ID)
.setLabel('Claim Patreon Benefits')
.setStyle('SUCCESS'),
new MessageButton()
.setCustomId(PATREON_LEAGUE_TRIGGER_ID)
.setLabel('(🏆 Leagues) Claim Patreon Benefits')
.setStyle('SECONDARY')
.setStyle('SUCCESS')
);

const message = await patreonInfoChannel.send({ content, components: [actions] });
Expand Down Expand Up @@ -92,47 +86,6 @@ export async function handlePatreonTrigger(interaction: ButtonInteraction) {
interaction.showModal(modal);
}

export async function handlePatreonLeagueTrigger(interaction: ButtonInteraction) {
if (!interaction.member) return;

const member = interaction.member as GuildMember;

if (!hasRole(member, config.discord.roles.patreonSupporter)) {
await interaction.reply({ content: NOT_A_PATRON_ERROR_MESSAGE, ephemeral: true });
return;
}

const isTier2Supporter = hasRole(member, config.discord.roles.patreonSupporterT2);

const modal = new Modal()
.setCustomId(PATREON_LEAGUE_MODAL_ID)
.setTitle(`Claim League Benefits (Tier ${isTier2Supporter ? 2 : 1})`);

const usernameInput = new TextInputComponent()
.setCustomId('username')
.setLabel('Your in-game username')
.setPlaceholder('Ex: Zezima')
.setMaxLength(12)
.setStyle(1)
.setRequired(true);

const groupIdInput = new TextInputComponent()
.setCustomId('groupId')
.setLabel("Your League group's ID")
.setPlaceholder("Ex: 139 (Can be found on your group's page URL.)")
.setStyle(1);

// @ts-expect-error -- Typings are wrong on discord.js v13.7.0 (can be deleted on a v14 upgrade)
modal.addComponents(new MessageActionRow().addComponents(usernameInput));

if (isTier2Supporter) {
// @ts-expect-error -- Typings are wrong on discord.js v13.7.0 (can be deleted on a v14 upgrade)
modal.addComponents(new MessageActionRow().addComponents(groupIdInput));
}

interaction.showModal(modal);
}

export async function handlePatreonModalSubmit(interaction: ModalSubmitInteraction) {
const username = interaction.fields.getTextInputValue('username');

Expand Down Expand Up @@ -176,47 +129,3 @@ export async function handlePatreonModalSubmit(interaction: ModalSubmitInteracti
interaction.reply({ content: error.message, ephemeral: true });
}
}

export async function handlePatreonLeagueModalSubmit(interaction: ModalSubmitInteraction) {
const username = interaction.fields.getTextInputValue('username');

if (!username) {
interaction.reply({ content: '❌ Please provide your in-game username.', ephemeral: true });
return;
}

let groupId: number | undefined;

if (hasRole(interaction.member as GuildMember, config.discord.roles.patreonSupporterT2)) {
const groupIdValue = interaction.fields.getTextInputValue('groupId');
const isInteger = typeof groupIdValue === 'string' && Number.isInteger(parseInt(groupIdValue));

if (!isInteger) {
interaction.reply({ content: '❌ Please provide a valid group ID.', ephemeral: true });
return;
}

groupId = parseInt(groupIdValue);
}

try {
await claimLeagueBenefits(interaction.user.id, username, groupId);

let successMessage = '✅ Your benefits have been claimed!';

if (groupId) {
successMessage += ` You can edit your group's images and social links on your group's edit page on the website.`;
}

interaction.reply({ content: successMessage, ephemeral: true });

sendModLog(
interaction.guild,
`${interaction.user} has claimed ${
groupId ? 'Tier 2' : 'Tier 1'
} (League) Patreon benefits for: \nUsername: ${username}${groupId ? `\nGroup id: ${groupId}` : ''}`
);
} catch (error) {
interaction.reply({ content: error.message, ephemeral: true });
}
}
18 changes: 0 additions & 18 deletions src/services/wiseoldman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ const womClient = new WOMClient({
apiKey: config.apiKey
});

const leagueWomClient = new WOMClient({
userAgent: 'WiseOldMan Discord Bot',
baseAPIUrl: 'https://api.wiseoldman.net/league',
apiKey: config.apiKey
});

export function getCompetitionStatus(competition: CompetitionDetails | CompetitionListItem) {
const now = new Date();
const endsAt = competition.endsAt;
Expand Down Expand Up @@ -183,18 +177,6 @@ export async function claimBenefits(
});
}

export async function claimLeagueBenefits(
discordId: string,
username: string,
groupId?: number
): Promise<void> {
return leagueWomClient.putRequest(`/patrons/claim/${discordId}`, {
username,
groupId,
adminPassword: env.ADMIN_PASSWORD
});
}

/**
* Send an API request attempting to update a player's country
*/
Expand Down

0 comments on commit 6007a56

Please sign in to comment.