-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed !sounds when having a lot of sounds
- Loading branch information
1 parent
863fd08
commit 073ad9e
Showing
3 changed files
with
60 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export default class MessageChunker { | ||
private readonly MAX_MESSAGE_LENGTH = 2000; | ||
private readonly CODE_MARKER_LENGTH = '```'.length * 2; | ||
|
||
public chunkedMessages(toChunk: Array<string>, params: Array<string>): Array<string> { | ||
const chunks = this.chunkArray(toChunk); | ||
|
||
const indexInput = parseInt(params[0]); | ||
const realIndex = indexInput - 1; | ||
|
||
if (indexInput && realIndex >= 0 && realIndex < chunks.length) { | ||
return [ | ||
`\`\`\`Page ${indexInput} of ${chunks.length}\`\`\``, | ||
['```', ...chunks[realIndex], '```'].join('\n') | ||
]; | ||
} | ||
|
||
return chunks.map(chunk => ['```', ...chunk, '```'].join('\n')); | ||
} | ||
|
||
private chunkArray(input: Array<string>): Array<Array<string>> { | ||
const chunkedInput: Array<Array<string>> = []; | ||
|
||
let total = 0; | ||
let temp: Array<string> = []; | ||
for (const element of input) { | ||
if (total + element.length > this.MAX_MESSAGE_LENGTH - this.CODE_MARKER_LENGTH) { | ||
chunkedInput.push(temp); | ||
temp = [element]; | ||
continue; | ||
} | ||
|
||
total += element.length; | ||
temp.push(element); | ||
} | ||
|
||
chunkedInput.push(temp); | ||
return chunkedInput; | ||
} | ||
} |