diff --git a/package.json b/package.json index 16388fd..5a2a44a 100644 --- a/package.json +++ b/package.json @@ -33,19 +33,19 @@ "dist/**/*.js.map" ], "devDependencies": { - "@types/node": "^18.11.18", - "@types/react": "^18.0.27", - "@types/react-dom": "^18.0.10", - "@typescript-eslint/eslint-plugin": "^5.49.0", - "@typescript-eslint/parser": "^5.49.0", + "@types/node": "^20.8.5", + "@types/react": "^18.2.28", + "@types/react-dom": "^18.2.13", + "@typescript-eslint/eslint-plugin": "^6.7.5", + "@typescript-eslint/parser": "^6.7.5", "discord.js": "^14.13.0", - "dotenv": "^16.0.3", - "eslint": "^8.32.0", + "dotenv": "^16.3.1", + "eslint": "^8.51.0", "husky": "^8.0.3", - "prettier": "^2.8.3", + "prettier": "^3.0.3", "pretty-quick": "^3.1.3", "ts-node": "^10.9.1", - "typescript": "^5.1.6" + "typescript": "^5.2.2" }, "dependencies": { "@derockdev/discord-components-core": "^3.6.1", @@ -55,9 +55,9 @@ "react-dom": "^18.2.0", "simple-markdown": "^0.7.3", "twemoji": "^14.0.2", - "undici": "^5.24.0" + "undici": "^5.26.3" }, "peerDependencies": { - "discord.js": "^14.0.0 || ^15.0.0" + "discord.js": "^14.13.0" } } diff --git a/src/index.ts b/src/index.ts index 9efb1f5..4a37f91 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,10 +81,11 @@ export async function generateFromMessages( channel: TextBasedChannel, options: CreateTranscriptOptions = {} -): Promise> { +): Promise | ObjectType[]> { // validate type if (!channel.isTextBased()) { // @ts-expect-error(2339): run-time check @@ -121,7 +122,22 @@ export async function createTranscript(allMessages.reverse(), channel, options); + if (!options.limitPerFile) { + return generateFromMessages(allMessages.reverse(), channel, options); + } else { + // split the messages into groups + const transcripts = []; + for (let i = 0; i < allMessages.length; i += options.limitPerFile) { + options.filename = `${options.filename ?? `transcript-${channel.id}`}_part.${i + 1}`; + + const allMessageGroups = allMessages.slice(i, i + options.limitPerFile); + const transcript = await generateFromMessages(allMessageGroups, channel, options); + + transcripts.push(transcript as ObjectType); + } + + return transcripts; + } } export default { diff --git a/src/types.ts b/src/types.ts index f97516c..1c396bb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -72,5 +72,11 @@ export type CreateTranscriptOptions = Partial< * The max amount of messages to fetch. Use `-1` to recursively fetch. */ limit: number; + + /** + * The max number of messages per file. If not defined or null, all messages will be in one file. + * @default null + */ + limitPerFile?: number | null; } >;