Skip to content

Commit 3b9a16c

Browse files
committed
Removed unnecessary constants
- Removed remindmeMaxTimeStringLength, documentation is added right below the only usage - Removed licenseInfoCooldown, the number is now already calculated (1000 x 60 x 30 = 1800000) and documentation is added right below the only usage - Removed maxSafeMessageLength as there is no easy way to guarantee that message markdown characters won't be split into different messages. Default (1950) is used instead. - Bumped version to v2.3.0-beta.5 - Added missing command variations into README.md
1 parent 8267754 commit 3b9a16c

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The prefix is `/`.
1818
* `(source|github|repo|repository)` : Get information about ChillBot's source code repository.
1919
* `stop` : Stop the bot. This command is only available for developers of ChillBot.
2020
* `restart` : Restart the bot in a new instance of Node.js. This command is only available for developers of ChillBot.
21-
* `(osslicenses|opensourcelicenses)` : Get licenses information and notices about ChillBot's dependencies, used tools and JavaScript runtime.
21+
* `(osslicenses|osslicences|opensourcelicenses|opensourcelicences)` : Get licenses information and notices about ChillBot's dependencies, used tools and JavaScript runtime.
2222
* `(changes|changelog|changelogs) [tagName]` : Get changelog for the latest release. If "tagName" is present and corresponds to a release, get the changelog for the specific release.
2323
* `invite` : Get the link to invite ChillBot to a server.
2424

index.js

+12-16
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,12 @@ const token = getConfiguration("token");
8282
const developmentEnvironment = getConfiguration("developmentEnvironment");
8383
const cliProcessTimeout = getConfiguration("cliProcessTimeout");
8484
const inviteURL = getConfiguration("inviteURL");
85-
const remindmeMaxTimeStringLength = 100;
86-
// 100 is the limit for ms library, see https://github.com/zeit/ms/blob/2.1.1/index.js#L50
87-
const licenseInfoCooldown = 1000 * 60 * 30;
8885

8986
const reminderTimerList = [];
9087
const licenseInfoSentGuildList = new Map();
91-
const maxSafeMessageLength = 2000 - ("_***__~~```".length * 2);
9288
const sendOptionsForLongMessage = {
9389
split: {
94-
char: " ",
95-
maxLength: maxSafeMessageLength
90+
char: " "
9691
}
9792
};
9893

@@ -252,7 +247,8 @@ client.on("ready", () => {
252247
let timeout;
253248
if (args.length === 1) {
254249
messageToSend = `Please provide a time in seconds, minutes, hours, days or months! Example: ${code("/remindme 3d Do homework")}`;
255-
} else if (args[1].length > remindmeMaxTimeStringLength) {
250+
} else if (args[1].length > 100) {
251+
// 100 is the limit for ms library, see https://github.com/zeit/ms/blob/2.1.1/index.js#L50
256252
messageToSend = "The string of time you specified is too long!";
257253
} else {
258254
timeout = ms(args[1]);
@@ -418,7 +414,11 @@ client.on("ready", () => {
418414
clearTimeout(licenseInfoSentGuildList.get(firstItemKey)[1]);
419415
licenseInfoSentGuildList.delete(firstItemKey);
420416
}
421-
licenseInfoSentGuildList.set(guildID, [message.url, setTimeout(() => licenseInfoSentGuildList.delete(guildID), licenseInfoCooldown)]);
417+
licenseInfoSentGuildList.set(guildID, [message.url, setTimeout(() => licenseInfoSentGuildList.delete(guildID), 1800000)]);
418+
// 1800000 = 1000 * 60 * 30, the timeout is 30 minutes
419+
const maxLength = 1950;
420+
// 1950 is the default maximum character length per message piece,
421+
// see https://discord.js.org/#/docs/main/stable/typedef/SplitOptions
422422
for (const library of await libraryList) {
423423
const libraryName = library.name
424424
const libraryVersion = library.version;
@@ -436,11 +436,11 @@ client.on("ready", () => {
436436
return;
437437
}
438438
messageToSend = libraryLicense;
439-
while (messageToSend.length > maxSafeMessageLength) {
440-
let partialMessage = messageToSend.substring(0, maxSafeMessageLength);
439+
while (messageToSend.length > maxLength) {
440+
let partialMessage = messageToSend.substring(0, maxLength);
441441
const splitableIndex = partialMessage.lastIndexOf("\n");
442442
if (splitableIndex === -1) {
443-
messageToSend = messageToSend.substring(maxSafeMessageLength);
443+
messageToSend = messageToSend.substring(maxLength);
444444
} else {
445445
partialMessage = messageToSend.substring(0, splitableIndex);
446446
messageToSend = messageToSend.substring(splitableIndex + 1);
@@ -530,11 +530,7 @@ client.on("ready", () => {
530530
const parsedTagName = parsed.tag_name;
531531
const displayTagName = tagName === undefined ? (parsedTagName === undefined ? "latest": parsedTagName) : tagName;
532532
messageToSend = `${bold(displayName)}\nRelease: ${displayTagName}\nChanges:\n${description}`;
533-
channel.send(messageToSend, {
534-
split: {
535-
maxLength: maxSafeMessageLength
536-
}
537-
}).catch(error => console.error(`An error occured while sending message "${messageToSend}"!\n\nFull details:\n${error}`));
533+
channel.send(messageToSend).catch(error => console.error(`An error occured while sending message "${messageToSend}"!\n\nFull details:\n${error}`));
538534
} catch (error) {
539535
console.error("Unable to get changelog, received data is not valid JSON!");
540536
channel.send(errorFetchingChangelogString)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chillbot",
3-
"version": "2.3.0-beta.4",
3+
"version": "2.3.0-beta.5",
44
"description": "Chill!",
55
"keywords": [
66
"discord",

0 commit comments

Comments
 (0)