Skip to content

Commit

Permalink
Prevents failing when missing permissions for non-essential feature s…
Browse files Browse the repository at this point in the history
…teps
  • Loading branch information
PolariTOON committed Dec 30, 2023
1 parent cb99d0c commit 5312ff7
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 68 deletions.
16 changes: 9 additions & 7 deletions src/commands/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ const approveCommand: Command = {
});
return;
}
await targetMessage.react("✅");
const reaction: MessageReaction | undefined = targetMessage.reactions.cache.find((reaction: MessageReaction): boolean => {
return (reaction.emoji.name ?? "") === "❎";
});
if (reaction != null) {
await reaction.users.remove();
}
try {
await targetMessage.react("✅");
const reaction: MessageReaction | undefined = targetMessage.reactions.cache.find((reaction: MessageReaction): boolean => {
return (reaction.emoji.name ?? "") === "❎";
});
if (reaction != null) {
await reaction.users.remove();
}
} catch {}
function formatMessage(locale: Locale): string {
return replyLocalizations[locale]({});
}
Expand Down
16 changes: 9 additions & 7 deletions src/commands/refuse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ const refuseCommand: Command = {
});
return;
}
await targetMessage.react("❎");
const reaction: MessageReaction | undefined = targetMessage.reactions.cache.find((reaction: MessageReaction): boolean => {
return (reaction.emoji.name ?? "") === "✅";
});
if (reaction != null) {
await reaction.users.remove();
}
try {
await targetMessage.react("❎");
const reaction: MessageReaction | undefined = targetMessage.reactions.cache.find((reaction: MessageReaction): boolean => {
return (reaction.emoji.name ?? "") === "✅";
});
if (reaction != null) {
await reaction.users.remove();
}
} catch {}
function formatMessage(locale: Locale): string {
return replyLocalizations[locale]({});
}
Expand Down
10 changes: 6 additions & 4 deletions src/hooks/approval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ const approvalHook: Hook = {
parse: [],
},
});
await message.react("🇭");
await message.react("🇪");
await message.react("🇾");
await message.react("👋");
try {
await message.react("🇭");
await message.react("🇪");
await message.react("🇾");
await message.react("👋");
} catch {}
}
const content: string = `You managed to get verified in the official *${escapeMarkdown(name)}* *Discord* server!\nYou should now be able to interact with the community.\nSee you there!`;
await newMember.send({content});
Expand Down
10 changes: 6 additions & 4 deletions src/hooks/arrival.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ const arrivalHook: Hook = {
avatarURL: applicationIcon,
...(channel != null && channel.isThreadOnly() ? {threadName: welcome} : {}),
});
await message.react("🇭");
await message.react("🇪");
await message.react("🇾");
await message.react("👋");
try {
await message.react("🇭");
await message.react("🇪");
await message.react("🇾");
await message.react("👋");
} catch {}
}
},
describe(webhook: Webhook): Localized<(groups: {}) => string> {
Expand Down
10 changes: 6 additions & 4 deletions src/hooks/departure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ const departureHook: Hook = {
avatarURL: applicationIcon,
...(channel != null && channel.isThreadOnly() ? {threadName: farewell} : {}),
});
await message.react("🇧");
await message.react("🇾");
await message.react("🇪");
await message.react("👋");
try {
await message.react("🇧");
await message.react("🇾");
await message.react("🇪");
await message.react("👋");
} catch {}
}
},
describe(webhook: Webhook): Localized<(groups: {}) => string> {
Expand Down
22 changes: 12 additions & 10 deletions src/hooks/patching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,18 @@ const patchingHook: Hook = {
parse: [],
},
});
const replyMessage: Message<boolean> = await message.reply({
content: "Here is the old message:",
});
await replyMessage.reply({
content: oldMessage.content,
files: [...oldMessage.attachments.values()],
allowedMentions: {
parse: [],
},
});
try {
const replyMessage: Message<boolean> = await message.reply({
content: "Here is the old message:",
});
await replyMessage.reply({
content: oldMessage.content,
files: [...oldMessage.attachments.values()],
allowedMentions: {
parse: [],
},
});
} catch {}
}
},
describe(webhook: Webhook): Localized<(groups: {}) => string> {
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ const recordHook: Hook = {
avatarURL: applicationIcon,
...(channel != null && channel.isThreadOnly() ? {threadName: category} : {}),
});
await message.react("🎉");
try {
await message.react("🎉");
} catch {}
}
}
},
Expand Down
10 changes: 6 additions & 4 deletions src/hooks/refusal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ const refusalHook: Hook = {
parse: [],
},
});
await message.react("🇧");
await message.react("🇾");
await message.react("🇪");
await message.react("👋");
try {
await message.react("🇧");
await message.react("🇾");
await message.react("🇪");
await message.react("👋");
} catch {}
}
const content: string = `You did not manage to get verified in the official *${escapeMarkdown(name)}* *Discord* server...\nPlease make sure to read and respect the rules before retrying the verification process.\nSee you there...`;
await newMember.send({content});
Expand Down
58 changes: 31 additions & 27 deletions src/rules/rule7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,34 +118,38 @@ const rule7Rule: Rule = {
}
return emoji;
})();
if (emoji != null) {
await message.reply({
content: `<:${ruleReactionEmoji}:${emoji.id}>`,
});
}
const {rulesChannel}: Guild = guild;
const manualChannel: TextChannel | null = ruleRulesChannel != null ? ((): TextChannel | null => {
const channel: GuildBasedChannel | undefined = guild.channels.cache.find((channel: GuildBasedChannel): boolean => {
return channel.name === ruleRulesChannel;
});
if (channel == null || channel.type !== ChannelType.GuildText) {
return null;
try {
if (emoji != null) {
await message.reply({
content: `<:${ruleReactionEmoji}:${emoji.id}>`,
});
}
return channel;
})() : rulesChannel;
if (manualChannel != null) {
await message.reply({
content: `Please read and respect the rules in <#${manualChannel.id}>!`,
});
}
await message.react("🇷");
await message.react("🇺");
await message.react("🇱");
await message.react("🇪");
await message.react("7️⃣");
if (emoji != null) {
await message.react(emoji);
}
const {rulesChannel}: Guild = guild;
const manualChannel: TextChannel | null = ruleRulesChannel != null ? ((): TextChannel | null => {
const channel: GuildBasedChannel | undefined = guild.channels.cache.find((channel: GuildBasedChannel): boolean => {
return channel.name === ruleRulesChannel;
});
if (channel == null || channel.type !== ChannelType.GuildText) {
return null;
}
return channel;
})() : rulesChannel;
if (manualChannel != null) {
await message.reply({
content: `Please read and respect the rules in <#${manualChannel.id}>!`,
});
}
} catch {}
try {
await message.react("🇷");
await message.react("🇺");
await message.react("🇱");
await message.react("🇪");
await message.react("7️⃣");
if (emoji != null) {
await message.react(emoji);
}
} catch {}
},
describe(autoModerationRule: AutoModerationRule): Localized<(groups: {}) => string> {
const channels: (TextChannel | NewsChannel)[] = autoModerationRule.actions.map<TextChannel | NewsChannel | null>((action: AutoModerationAction): TextChannel | NewsChannel | null => {
Expand Down

0 comments on commit 5312ff7

Please sign in to comment.