Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add max number of messages per file
Browse files Browse the repository at this point in the history
SunkwiBOT committed Oct 13, 2023
1 parent 014c646 commit 2d70f93
Showing 3 changed files with 35 additions and 13 deletions.
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
20 changes: 18 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -81,10 +81,11 @@ export async function generateFromMessages<T extends ExportReturnType = ExportRe
* @param options The options to use when creating the transcript
* @returns The generated transcript
*/

export async function createTranscript<T extends ExportReturnType = ExportReturnType.Attachment>(
channel: TextBasedChannel,
options: CreateTranscriptOptions<T> = {}
): Promise<ObjectType<T>> {
): Promise<ObjectType<T> | ObjectType<T>[]> {
// validate type
if (!channel.isTextBased()) {
// @ts-expect-error(2339): run-time check
@@ -121,7 +122,22 @@ export async function createTranscript<T extends ExportReturnType = ExportReturn
if (resolvedLimit < allMessages.length) allMessages = allMessages.slice(0, limit);

// generate the transcript
return generateFromMessages<T>(allMessages.reverse(), channel, options);
if (!options.limitPerFile) {
return generateFromMessages<T>(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<T>(allMessageGroups, channel, options);

transcripts.push(transcript as ObjectType<T>);
}

return transcripts;
}
}

export default {
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -72,5 +72,11 @@ export type CreateTranscriptOptions<T extends ExportReturnType> = 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;
}
>;

0 comments on commit 2d70f93

Please sign in to comment.