Skip to content

Commit

Permalink
change stuff that broke with .4 and use new features
Browse files Browse the repository at this point in the history
waiting on discordjs/discord.js#8662 and a builders release before merge

This reverts commit ed1a413.

Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
  • Loading branch information
RedGuy12 committed Sep 23, 2022
1 parent 5431a69 commit 9267559
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 55 deletions.
18 changes: 9 additions & 9 deletions commands/explore-potatoes.ts
Expand Up @@ -7,7 +7,7 @@ import {
APIInteractionDataResolvedChannel,
GuildBasedChannel,
Snowflake,
InteractionReplyOptions,
BaseMessageOptions,
} from "discord.js";

import {
Expand Down Expand Up @@ -55,7 +55,7 @@ async function textChannelMatches(
}
case ChannelType.GuildForum:
case ChannelType.GuildText:
case ChannelType.GuildNews: {
case ChannelType.GuildAnnouncement: {
// If channelFound is a matching non-thread it will have already returned at the start of the function, so only check for threads.
const thread = await guild.channels.fetch(channelFound).catch(() => {});
return thread?.parent?.id === channelWanted.id;
Expand Down Expand Up @@ -97,11 +97,11 @@ const info: ChatInputCommand = {
ChannelType.GuildText,
ChannelType.GuildVoice,
ChannelType.GuildCategory,
ChannelType.GuildNews,
ChannelType.GuildNewsThread,
ChannelType.GuildPublicThread,
ChannelType.GuildPrivateThread,
// ChannelType.GuildForum,
ChannelType.GuildAnnouncement,
ChannelType.AnnouncementThread,
ChannelType.PublicThread,
ChannelType.PrivateThread,
ChannelType.GuildForum,
),
),

Expand Down Expand Up @@ -129,10 +129,10 @@ const info: ChatInputCommand = {
const nextId = generateHash("next");
const prevId = generateHash("prev");

const messages: InteractionReplyOptions[] = [];
const messages: BaseMessageOptions[] = [];
let index = 0;

async function getNextMessage(): Promise<InteractionReplyOptions> {
async function getNextMessage(): Promise<BaseMessageOptions> {
const info = (await fetchedMessages.next()).value;

const reply = info
Expand Down
8 changes: 5 additions & 3 deletions commands/guess-addon.ts
Expand Up @@ -18,6 +18,7 @@ import {
Snowflake,
ActionRowBuilder,
ModalActionRowComponentBuilder,
chatInputApplicationCommandMention,
} from "discord.js";
import Fuse from "fuse.js";
import CONSTANTS from "../common/CONSTANTS.js";
Expand All @@ -43,11 +44,12 @@ const fuse = new Fuse(addons, {
{ name: "description", weight: 2 },
],
});
const commandMarkdown = `\n\n*Run the </addon:${
const commandMarkdown = `\n\n*Run the ${chatInputApplicationCommandMention(
"addon",
(await client.application?.commands.fetch({ guildId: process.env.GUILD_ID }))?.find(
(command) => command.name === "addon",
)?.id // TODO: chatInputApplicationCommandMention() (waiting on https://github.com/discordjs/discord.js/pull/8546)
}> command for more information about this addon!*`;
)?.id,
)} command for more information about this addon!*`;

const GROUP_NAMES = ["Addon name", "Categorization", "Credits", "Misc"] as const;

Expand Down
2 changes: 1 addition & 1 deletion commands/suggestion.ts
Expand Up @@ -90,7 +90,7 @@ const COOLDOWN = 60_000;
*
* @returns The member who made the suggestion.
*/
async function getUserFromSuggestion(message: Message): Promise<GuildMember | User> {
async function getUserFromSuggestion(message: Message<true>): Promise<GuildMember | User> {
const author =
message.author.id === CONSTANTS.robotop
? message.embeds[0]?.footer?.text.split(": ")[1]
Expand Down
2 changes: 1 addition & 1 deletion common/CONSTANTS.js
Expand Up @@ -88,7 +88,7 @@ export default /** @type {const} */ ({
),
board: enforceChannelType(
channels.find((channel) => !!channel?.name.endsWith("board")),
[ChannelType.GuildText, ChannelType.GuildNews],
[ChannelType.GuildText, ChannelType.GuildAnnouncement],
),
welcome:
guild.systemChannel ||
Expand Down
4 changes: 3 additions & 1 deletion common/board.js
Expand Up @@ -46,6 +46,8 @@ await boardDatabase.init();
/**
* @param {import("./database").Databases["board"] | import("discord.js").Message} info
* @param {{ pre?: ButtonBuilder[]; post?: ButtonBuilder[] }} [extraButtons]
*
* @returns {Promise<import("discord.js").BaseMessageOptions | undefined>}
*/
export async function generateBoardMessage(info, extraButtons = {}) {
const count =
Expand Down Expand Up @@ -177,7 +179,7 @@ export async function updateBoard(message) {
allowedMentions: pings ? undefined : { users: [] },
});

if (CONSTANTS.channels.board.type === ChannelType.GuildNews)
if (CONSTANTS.channels.board.type === ChannelType.GuildAnnouncement)
promises.push(boardMessage.crosspost());

boardDatabase.data = info
Expand Down
2 changes: 1 addition & 1 deletion common/moderation/logging.js
Expand Up @@ -10,7 +10,7 @@ export const LOG_GROUPS = /** @type {const} */ ([
/**
* @param {string} content
* @param {typeof LOG_GROUPS[number]} group
* @param {Pick<import("discord.js").MessageOptions, "embeds" | "files" | "components">} [extra]
* @param {Pick<import("discord.js").BaseMessageOptions, "embeds" | "files" | "components">} [extra]
*/
export default async function log(content, group, extra = {}) {
const thread = await getLoggingThread(group);
Expand Down
4 changes: 2 additions & 2 deletions common/modmail.js
Expand Up @@ -32,7 +32,7 @@ export const MODMAIL_UNSUPPORTED =
*
* @param {import("discord.js").Message} message - Message sent by a user.
*
* @returns Webhook message.
* @returns {Promise<import("discord.js").WebhookCreateMessageOptions>} - Webhook message.
*/
export async function generateModmailMessage(message) {
const { files, embeds } = await extractMessageExtremities(message);
Expand Down Expand Up @@ -185,7 +185,7 @@ export async function sendOpenedMessage(user) {
/**
* @param {EmbedBuilder} confirmEmbed
* @param {(buttonInteraction: import("discord.js").MessageComponentInteraction) => Promise<void>} onConfirm
* @param {(options: { components: [MessageActionRowBuilder]; embeds: [EmbedBuilder] }) => Promise<Message>} reply
* @param {(options: import("discord.js").BaseMessageOptions) => Promise<Message>} reply
*/
export async function generateModmailConfirm(confirmEmbed, onConfirm, reply) {
const confirmId = generateHash("confirm");
Expand Down
2 changes: 1 addition & 1 deletion events/channel/create.js
Expand Up @@ -10,7 +10,7 @@ export default async function event(channel) {
[ChannelType.GuildText]: "Text",
[ChannelType.GuildVoice]: "Voice",
[ChannelType.GuildCategory]: "Category",
[ChannelType.GuildNews]: "Announcement",
[ChannelType.GuildAnnouncement]: "Announcement",
[ChannelType.GuildStageVoice]: "Stage",
[ChannelType.GuildForum]: "Forum",
}[channel.type]
Expand Down
2 changes: 1 addition & 1 deletion events/channel/delete.js
Expand Up @@ -10,7 +10,7 @@ export default async function event(channel) {
[ChannelType.GuildText]: "Text",
[ChannelType.GuildVoice]: "Voice",
[ChannelType.GuildCategory]: "Category",
[ChannelType.GuildNews]: "Announcement",
[ChannelType.GuildAnnouncement]: "Announcement",
[ChannelType.GuildStageVoice]: "Stage",
[ChannelType.GuildForum]: "Forum",
}[channel.type]
Expand Down
17 changes: 14 additions & 3 deletions events/channel/update.js
Expand Up @@ -26,7 +26,7 @@ export default async function event(oldChannel, newChannel) {
[ChannelType.GuildText]: " text",
[ChannelType.GuildVoice]: " voice",
[ChannelType.GuildCategory]: " category",
[ChannelType.GuildNews]: "n announcement",
[ChannelType.GuildAnnouncement]: "n announcement",
[ChannelType.GuildStageVoice]: " stage",
[ChannelType.GuildForum]: " forum",
}[newChannel.type] +
Expand Down Expand Up @@ -60,8 +60,12 @@ export default async function event(oldChannel, newChannel) {
}

if (
(oldChannel.type === ChannelType.GuildText || oldChannel.type === ChannelType.GuildNews) &&
(newChannel.type === ChannelType.GuildText || newChannel.type === ChannelType.GuildNews)
(oldChannel.type === ChannelType.GuildText ||
oldChannel.type === ChannelType.GuildForum ||
oldChannel.type === ChannelType.GuildAnnouncement) &&
(newChannel.type === ChannelType.GuildText ||
newChannel.type === ChannelType.GuildForum ||
newChannel.type === ChannelType.GuildAnnouncement)
) {
if (oldChannel.topic !== newChannel.topic) {
log(`✏ Channel ${newChannel.toString()}’s topic was changed!`, "channels", {
Expand Down Expand Up @@ -96,6 +100,13 @@ export default async function event(oldChannel, newChannel) {
);
}

if (oldChannel.type === ChannelType.GuildForum && newChannel.type === ChannelType.GuildForum) {
// TODO
oldChannel.availableTags;
oldChannel.defaultReactionEmoji;
oldChannel.defaultThreadRateLimitPerUser;
}

if (oldChannel.type === ChannelType.GuildVoice && newChannel.type === ChannelType.GuildVoice)
oldChannel.videoQualityMode !== newChannel.videoQualityMode &&
edits.push(
Expand Down
10 changes: 9 additions & 1 deletion events/guild/update.js
Expand Up @@ -97,10 +97,18 @@ export default async function event(oldGuild, newGuild) {
if (
oldGuild.features.includes("HAS_DIRECTORY_ENTRY") !==
newGuild.features.includes("HAS_DIRECTORY_ENTRY")
) {
logs.push(
`➕ Invites ${newGuild.features.includes("HAS_DIRECTORY_ENTRY") ? "" : "un"}paused`,
);
}
if (
oldGuild.features.includes("INVITES_DISABLED") !==
newGuild.features.includes("INVITES_DISABLED")
) {
logs.push(
`Server ${
newGuild.features.includes("HAS_DIRECTORY_ENTRY") ? "add" : "remov"
newGuild.features.includes("INVITES_DISABLED") ? "add" : "remov"
}ed from a directory channel`,
);
}
Expand Down
6 changes: 3 additions & 3 deletions events/interactionCreate.js
Expand Up @@ -107,9 +107,9 @@ export default async function event(interaction) {
await command.interaction(interaction);
} catch (error) {
logError(error, interaction.toString());
await interaction[
interaction.replied ? "followUp" : interaction.deferred ? "editReply" : "reply"
]({
await (interaction.replied
? interaction.followUp
: interaction[interaction.deferred ? "editReply" : "reply"])({
ephemeral: true,
content: `${CONSTANTS.emojis.statuses.no} An error occurred.`,
embeds: [],
Expand Down
4 changes: 2 additions & 2 deletions events/message/create.js
Expand Up @@ -139,7 +139,7 @@ export default async function event(message) {
}

if (
message.channel.type === ChannelType.GuildPublicThread &&
message.channel.type === ChannelType.PublicThread &&
message.channel.parent?.id === CONSTANTS.channels.modmail?.id &&
!message.content.startsWith("=") &&
(message.webhookId && message.author.id !== client.user?.id
Expand Down Expand Up @@ -209,7 +209,7 @@ export default async function event(message) {

if (CONSTANTS.channels.modlogs?.id !== getBaseChannel(message.channel)?.id) {
// eslint-disable-next-line no-irregular-whitespace -- This is intended.
const spoilerHack = "||​||".repeat(200);
const spoilerHack = "||​||".repeat(199);

if (message.content.includes(spoilerHack)) {
const array = message.cleanContent.split(spoilerHack);
Expand Down
23 changes: 21 additions & 2 deletions events/thread/update.js
@@ -1,4 +1,4 @@
import { EmbedBuilder, ThreadAutoArchiveDuration } from "discord.js";
import { EmbedBuilder, ThreadAutoArchiveDuration, ButtonBuilder, ButtonStyle } from "discord.js";
import {
MODMAIL_COLORS,
getUserFromModmail,
Expand All @@ -11,6 +11,7 @@ import { badWordsAllowed, censor } from "../../common/moderation/automod.js";
import log, { LOG_GROUPS } from "../../common/moderation/logging.js";
import { DATABASE_THREAD } from "../../common/database.js";
import CONSTANTS from "../../common/CONSTANTS.js";
import { MessageActionRowBuilder } from "../../common/types/ActionRowBuilder.js";

/** @type {import("../../common/types/event").default<"threadUpdate">} */
export default async function event(oldThread, newThread) {
Expand Down Expand Up @@ -43,7 +44,25 @@ export default async function event(oldThread, newThread) {
` second${newThread.rateLimitPerUser === 1 ? "" : "s"}`,
);
}

newThread.appliedTags; // TODO
if (oldThread.flags.has("Pinned") !== newThread.flags.has("Pinned")) {
await log(
`📌 Post ${
newThread.flags.has("Pinned") ? "" : "un"
}pinned in ${newThread.parent?.toString()}!`,
"messages",
{
components: [
new MessageActionRowBuilder().addComponents(
new ButtonBuilder()
.setLabel("View Post")
.setStyle(ButtonStyle.Link)
.setURL(newThread.url),
),
],
},
);
}
if (
newThread.archived &&
(newThread.name === DATABASE_THREAD ||
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "scradd",
"version": "2.0.3",
"version": "2.0.4-pre",
"private": true,
"description": "Custom Discord bot for the Scratch Addons server.",
"homepage": "https://discord.gg/FPv957V6SD",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -13,7 +13,7 @@
"maxNodeModuleJsDepth": 0,
"module": "ESNext",
"moduleResolution": "Node",
"noEmitOnError": true,
"noEmitOnError": false,
"noErrorTruncation": true,
"noImplicitAny": true,
"noImplicitOverride": true,
Expand Down
13 changes: 7 additions & 6 deletions util/discord.js
Expand Up @@ -8,6 +8,7 @@ import {
Message,
MessageType,
SelectMenuBuilder,
ChannelType,
} from "discord.js";
import CONSTANTS from "../common/CONSTANTS.js";
import { escapeMessage, escapeLinks } from "./markdown.js";
Expand All @@ -18,7 +19,7 @@ import { MessageActionRowBuilder } from "../common/types/ActionRowBuilder.js";
/**
* @param {import("discord.js").Message | import("discord.js").PartialMessage} message
*
* @returns {Promise<Required<Pick<import("discord.js").MessageOptions, "embeds" | "files">>>}
* @returns {Promise<Required<Pick<import("discord.js").BaseMessageOptions, "embeds" | "files">>>}
*/
export async function extractMessageExtremities(message, allowLanguage = true) {
const embeds = [
Expand Down Expand Up @@ -182,8 +183,10 @@ export async function messageToText(message, replies = true) {
return (
CONSTANTS.emojis.discord.edit +
` ${message.author.toString()} changed the ${
// message.channel.type === ChannelType.GuildForum ? "post title" :
"channel name"
message.channel.isThread() &&
message.channel.parent?.type === ChannelType.GuildForum
? "post title"
: "channel name"
}: **${escapeMessage(message.content)}**`
);
}
Expand Down Expand Up @@ -358,9 +361,7 @@ export async function reactAll(message, reactions) {
* @param {(value: T, index: number, array: (T | undefined)[]) => string} toString
* @param {string} failMessage
* @param {string} title
* @param {(
* options: import("discord.js").WebhookEditMessageOptions,
* ) => Promise<Message | import("discord.js").InteractionResponse | void>} reply
* @param {(options: import("discord.js").BaseMessageOptions) => Promise<Message | import("discord.js").InteractionResponse | void>} reply
*/

export async function paginate(array, toString, failMessage, title, reply) {
Expand Down

0 comments on commit 9267559

Please sign in to comment.