-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Discount unranked metrics in equality checks * Add "claim patreon benefits" modal
- Loading branch information
Showing
9 changed files
with
211 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
To keep Wise Old Man free without any ads, we depend on generous support from our patrons to cover our servers costs. Please consider supporting us. | ||
|
||
<https://wiseoldman.net/patreon> | ||
|
||
# Benefits | ||
|
||
### Tier 1 ($3) | ||
|
||
``` | ||
Support the project, flex your status on the website/Discord AND auto-update your profile everyday? Sounds like a deal to me! | ||
- Daily auto-update for your player profile | ||
- "Patreon Supporter" Badge on your player profile | ||
- "Patreon Supporter" Discord Role | ||
``` | ||
|
||
### Tier 2 ($5.99) | ||
|
||
``` | ||
With this generous pledge, you'll be literally keeping the lights on. As a reward, your group stays up to date and stands out from the others! | ||
- Every Tier 1 benefit | ||
- Daily auto-update for all your group members | ||
- Custom Avatar and Banner on your group page | ||
- Social links on your group page | ||
- "Patreon Supporter" Badge on your group page | ||
- Higher ranking and visibility on group page searches | ||
``` | ||
|
||
# How to claim your benefits | ||
|
||
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. | ||
|
||
** ** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { | ||
ButtonInteraction, | ||
Client, | ||
GuildMember, | ||
MessageActionRow, | ||
MessageButton, | ||
Modal, | ||
ModalSubmitInteraction, | ||
TextInputComponent | ||
} from 'discord.js'; | ||
import config from './config'; | ||
import { hasRole } from './utils'; | ||
import { claimBenefits } from './services/wiseoldman'; | ||
|
||
export const PATREON_MODAL_ID = 'patreon-benefits-modal'; | ||
export const PATREON_TRIGGER_ID = 'patreon-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.`; | ||
|
||
export async function setupPatreonTrigger(client: Client) { | ||
const patreonInfoChannel = client.channels.cache.get(config.discord.channels.patreonInfo); | ||
if (!patreonInfoChannel?.isText()) return; | ||
|
||
const messages = await patreonInfoChannel.messages.fetch({ limit: 100 }); | ||
const botMessages = messages.filter(msg => msg.author.id === client.user?.id); | ||
|
||
if (botMessages.size !== 0) { | ||
// Already posted the Patreon Info message. | ||
return; | ||
} | ||
|
||
const content = fs.readFileSync(path.join('src', 'content', 'patreon-info.md'), 'utf8'); | ||
|
||
const actions = new MessageActionRow().addComponents( | ||
new MessageButton() | ||
.setCustomId(PATREON_TRIGGER_ID) | ||
.setLabel('Claim Patreon Benefits') | ||
.setStyle('SUCCESS') | ||
); | ||
|
||
const message = await patreonInfoChannel.send({ content, components: [actions] }); | ||
await message.suppressEmbeds(true); | ||
} | ||
|
||
export async function handlePatreonTrigger(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_MODAL_ID) | ||
.setTitle(`Claim Patreon 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 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'); | ||
const groupIdValue = interaction.fields.getTextInputValue('groupId'); | ||
|
||
let groupId: number | undefined; | ||
|
||
if (!username) { | ||
interaction.reply({ content: '❌ Please provide your in-game username.', ephemeral: true }); | ||
return; | ||
} | ||
|
||
if (groupIdValue) { | ||
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 claimBenefits(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 }); | ||
} catch (error) { | ||
console.log(error); | ||
interaction.reply({ content: error.message, ephemeral: true }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters