Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/commands/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ const applyCommand: Command = {
const {member, guild, locale}: ChatInputCommandInteraction<"cached"> = interaction;
const resolvedLocale: Locale = resolve(locale);
const {roles}: Guild = guild;
const applyingRole: Role | undefined = roles.cache.find((role: Role): boolean => {
const applyingRole: Role | null = roles.cache.find((role: Role): boolean => {
return role.name === commandApplyingRole;
});
}) ?? null;
if (applyingRole == null) {
return;
}
const verifiedRole: Role | undefined = roles.cache.find((role: Role): boolean => {
const verifiedRole: Role | null = roles.cache.find((role: Role): boolean => {
return role.name === commandVerifiedRole;
});
}) ?? null;
if (verifiedRole == null) {
return;
}
Expand Down
34 changes: 17 additions & 17 deletions src/commands/approve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
Message,
MessageContextMenuCommandInteraction,
MessageReaction,
PartialMessageReaction,
Role,
} from "discord.js";
import type Command from "../commands.js";
Expand Down Expand Up @@ -52,31 +53,30 @@ const approveCommand: Command = {
const {guild, locale, targetMessage}: MessageContextMenuCommandInteraction<"cached"> = interaction;
const resolvedLocale: Locale = resolve(locale);
const {roles}: Guild = guild;
const applyingRole: Role | undefined = roles.cache.find((role: Role): boolean => {
const applyingRole: Role | null = roles.cache.find((role: Role): boolean => {
return role.name === commandApplyingRole;
});
}) ?? null;
if (applyingRole == null) {
return;
}
const verifiedRole: Role | undefined = roles.cache.find((role: Role): boolean => {
const verifiedRole: Role | null = roles.cache.find((role: Role): boolean => {
return role.name === commandVerifiedRole;
});
}) ?? null;
if (verifiedRole == null) {
return;
}
const member: GuildMember | undefined = await (async (): Promise<GuildMember | undefined> => {
const member: GuildMember | null = await (async (): Promise<GuildMember | null> => {
try {
const {author, member}: Message<true> = targetMessage;
if (member == null) {
const memberId: string = author.id;
const member: GuildMember | undefined = guild.members.cache.get(memberId);
if (member == null) {
return await guild.members.fetch(memberId);
}
return member;
const {author}: Message<true> = targetMessage;
const memberId: string = author.id;
const member: GuildMember | null = guild.members.cache.get(memberId) ?? null;
if (member == null || member.partial) {
return await guild.members.fetch(memberId);
}
return member;
} catch {}
} catch {
return null;
}
})();
if (member == null) {
await interaction.reply({
Expand All @@ -96,9 +96,9 @@ const approveCommand: Command = {
return;
}
await targetMessage.react("✅");
const reaction: MessageReaction | undefined = targetMessage.reactions.cache.find((reaction: MessageReaction): boolean => {
return (reaction.emoji.name ?? "") === "❎";
});
const reaction: MessageReaction | null = targetMessage.reactions.cache.find((reaction: MessageReaction | PartialMessageReaction): reaction is MessageReaction => {
return !reaction.partial && (reaction.emoji.name ?? "") === "❎";
}) ?? null;
if (reaction != null) {
await reaction.users.remove();
}
Expand Down
20 changes: 16 additions & 4 deletions src/commands/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,29 @@ const chatCommand: Command = {
});
return;
}
const message: Message<true> | undefined = await (async (): Promise<Message<true> | undefined> => {
const message: Message<true> | null = await (async (): Promise<Message<true> | null> => {
try {
if (channel.isThreadOnly()) {
const thread: ThreadChannel<boolean> | undefined = channel.threads.cache.get(identifier);
const thread: ThreadChannel<boolean> | null = await (async (): Promise<ThreadChannel<boolean> | null> => {
try {
const thread: ThreadChannel<true> | null = channel.threads.cache.get(identifier) ?? null;
if (thread == null || thread.partial) {
return await channel.threads.fetch(identifier);
}
return thread;
} catch {
return null;
}
})();
if (thread == null) {
return;
return null;
}
return await thread.messages.fetch(identifier);
}
return await channel.messages.fetch(identifier);
} catch {}
} catch {
return null;
}
})();
if (message == null) {
await interaction.reply({
Expand Down
20 changes: 16 additions & 4 deletions src/commands/gate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,29 @@ const gateCommand: Command = {
});
return;
}
const message: Message<true> | undefined = await (async (): Promise<Message<true> | undefined> => {
const message: Message<true> | null = await (async (): Promise<Message<true> | null> => {
try {
if (channel.isThreadOnly()) {
const thread: ThreadChannel<boolean> | undefined = channel.threads.cache.get(identifier);
const thread: ThreadChannel<boolean> | null = await (async (): Promise<ThreadChannel<boolean> | null> => {
try {
const thread: ThreadChannel<true> | null = channel.threads.cache.get(identifier) ?? null;
if (thread == null || thread.partial) {
return await channel.threads.fetch(identifier);
}
return thread;
} catch {
return null;
}
})();
if (thread == null) {
return;
return null;
}
return await thread.messages.fetch(identifier);
}
return await channel.messages.fetch(identifier);
} catch {}
} catch {
return null;
}
})();
if (message == null) {
await interaction.reply({
Expand Down
54 changes: 30 additions & 24 deletions src/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,33 +82,33 @@ function hasAdministratorPermission(channel: GuildBasedChannel, member: GuildMem
}
function hasChannelPermission(permissions: Collection<string, ApplicationCommandPermissions[]>, applicationOrCommand: ClientApplication | ApplicationCommand, channel: GuildBasedChannel): boolean | null {
const allChannelsId: string = `${BigInt(channel.guild.id) - 1n}`;
const applicationOrCommandPermissions: ApplicationCommandPermissions[] | undefined = permissions.get(applicationOrCommand.id);
const applicationOrCommandPermissions: ApplicationCommandPermissions[] | null = permissions.get(applicationOrCommand.id) ?? null;
if (applicationOrCommandPermissions == null) {
return null;
}
const channelPermission: ApplicationCommandPermissions | undefined = applicationOrCommandPermissions.find((permission: ApplicationCommandPermissions): boolean => {
const channelPermission: ApplicationCommandPermissions | null = applicationOrCommandPermissions.find((permission: ApplicationCommandPermissions): boolean => {
return permission.type === ApplicationCommandPermissionType.Channel && permission.id === channel.id;
});
}) ?? null;
if (channelPermission != null) {
return channelPermission.permission;
}
const allChannelsPermission: ApplicationCommandPermissions | undefined = applicationOrCommandPermissions.find((permission: ApplicationCommandPermissions): boolean => {
const allChannelsPermission: ApplicationCommandPermissions | null = applicationOrCommandPermissions.find((permission: ApplicationCommandPermissions): boolean => {
return permission.type === ApplicationCommandPermissionType.Channel && permission.id === allChannelsId;
});
}) ?? null;
if (allChannelsPermission != null) {
return allChannelsPermission.permission;
}
return null;
}
function hasMemberPermission(permissions: Collection<string, ApplicationCommandPermissions[]>, applicationOrCommand: ClientApplication | ApplicationCommand, member: GuildMember): boolean | null {
const allUsersId: string = member.guild.id;
const applicationOrCommandPermissions: ApplicationCommandPermissions[] | undefined = permissions.get(applicationOrCommand.id);
const applicationOrCommandPermissions: ApplicationCommandPermissions[] | null = permissions.get(applicationOrCommand.id) ?? null;
if (applicationOrCommandPermissions == null) {
return null;
}
const userPermission: ApplicationCommandPermissions | undefined = applicationOrCommandPermissions.find((permission: ApplicationCommandPermissions): boolean => {
const userPermission: ApplicationCommandPermissions | null = applicationOrCommandPermissions.find((permission: ApplicationCommandPermissions): boolean => {
return permission.type === ApplicationCommandPermissionType.User && permission.id === member.id;
});
}) ?? null;
if (userPermission != null) {
return userPermission.permission;
}
Expand All @@ -122,9 +122,9 @@ function hasMemberPermission(permissions: Collection<string, ApplicationCommandP
return permission.permission;
});
}
const allUsersPermission: ApplicationCommandPermissions | undefined = applicationOrCommandPermissions.find((permission: ApplicationCommandPermissions): boolean => {
const allUsersPermission: ApplicationCommandPermissions | null = applicationOrCommandPermissions.find((permission: ApplicationCommandPermissions): boolean => {
return permission.type === ApplicationCommandPermissionType.User && permission.id === allUsersId;
});
}) ?? null;
if (allUsersPermission != null) {
return allUsersPermission.permission;
}
Expand Down Expand Up @@ -205,26 +205,32 @@ const helpCommand: Command = {
return;
}
const applicationCommands: Collection<string, ApplicationCommand> = guild.commands.cache;
const permissions: Collection<string, ApplicationCommandPermissions[]> | undefined = await (async (): Promise<Collection<string, ApplicationCommandPermissions[]> | undefined> => {
const permissions: Collection<string, ApplicationCommandPermissions[]> | null = await (async (): Promise<Collection<string, ApplicationCommandPermissions[]> | null> => {
try {
return await guild.commands.permissions.fetch({});
} catch {}
} catch {
return null;
}
})();
if (permissions == null) {
return;
}
const webhooks: Collection<string, Webhook> | undefined = await (async (): Promise<Collection<string, Webhook> | undefined> => {
const webhooks: Collection<string, Webhook> | null = await (async (): Promise<Collection<string, Webhook> | null> => {
try {
return await guild.fetchWebhooks();
} catch {}
} catch {
return null;
}
})();
if (webhooks == null) {
return;
}
const autoModerationRules: Collection<string, AutoModerationRule> | undefined = await (async (): Promise<Collection<string, AutoModerationRule> | undefined> => {
const autoModerationRules: Collection<string, AutoModerationRule> | null = await (async (): Promise<Collection<string, AutoModerationRule> | null> => {
try {
return await guild.autoModerationRules.fetch();
} catch {}
} catch {
return null;
}
})();
if (autoModerationRules == null) {
return;
Expand All @@ -233,9 +239,9 @@ const helpCommand: Command = {
const descriptions: Localized<(groups: {}) => string>[] = [
Object.keys(commands).map<Localized<(groups: {}) => string> | null>((commandName: string): Localized<(groups: {}) => string> | null => {
const command: Command = commands[commandName as keyof typeof commands];
const applicationCommand: ApplicationCommand | undefined = applicationCommands.find((applicationCommand: ApplicationCommand): boolean => {
const applicationCommand: ApplicationCommand | null = applicationCommands.find((applicationCommand: ApplicationCommand): boolean => {
return applicationCommand.name === commandName;
});
}) ?? null;
if (applicationCommand == null) {
return null;
}
Expand All @@ -256,9 +262,9 @@ const helpCommand: Command = {
}),
Object.keys(hooks).map<Localized<(groups: {}) => string> | null>((hookName: string): Localized<(groups: {}) => string> | null => {
const hook: Hook = hooks[hookName as keyof typeof hooks];
const webhook: Webhook | undefined = webhooks.find((webhook: Webhook): boolean => {
const webhook: Webhook | null = webhooks.find((webhook: Webhook): boolean => {
return webhook.name === hookName;
});
}) ?? null;
if (webhook == null) {
return null;
}
Expand All @@ -277,9 +283,9 @@ const helpCommand: Command = {
}),
Object.keys(rules).map<Localized<(groups: {}) => string> | null>((ruleName: string): Localized<(groups: {}) => string> | null => {
const rule: Rule = rules[ruleName as keyof typeof rules];
const autoModerationRule: AutoModerationRule | undefined = autoModerationRules.find((autoModerationRule: AutoModerationRule): boolean => {
const autoModerationRule: AutoModerationRule | null = autoModerationRules.find((autoModerationRule: AutoModerationRule): boolean => {
return autoModerationRule.name === ruleName;
});
}) ?? null;
if (autoModerationRule == null) {
return null;
}
Expand All @@ -295,8 +301,8 @@ const helpCommand: Command = {
if (channelId == null) {
return null;
}
const channel: GuildBasedChannel | undefined = autoModerationRule.guild.channels.cache.get(channelId);
if (channel == null || channel.isThread() || channel.isVoiceBased() || !channel.isTextBased()) {
const channel: GuildBasedChannel | null = autoModerationRule.guild.channels.cache.get(channelId) ?? null;
if (channel == null || channel.partial || channel.isThread() || channel.isVoiceBased() || !channel.isTextBased()) {
return null;
}
return channel;
Expand Down
34 changes: 17 additions & 17 deletions src/commands/refuse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
Message,
MessageContextMenuCommandInteraction,
MessageReaction,
PartialMessageReaction,
Role,
} from "discord.js";
import type Command from "../commands.js";
Expand Down Expand Up @@ -52,31 +53,30 @@ const refuseCommand: Command = {
const {guild, locale, targetMessage}: MessageContextMenuCommandInteraction<"cached"> = interaction;
const resolvedLocale: Locale = resolve(locale);
const {roles}: Guild = guild;
const applyingRole: Role | undefined = roles.cache.find((role: Role): boolean => {
const applyingRole: Role | null = roles.cache.find((role: Role): boolean => {
return role.name === commandApplyingRole;
});
}) ?? null;
if (applyingRole == null) {
return;
}
const verifiedRole: Role | undefined = roles.cache.find((role: Role): boolean => {
const verifiedRole: Role | null = roles.cache.find((role: Role): boolean => {
return role.name === commandVerifiedRole;
});
}) ?? null;
if (verifiedRole == null) {
return;
}
const member: GuildMember | undefined = await (async (): Promise<GuildMember | undefined> => {
const member: GuildMember | null = await (async (): Promise<GuildMember | null> => {
try {
const {author, member}: Message<true> = targetMessage;
if (member == null) {
const memberId: string = author.id;
const member: GuildMember | undefined = guild.members.cache.get(memberId);
if (member == null) {
return await guild.members.fetch(memberId);
}
return member;
const {author}: Message<true> = targetMessage;
const memberId: string = author.id;
const member: GuildMember | null = guild.members.cache.get(memberId) ?? null;
if (member == null || member.partial) {
return await guild.members.fetch(memberId);
}
return member;
} catch {}
} catch {
return null;
}
})();
if (member == null) {
await interaction.reply({
Expand All @@ -96,9 +96,9 @@ const refuseCommand: Command = {
return;
}
await targetMessage.react("❎");
const reaction: MessageReaction | undefined = targetMessage.reactions.cache.find((reaction: MessageReaction): boolean => {
return (reaction.emoji.name ?? "") === "✅";
});
const reaction: MessageReaction | null = targetMessage.reactions.cache.find((reaction: MessageReaction | PartialMessageReaction): reaction is MessageReaction => {
return !reaction.partial && (reaction.emoji.name ?? "") === "✅";
}) ?? null;
if (reaction != null) {
await reaction.users.remove();
}
Expand Down
18 changes: 9 additions & 9 deletions src/commands/roadmap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type {
ChatInputCommandInteraction,
ForumChannel,
GuildBasedChannel,
MediaChannel,
NewsChannel,
StageChannel,
TextChannel,
VoiceChannel,
} from "discord.js";
import type Command from "../commands.js";
import type {ApplicationCommand, ApplicationCommandData, ApplicationUserInteraction} from "../commands.js";
Expand Down Expand Up @@ -44,15 +50,9 @@ const roadmapCommand: Command = {
}
const {guild, locale}: ChatInputCommandInteraction<"cached"> = interaction;
const resolvedLocale: Locale = resolve(locale);
const channel: GuildBasedChannel | null = ((): GuildBasedChannel | null => {
const channel: GuildBasedChannel | undefined = guild.channels.cache.find((channel: GuildBasedChannel): boolean => {
return channel.name === commandIntentChannel;
});
if (channel == null || channel.type === ChannelType.GuildCategory || channel.isThread()) {
return null;
}
return channel;
})();
const channel: TextChannel | NewsChannel | VoiceChannel | StageChannel | ForumChannel | MediaChannel | null = guild.channels.cache.find((channel: GuildBasedChannel): channel is TextChannel | NewsChannel | VoiceChannel | StageChannel | ForumChannel | MediaChannel => {
return !channel.partial && channel.type !== ChannelType.GuildCategory && !channel.isThread() && channel.name === commandIntentChannel;
}) ?? null;
function formatMessage(locale: Locale): string {
return replyLocalizations[locale]({
intent: (): string => {
Expand Down
Loading