Skip to content

Commit a2bbd30

Browse files
committed
zap: Some optimization
1 parent 138d997 commit a2bbd30

File tree

1 file changed

+37
-47
lines changed

1 file changed

+37
-47
lines changed

helpers/ipc-client.js

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -84,30 +84,26 @@ module.exports.load = (discordClient) => {
8484
}
8585
if (message.data.event === "paypalNotification") {
8686
console.log(`PayPal notification received! ${message.data}`);
87-
const shardID = message.data.shardID;
88-
if (!discordClient.shard.ids.includes(shardID)) return;
8987
const { premiumLogs } = discordClient.config;
9088
const aLogs = discordClient.channels.cache.get(premiumLogs);
89+
if (!aLogs) return console.log(`Shard #${discordClient.shard.ids[0]}: PayPal Notif, channel logs can not be found`);
90+
const user = discordClient.users.fetch(message.data.userID).catch(() => {});
91+
if (!user) return console.log(`Shard #${discordClient.shard.ids[0]}: PayPal Notif, user can not be found ${message.data.userID}`);
9192
switch (message.data.notificationType) {
9293
case "verification": {
93-
discordClient.users.fetch(message.data.userID).then((user) => {
94-
const logEmbed = new MessageEmbed()
95-
.setAuthor(`${user.tag} purchased ManageInvite Premium`, user.displayAvatarURL())
96-
.setDescription(`Server **${message.data.guildName}** is waiting for verification... :clock7:`)
97-
.setColor("#ff9966");
98-
if (aLogs) aLogs.send(logEmbed);
99-
});
94+
const logEmbed = new MessageEmbed()
95+
.setAuthor(`${user.tag} purchased ManageInvite Premium`, user.displayAvatarURL())
96+
.setDescription(`Server **${message.data.guildName}** is waiting for verification... :clock7:`)
97+
.setColor("#ff9966");
98+
aLogs.send(logEmbed);
10099
break;
101100
}
102101
case "subscribed": {
103-
discordClient.users.fetch(message.data.userID).then((user) => {
104-
const logEmbed = new MessageEmbed()
105-
.setAuthor(`${user.tag} created a subscription`, user.displayAvatarURL())
106-
.setDescription(`Subscription for guild **${message.data.guildName}** created... :white_check_mark:`)
107-
.setColor("#ff9966");
108-
console.log(!!aLogs, "Sending logs embed!");
109-
if (aLogs) aLogs.send(logEmbed);
110-
});
102+
const logEmbed = new MessageEmbed()
103+
.setAuthor(`${user.tag} created a subscription`, user.displayAvatarURL())
104+
.setDescription(`Subscription for guild **${message.data.guildName}** created... :white_check_mark:`)
105+
.setColor("#ff9966");
106+
aLogs.send(logEmbed);
111107
discordClient.shard.broadcastEval(`
112108
if(this.guilds.cache.some((g) => g.roles.cache.has(this.config.premiumRole))){
113109
const guild = this.guilds.cache.find((g) => g.roles.cache.has(this.config.premiumRole));
@@ -119,42 +115,36 @@ module.exports.load = (discordClient) => {
119115
break;
120116
}
121117
case "paid": {
122-
discordClient.users.fetch(message.data.userID).then((user) => {
123-
const logEmbed = new MessageEmbed()
124-
.setAuthor(`${user.tag} paid for ManageInvite Premium`, user.displayAvatarURL())
125-
.setDescription(`Recurring payment for **${message.data.guildName}** was paid (**$2**) :crown:`)
126-
.setColor("#ff9966");
127-
if (aLogs) aLogs.send(logEmbed);
128-
});
118+
const logEmbed = new MessageEmbed()
119+
.setAuthor(`${user.tag} paid for ManageInvite Premium`, user.displayAvatarURL())
120+
.setDescription(`Recurring payment for **${message.data.guildName}** was paid (**$2**) :crown:`)
121+
.setColor("#ff9966");
122+
aLogs.send(logEmbed);
129123
break;
130124
}
131125
case "cancelled": {
132-
discordClient.users.fetch(message.data.userID).then(async (user) => {
133-
const formContent = `Hello, **${user.username}**\r\nWe're sorry to see you go! Could you tell us why you have cancelled your subscription, so that we can try to improve it? :smiley: \r\n\r\nI cancelled my subscription for the following reason: \r\n\r\n:one: I no longer use ManageInvite for my server\r\n:two: I don't want to pay $2 anymore, it's too big a budget for what ManageInvite offers\r\n:three: I found a better bot\r\n:four: Other\r\n** **`;
134-
const formMessage = await user.send(formContent).catch(() => {});
135-
if (formMessage){
136-
formMessage.react("\u0031\u20E3");
137-
formMessage.react("\u0032\u20E3");
138-
formMessage.react("\u0033\u20E3");
139-
formMessage.react("\u0034\u20E3");
140-
}
141-
const logEmbed = new MessageEmbed()
142-
.setAuthor(`${user.tag} cancelled their subscription for ManageInvite Premium`, user.displayAvatarURL())
143-
.setDescription(`Recurring payment for **${message.data.guildName}** was cancelled :wave:\n${formMessage ? "Satisfaction form sent! Awaiting answer... :pencil:" : "I wasn't able to send the satisfaction form... :confused:"}`)
144-
.setFooter(`Form ID: ${formMessage ? formMessage.id : "not sent"}`)
145-
.setColor("#1E90FF");
146-
if (aLogs) aLogs.send(logEmbed);
147-
});
126+
const formContent = `Hello, **${user.username}**\r\nWe're sorry to see you go! Could you tell us why you have cancelled your subscription, so that we can try to improve it? :smiley: \r\n\r\nI cancelled my subscription for the following reason: \r\n\r\n:one: I no longer use ManageInvite for my server\r\n:two: I don't want to pay $2 anymore, it's too big a budget for what ManageInvite offers\r\n:three: I found a better bot\r\n:four: Other\r\n** **`;
127+
const formMessage = await user.send(formContent).catch(() => {});
128+
if (formMessage){
129+
formMessage.react("\u0031\u20E3");
130+
formMessage.react("\u0032\u20E3");
131+
formMessage.react("\u0033\u20E3");
132+
formMessage.react("\u0034\u20E3");
133+
}
134+
const logEmbed = new MessageEmbed()
135+
.setAuthor(`${user.tag} cancelled their subscription for ManageInvite Premium`, user.displayAvatarURL())
136+
.setDescription(`Recurring payment for **${message.data.guildName}** was cancelled :wave:\n${formMessage ? "Satisfaction form sent! Awaiting answer... :pencil:" : "I wasn't able to send the satisfaction form... :confused:"}`)
137+
.setFooter(`Form ID: ${formMessage ? formMessage.id : "not sent"}`)
138+
.setColor("#1E90FF");
139+
aLogs.send(logEmbed);
148140
break;
149141
}
150142
case "dms": {
151-
discordClient.users.fetch(message.data.userID).then((user) => {
152-
const logEmbed = new MessageEmbed()
153-
.setAuthor(`Thanks for purchasing ManageInvite Premium, ${user.tag}`, user.displayAvatarURL())
154-
.setDescription(`Congratulations, your server **${message.data.guildName}** is now premium! :crown:`)
155-
.setColor("#ff9966");
156-
user.send(logEmbed);
157-
});
143+
const logEmbed = new MessageEmbed()
144+
.setAuthor(`Thanks for purchasing ManageInvite Premium, ${user.tag}`, user.displayAvatarURL())
145+
.setDescription(`Congratulations, your server **${message.data.guildName}** is now premium! :crown:`)
146+
.setColor("#ff9966");
147+
user.send(logEmbed);
158148
break;
159149
}
160150
}

0 commit comments

Comments
 (0)