New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

discord.js-prompts

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord.js-prompts - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

2

build/DiscordChannel.d.ts

@@ -16,3 +16,3 @@ import { ChannelInterface } from "prompt-anything";

*/
storeMessage(message: Message): void;
storeMessages(message: Message | Message[]): void;
sendMenuVisual(visual: MenuVisual): Promise<Message>;

@@ -19,0 +19,0 @@ sendMessageVisual(visual: MessageVisual): Promise<Message | Message[]>;

@@ -25,4 +25,9 @@ "use strict";

*/
storeMessage(message) {
this.messages.push(message);
storeMessages(message) {
if (Array.isArray(message)) {
message.forEach(m => this.messages.push(m));
}
else {
this.messages.push(message);
}
}

@@ -53,3 +58,3 @@ sendMenuVisual(visual) {

const sent = yield this.sendMenuVisual(visual);
this.storeMessage(sent);
this.storeMessages(sent);
return sent;

@@ -59,8 +64,3 @@ }

const sent = yield this.sendMessageVisual(visual);
if (Array.isArray(sent)) {
sent.forEach(m => this.storeMessage(m));
}
else {
this.storeMessage(sent);
}
this.storeMessages(sent);
return sent;

@@ -67,0 +67,0 @@ }

@@ -31,3 +31,3 @@ "use strict";

static createMenuRejection(message, data, menu) {
return new prompt_anything_1.Rejection('That is an invalid option. Try again.');
return new prompt_anything_1.Rejection('That is not a valid selection. Try again.');
}

@@ -53,3 +53,3 @@ // Override event

*/
channel.storeMessage(message);
channel.storeMessages(message);
this.handleMessage(message, data, emitter);

@@ -56,0 +56,0 @@ }));

@@ -45,2 +45,14 @@ import { Message, MessageEmbed } from 'discord.js';

/**
* Get array of numbers of a range, separated by "-"
*
* @param string
*/
static getMultiSelectOptionRange(string: string): number[];
/**
* Get comma-separated values for multi-select.
*
* @param string Input string
*/
static getMultiSelectOptions(string: string): number[];
/**
* Enable pagination by defining an error handler for

@@ -47,0 +59,0 @@ * when the menu fails to set up pages (when message

@@ -39,2 +39,30 @@ "use strict";

/**
* Get array of numbers of a range, separated by "-"
*
* @param string
*/
static getMultiSelectOptionRange(string) {
const split = string.split('-');
const start = Number(split[0]);
const end = Number(split[split.length - 1]);
if (isNaN(start) || isNaN(end)) {
return [];
}
const numbers = [];
for (let i = start; i <= end; ++i) {
numbers.push(i);
}
return numbers;
}
/**
* Get comma-separated values for multi-select.
*
* @param string Input string
*/
static getMultiSelectOptions(string) {
const values = string.split(',').map(s => s.trim());
const ranges = values.map(v => this.getMultiSelectOptionRange(v)).flat(1);
return ranges.filter((val, index) => ranges.indexOf(val) === index);
}
/**
* Enable pagination by defining an error handler for

@@ -108,3 +136,3 @@ * when the menu fails to set up pages (when message

else {
const numbers = content.split(',').map(val => Number(val));
const numbers = MenuEmbed.getMultiSelectOptions(content);
return numbers.every(val => this.isValidOption(val));

@@ -111,0 +139,0 @@ }

@@ -47,3 +47,3 @@ "use strict";

},
storeMessage: jest.fn()
storeMessages: jest.fn()
};

@@ -114,5 +114,5 @@ beforeEach(() => {

yield flushPromises();
expect(emit).toHaveBeenCalledWith('reject', message, new prompt_anything_1.Rejection('That is an invalid option. Try again.'));
expect(emit).toHaveBeenCalledWith('reject', message, new prompt_anything_1.Rejection('That is not a valid selection. Try again.'));
}));
});
});

@@ -32,2 +32,21 @@ "use strict";

});
it('works with ranges', () => {
const menu = new MenuEmbed_1.MenuEmbed(undefined, {
multiSelect: true
});
menu
.addOption('a')
.addOption('b')
.addOption('c')
.addOption('d')
.addOption('e');
expect(menu.isValidSelection('1,2-4'))
.toEqual(true);
expect(menu.isValidSelection('2-4,1'))
.toEqual(true);
expect(menu.isValidSelection('2-9, 1'))
.toEqual(false);
expect(menu.isValidSelection('2-4, 9'))
.toEqual(false);
});
});

@@ -34,0 +53,0 @@ describe('spansMultiplePages', () => {

@@ -171,8 +171,24 @@ "use strict";

.mockResolvedValue(createdMessage);
const storeMessage = jest.spyOn(discordChannel, 'storeMessage')
const storeMessages = jest.spyOn(discordChannel, 'storeMessages')
.mockImplementation();
// Send
yield discordChannel.send(visual);
expect(storeMessage).toHaveBeenCalledWith(createdMessage);
expect(storeMessages).toHaveBeenCalledWith(createdMessage);
}));
it('saves each message if an array of messages is sent', () => __awaiter(void 0, void 0, void 0, function* () {
const visual = new MessageVisual_1.MessageVisual('aedsgrf');
const discordChannel = new DiscordChannel_1.DiscordChannel({});
const createdMessages = [{
content: 'a'
}, {
content: 'b'
}];
jest.spyOn(discordChannel, 'sendMessageVisual')
.mockResolvedValue(createdMessages);
const storeMessages = jest.spyOn(discordChannel, 'storeMessages')
.mockImplementation();
// Send
yield discordChannel.send(visual);
expect(storeMessages).toHaveBeenCalledWith(createdMessages);
}));
it('saves the message for sendMenuVisual', () => __awaiter(void 0, void 0, void 0, function* () {

@@ -188,9 +204,9 @@ const visual = new MenuVisual_1.MenuVisual(new MenuEmbed_1.MenuEmbed());

.mockResolvedValue(createdMessage);
const storeMessage = jest.spyOn(discordChannel, 'storeMessage')
const storeMessages = jest.spyOn(discordChannel, 'storeMessages')
.mockImplementation();
// Send
yield discordChannel.send(visual);
expect(storeMessage).toHaveBeenCalledWith(createdMessage);
expect(storeMessages).toHaveBeenCalledWith(createdMessage);
}));
});
});

@@ -54,3 +54,3 @@ "use strict";

},
storeMessage: jest.fn()
storeMessages: jest.fn()
};

@@ -97,3 +97,3 @@ beforeEach(() => {

createdCollector.emit('collect', message);
expect(discordChannel.storeMessage)
expect(discordChannel.storeMessages)
.toHaveBeenCalledWith(message);

@@ -100,0 +100,0 @@ });

@@ -77,2 +77,51 @@ "use strict";

});
describe('static getMultiSelectOptionRange', () => {
it('returns correctly', () => {
const str = '1-4';
expect(MenuEmbed_1.MenuEmbed.getMultiSelectOptionRange(str))
.toEqual([1, 2, 3, 4]);
});
it('returns an empty array if invalid start or end', () => {
const str = 'a-4';
expect(MenuEmbed_1.MenuEmbed.getMultiSelectOptionRange(str))
.toEqual([]);
const str2 = '1-b';
expect(MenuEmbed_1.MenuEmbed.getMultiSelectOptionRange(str2))
.toEqual([]);
});
});
describe('static getMultiSelectOptions', () => {
beforeEach(() => {
jest.spyOn(MenuEmbed_1.MenuEmbed, 'getMultiSelectOptionRange')
.mockReturnValue([]);
});
it('returns correctly', () => {
const str = '1,2-3,4,6-8,10';
jest.spyOn(MenuEmbed_1.MenuEmbed, 'getMultiSelectOptionRange')
.mockReturnValueOnce([1])
.mockReturnValueOnce([2, 3])
.mockReturnValueOnce([4])
.mockReturnValueOnce([6, 7, 8])
.mockReturnValueOnce([10]);
expect(MenuEmbed_1.MenuEmbed.getMultiSelectOptions(str))
.toEqual([1, 2, 3, 4, 6, 7, 8, 10]);
});
it('removes duplicates', () => {
const str = '1-4,3-5';
jest.spyOn(MenuEmbed_1.MenuEmbed, 'getMultiSelectOptionRange')
.mockReturnValueOnce([1, 2, 3, 4])
.mockReturnValueOnce([3, 4, 5]);
expect(MenuEmbed_1.MenuEmbed.getMultiSelectOptions(str))
.toEqual([1, 2, 3, 4, 5]);
});
it('works with spaces', () => {
const str = '1, 2-4, 5';
jest.spyOn(MenuEmbed_1.MenuEmbed, 'getMultiSelectOptionRange')
.mockReturnValueOnce([1])
.mockReturnValueOnce([2, 3, 4])
.mockReturnValueOnce([5]);
expect(MenuEmbed_1.MenuEmbed.getMultiSelectOptions(str))
.toEqual([1, 2, 3, 4, 5]);
});
});
describe('enablePagination', () => {

@@ -79,0 +128,0 @@ it('defines the error handler', () => {

{
"name": "discord.js-prompts",
"version": "2.0.2",
"version": "2.1.0",
"description": "Create prompts in Discord, just like you would in console!",

@@ -5,0 +5,0 @@ "main": "build/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc