Skip to content

Commit

Permalink
check discord supporter with command
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherBThai committed Dec 12, 2023
1 parent f782921 commit 83270ad
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dblapi.js": "^2.4.0",
"dd-trace": "^0.31.4",
"dotenv": "^10.0.0",
"eris-sharder": "github:ChristopherBThai/eris-sharder#65d94d5725868dab23552b5bdb60d526e4391a7f",
"eris-sharder": "github:ChristopherBThai/eris-sharder#82e175ccbfa023450f26ab015151f57bc5dec766",
"erlpack": "github:abalabahaha/erlpack",
"eventemitter3": "^4.0.4",
"express": "^4.17.1",
Expand Down
2 changes: 0 additions & 2 deletions src/commands/commandList/patreon/utils/patreonUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ function parseEntitlment(entitlment) {
return { error: 'Invalid User' };
}
let endDate = entitlment.ends_at;
// TODO delete
endDate = Date.now();
if (!endDate) {
return { error: 'Invalid End Time' };
}
Expand Down
108 changes: 76 additions & 32 deletions src/commands/commandList/utils/patreon.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const CommandInterface = require('../../CommandInterface.js');

const patreonUtil = require('../patreon/utils/patreonUtil.js');

const checkId = 'supporter_check';

module.exports = new CommandInterface({
alias: ['patreon', 'donate', 'support', 'supporter'],

Expand All @@ -32,37 +34,79 @@ module.exports = new CommandInterface({
delete p.msg.author.supporterRank;
const supporter = await patreonUtil.getSupporterRank(p, p.msg.author);

let stat = 'Join today for special animals and benefits!';
const timestamp = this.global.toDiscordTimestamp(new Date(supporter.endTime), 'f');
if (supporter.benefitRank >= 3) {
stat = 'You are currently a **Supporter+**!';
stat += '\n**<:blank:427371936482328596> |** until: **' + timestamp + '**';
} else if (supporter.benefitRank >= 1) {
stat = 'You are currently a **Supporter**!';
stat += '\n**<:blank:427371936482328596> |** until: **' + timestamp + '**';
}

let content = `**${this.config.emoji.owo.woah} |** Donate to OwO Bot for special benefits!\n**${this.config.emoji.blank} |** ${stat}`;
content += `\n**${this.config.emoji.blank} |** Join by clicking my profile or one of the following choices below!`;
const components = [
{
type: 1,
components: [
{
type: 2,
label: 'Patreon',
style: 5,
url: 'https://www.patreon.com/OwOBot',
},
{
type: 2,
label: 'OwO Store',
style: 5,
url: 'https://owobot.com/store',
},
],
},
];
p.send({ content, components });
let content = createContent.bind(this)(supporter);
const msg = await p.send(content);

let filter = (componentName, user) =>
componentName === checkId && user.id === this.msg.author.id;
let collector = this.interactionCollector.create(msg, filter, {
time: 900000,
});

collector.on('collect', async (component, user, ack, err, value, entitlements) => {
collector.stop();
if (entitlements && entitlements.length) {
for (let i in entitlements) {
await patreonUtil.handleDiscordUpdate.bind(this)(entitlements[i]);
}
}
delete p.msg.author.supporterRank;
const supporter = await patreonUtil.getSupporterRank(p, p.msg.author);
let content = createContent.bind(this)(supporter);
content.components[0].components[2].disabled = true;
ack(content);
});

collector.on('end', async () => {
if (content.components[0].components[2]) {
content.components[0].components[2].disabled = true;
}
msg.edit(content);
});
},
});

function createContent(supporter) {
let stat = 'Join today for special animals and benefits!';
const timestamp = this.global.toDiscordTimestamp(new Date(supporter.endTime), 'f');
if (supporter.benefitRank >= 3) {
stat = 'You are currently a **Supporter+**!';
stat += '\n**<:blank:427371936482328596> |** until: **' + timestamp + '**';
} else if (supporter.benefitRank >= 1) {
stat = 'You are currently a **Supporter**!';
stat += '\n**<:blank:427371936482328596> |** until: **' + timestamp + '**';
}

let content = `**${this.config.emoji.owo.woah} |** Donate to OwO Bot for special benefits!\n**${this.config.emoji.blank} |** ${stat}`;
content += `\n**${this.config.emoji.blank} |** Join by clicking my profile or one of the following choices below!`;
const components = [
{
type: 1,
components: [
{
type: 2,
label: 'Patreon',
style: 5,
url: 'https://www.patreon.com/OwOBot',
},
{
type: 2,
label: 'OwO Store',
style: 5,
url: 'https://owobot.com/store',
},
{
type: 2,
label: 'Check Subscription',
custom_id: checkId,
style: 1,
emoji: {
id: null,
name: this.config.emoji.magnify,
},
},
],
},
];
return { content, components };
}
1 change: 1 addition & 0 deletions src/data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"battle": "",
"essence": "<a:essence:451638978299428875>",
"star": "",
"magnify": "🔎",
"perkTicket": {
"common": "<:cticket:815767124680114206>",
"wcommon": "<:wcticket:930641266159517726>",
Expand Down
8 changes: 4 additions & 4 deletions src/utils/interactionCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class InteractionCollector {
return iee;
}

interact({ member, message, data, id, token }) {
interact({ member, message, data, id, token, entitlements }) {
member.id = member.user.id;
const listener = this.listeners[message.id] || this.listeners[message.interaction?.id];
if (listener) {
listener.interact(data, member, id, token);
listener.interact(data, member, id, token, entitlements);
} else {
const url = `https://discord.com/api/v8/interactions/${id}/${token}/callback`;
const content = {
Expand Down Expand Up @@ -58,7 +58,7 @@ class InteractionEventEmitter extends EventEmitter {
return this.filter(componentName, user);
}

interact(component, user, id, token) {
interact(component, user, id, token, entitlements) {
if (!this.checkFilter(component.custom_id, user)) {
const url = `https://discord.com/api/v8/interactions/${id}/${token}/callback`;
const content = {
Expand Down Expand Up @@ -118,7 +118,7 @@ class InteractionEventEmitter extends EventEmitter {
});
}

this.emit('collect', component.custom_id, user, ack, err, component.values);
this.emit('collect', component.custom_id, user, ack, err, component.values, entitlements);

if (this.idleTimeout) {
clearTimeout(this.idle);
Expand Down

0 comments on commit 83270ad

Please sign in to comment.