Skip to content

Commit

Permalink
suppress notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
minarin0179 committed Oct 15, 2024
1 parent 30f7424 commit 1790ca8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
23 changes: 17 additions & 6 deletions src/commands/slashcommands/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
GuildEmoji,
GuildTextBasedChannel,
Message,
MessageFlags,
MessageReaction,
SlashCommandBuilder,
TextChannel,
Expand Down Expand Up @@ -67,8 +68,8 @@ export default new SlashCommand({
const children =
targetCategory instanceof CategoryChannel
? discordSort(
targetCategory.children.cache.filter((ch): ch is TextChannel => ch.type === ChannelType.GuildText)
)
targetCategory.children.cache.filter((ch): ch is TextChannel => ch.type === ChannelType.GuildText)
)
: new Collection<string, TextChannel>([[targetCategory.id, targetCategory]]);
if (children.size == 0) {
return reply(interaction, { content: "保存するチャンネルがありません", ephemeral: true });
Expand Down Expand Up @@ -105,6 +106,7 @@ export default new SlashCommand({
}
return embedBuilder;
}),
flags: MessageFlags.SuppressNotifications,
});
}

Expand Down Expand Up @@ -142,21 +144,30 @@ const RunArchive = async (source: GuildTextBasedChannel, destination: TextChanne

const slicedDatas = archiveDatas.slice(lastIndex, index + 1);
const embeds = slicedDatas.map(data => data.embed);
await destinationThread.send({ embeds: embeds });
await destinationThread.send({
embeds: embeds,
flags: MessageFlags.SuppressNotifications,
});

for await (const file of data.files) {
await destinationThread.send({ files: [file] });
await destinationThread.send({
files: [file],
flags: MessageFlags.SuppressNotifications,
});
}

if (!isEmptyText(data.reactions)) {
await destinationThread.send(data.reactions);
await destinationThread.send({
content: data.reactions,
flags: MessageFlags.SuppressNotifications,
});
}

lastIndex = index + 1;
embedSize = 0;
}

(await destinationThread.fetchStarterMessage())?.delete().catch(() => {});
(await destinationThread.fetchStarterMessage())?.delete().catch(() => { });
await destinationThread.setArchived(true);

return (source.isThread() ? "┗" : "") + `[_#_ ${destinationThread.name}](${destinationThread.url})`;
Expand Down
3 changes: 2 additions & 1 deletion src/commands/slashcommands/copy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChannelType, GuildChannel, GuildChannelCloneOptions, SlashCommandBuilder } from "discord.js";
import { ChannelType, GuildChannel, GuildChannelCloneOptions, MessageFlags, SlashCommandBuilder } from "discord.js";
import { SlashCommand } from "../../structures/SlashCommand";
import { isCategory } from "../../utils/isCategory";
import { reply } from "../../utils/Reply";
Expand Down Expand Up @@ -41,6 +41,7 @@ export default new SlashCommand({
transferAllMessages(before, after, {
allowedMentions: { parse: [] },
updates: channelLinks,
flags: [MessageFlags.SuppressNotifications],
})
)
);
Expand Down
11 changes: 9 additions & 2 deletions src/utils/transferMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import {
AnyThreadChannel,
Attachment,
AttachmentBuilder,
BitFieldResolvable,
GuildChannel,
GuildTextBasedChannel,
Message,
MessageCreateOptions,
MessageFlags,
MessageMentionOptions,
MessageType,
ThreadChannel,
Expand All @@ -21,6 +23,10 @@ import { MyConstants } from "../constants/constants";
type transferOptions = {
noReaction?: boolean;
allowedMentions?: MessageMentionOptions;
flags?: BitFieldResolvable<
"SuppressEmbeds" | "SuppressNotifications",
MessageFlags.SuppressEmbeds | MessageFlags.SuppressNotifications
>;
updates?: ChannelLink[]; //チャンネルリンク差し替え用
};

Expand All @@ -32,7 +38,7 @@ export const transferMessage = async (
await destination.sendTyping();

let contentAll = message.content;
const { allowedMentions, updates } = options ?? {};
const { allowedMentions, updates, flags } = options ?? {};

if (updates) {
contentAll = replaceChannelLinks(contentAll, updates);
Expand All @@ -44,7 +50,7 @@ export const transferMessage = async (
//最後の1チャンクだけ取り出して残りは先に送る
const content = contentSplit.pop();
for await (const msg of contentSplit) {
await destination.send({ content: msg, allowedMentions });
await destination.send({ content: msg, allowedMentions, flags });
}

const { attachments, components, embeds } = message;
Expand All @@ -63,6 +69,7 @@ export const transferMessage = async (
components,
embeds,
allowedMentions,
flags,
} as MessageCreateOptions;

//transfer,openのボタンを更新
Expand Down

0 comments on commit 1790ca8

Please sign in to comment.