Skip to content

Commit bd59759

Browse files
committed
Fixed "/changelog" not accepting execution without argument
- Fixed a bug where trying to execute "/changelog" command without tag name argument will fail - Disallow giving items to oneself - Changed unnecessary use of raw string literal (`Please mention someone!`) for "/give" error message
1 parent dfb5e92 commit bd59759

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

index.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,9 @@ client.on("ready", () => {
321321
} else {
322322
target = getFirstMentionedUser(message);
323323
if (target === undefined) {
324-
messageToSend = `Please mention someone!`;
324+
messageToSend = "Please mention someone!";
325+
} else if (target.user.equals(author)) {
326+
messageToSend = "You can't give items to yourself!";
325327
} else if (!(args[1] === createMentionForUser(target.user) || args[1] === createMentionForUser(target.user, true))) {
326328
messageToSend = "The syntax is /give <mention> <amount> <item>!";
327329
} else if (args.length === 2) {
@@ -461,14 +463,17 @@ client.on("ready", () => {
461463
}
462464
let messageToSend;
463465
let tagName;
464-
if (!/^v?((0|([1-9]\d*))\.){2}(0|([1-9]\d*))(\-((alpha)|(beta)|(rc))([1-9]\d*))?$/gi.test(args[1])) {
465-
messageToSend = "Tag name must be in a format of \"a.b.c\" or \"va.b.c\" (where a, b, c are numbers) with optional suffix for alpha, beta and rc releases, without any leading 0s!";
466-
return message.reply(messageToSend)
467-
.catch(error => console.error(`An error occured while replying "${messageToSend}" to message!\n\nFull details:\n${error.toString()}`));
468-
}
469-
tagName = args[1].toLowerCase();
470-
if (!tagName.startsWith("v")) {
471-
tagName = `v${tagName}`;
466+
if (args.length > 1) {
467+
if (/^v?((0|([1-9]\d*))\.){2}(0|([1-9]\d*))(\-((alpha)|(beta)|(rc))([1-9]\d*))?$/gi.test(args[1])) {
468+
tagName = args[1].toLowerCase();
469+
if (!tagName.startsWith("v")) {
470+
tagName = `v${tagName}`;
471+
}
472+
} else {
473+
messageToSend = "Tag name must be in a format of \"a.b.c\" or \"va.b.c\" (where a, b, c are numbers) with optional suffix for alpha, beta and rc releases, without any leading 0s!";
474+
return message.reply(messageToSend)
475+
.catch(error => console.error(`An error occured while replying "${messageToSend}" to message!\n\nFull details:\n${error.toString()}`));
476+
}
472477
}
473478
messageToSend = "Fetching changelog...";
474479
await channel.send(messageToSend)

0 commit comments

Comments
 (0)