From 6007a56ff3f6fd4fc813aca5b0776328db2556bb Mon Sep 17 00:00:00 2001 From: Ruben Amendoeira Date: Fri, 2 Feb 2024 18:52:53 +0100 Subject: [PATCH] Remove option to claim league patreon benefits (#237) --- package-lock.json | 4 +- package.json | 2 +- src/bot.ts | 14 ------ src/content/patreon-info.md | 2 - src/patreon-trigger.ts | 95 +------------------------------------ src/services/wiseoldman.ts | 18 ------- 6 files changed, 5 insertions(+), 130 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7d833c30..ae93c337 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "wise-old-man-bot", - "version": "1.4.2", + "version": "1.4.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "wise-old-man-bot", - "version": "1.4.2", + "version": "1.4.3", "license": "ISC", "dependencies": { "@discordjs/builders": "^0.12.0", diff --git a/package.json b/package.json index aba771d8..285ffa52 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/bot.ts b/src/bot.ts index eb12b288..5428a82d 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -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 @@ -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); }); diff --git a/src/content/patreon-info.md b/src/content/patreon-info.md index 92b9d0b1..e7528642 100644 --- a/src/content/patreon-info.md +++ b/src/content/patreon-info.md @@ -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. - ** ** \ No newline at end of file diff --git a/src/patreon-trigger.ts b/src/patreon-trigger.ts index 127b2f4b..1a6863b0 100644 --- a/src/patreon-trigger.ts +++ b/src/patreon-trigger.ts @@ -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.`; @@ -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] }); @@ -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'); @@ -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 }); - } -} diff --git a/src/services/wiseoldman.ts b/src/services/wiseoldman.ts index 71652fca..2003aa15 100644 --- a/src/services/wiseoldman.ts +++ b/src/services/wiseoldman.ts @@ -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; @@ -183,18 +177,6 @@ export async function claimBenefits( }); } -export async function claimLeagueBenefits( - discordId: string, - username: string, - groupId?: number -): Promise { - return leagueWomClient.putRequest(`/patrons/claim/${discordId}`, { - username, - groupId, - adminPassword: env.ADMIN_PASSWORD - }); -} - /** * Send an API request attempting to update a player's country */