discord.js-prompts
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -13,9 +13,5 @@ /// <reference types="node" /> | ||
duration: number; | ||
static getInactivityVisual<DataType>(channel?: DiscordChannel, data?: DataType): Promise<MessageVisual>; | ||
static getExitVisual<DataType>(message?: Message, channel?: DiscordChannel, data?: DataType): Promise<MessageVisual>; | ||
static getRejectVisual<DataType>(error: Rejection, message?: Message, channel?: DiscordChannel, data?: DataType): Promise<MessageVisual>; | ||
static createMenuRejection<DataType>(message?: Message, data?: DataType, menu?: MenuEmbed): Rejection; | ||
onReject(error: Rejection, message: Message, channel: DiscordChannel, data: DataType): Promise<void>; | ||
onInactivity(channel: DiscordChannel, data: DataType): Promise<void>; | ||
onExit(message: Message, channel: DiscordChannel, data: DataType): Promise<void>; | ||
createEmitter(): EventEmitter; | ||
@@ -22,0 +18,0 @@ createCollector(channel: DiscordChannel, data: DataType & BaseData): PromptCollector<DataType, Message>; |
@@ -23,14 +23,2 @@ "use strict"; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
static getInactivityVisual(channel, data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return new MessageVisual_1.MessageVisual('Menu closed due to inactivity.'); | ||
}); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
static getExitVisual(message, channel, data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return new MessageVisual_1.MessageVisual('Menu closed.'); | ||
}); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
static getRejectVisual(error, message, channel, data) { | ||
@@ -45,3 +33,3 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
// Override events | ||
// Override event | ||
onReject(error, message, channel, data) { | ||
@@ -53,14 +41,2 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
onInactivity(channel, data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const visual = yield this.constructor.getInactivityVisual(channel, data); | ||
yield this.sendVisual(visual, channel); | ||
}); | ||
} | ||
onExit(message, channel, data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const visual = yield this.constructor.getExitVisual(message, channel, data); | ||
yield this.sendVisual(visual, channel); | ||
}); | ||
} | ||
createEmitter() { | ||
@@ -91,3 +67,3 @@ return new events_1.EventEmitter(); | ||
if (message.content === 'exit') { | ||
emitter.emit('exit', message); | ||
emitter.emit('exit'); | ||
return; | ||
@@ -94,0 +70,0 @@ } |
@@ -75,3 +75,3 @@ "use strict"; | ||
createdCollector.emit('collect', message); | ||
expect(emit).toHaveBeenCalledWith('exit', message); | ||
expect(emit).toHaveBeenCalledWith('exit'); | ||
}); | ||
@@ -78,0 +78,0 @@ it('emits a message when valid input for menu', () => __awaiter(void 0, void 0, void 0, function* () { |
@@ -109,3 +109,3 @@ "use strict"; | ||
})); | ||
it(`exits when message is exit`, () => __awaiter(void 0, void 0, void 0, function* () { | ||
it(`rejects when message is exit`, () => __awaiter(void 0, void 0, void 0, function* () { | ||
const askNameFn = (m, data) => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -118,3 +118,3 @@ return Object.assign(Object.assign({}, data), { name: m.content }); | ||
const runner = new DiscordPromptRunner_1.DiscordPromptRunner(author, {}); | ||
runner.run(askNameNode, textChannel); | ||
const run = runner.run(askNameNode, textChannel); | ||
// Wait for all pending promise callbacks to be executed for the emitter to set up | ||
@@ -124,4 +124,4 @@ yield flushPromises(); | ||
collector.emit('tryCollect', exitMessage); | ||
yield flushPromises(); | ||
expect(emit).toHaveBeenCalledWith('exit', exitMessage); | ||
yield expect(run).rejects.toThrow(prompt_anything_1.Errors.UserVoluntaryExitError); | ||
expect(emit).toHaveBeenCalledWith('exit'); | ||
expect(collectorStop).toHaveBeenCalled(); | ||
@@ -209,4 +209,4 @@ })); | ||
reactCollector.removeAllListeners(); | ||
emitter.emit('exit', createMockMessage(authorID)); | ||
emitter.emit('exit'); | ||
})); | ||
}); |
@@ -35,14 +35,2 @@ "use strict"; | ||
}); | ||
describe('static getInactivityVisual', () => { | ||
it('returns correctly', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = yield DiscordPrompt_1.DiscordPrompt.getInactivityVisual(); | ||
expect(result).toBeInstanceOf(MessageVisual_1.MessageVisual); | ||
})); | ||
}); | ||
describe('static getExitVisual', () => { | ||
it('returns correctly', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const result = yield DiscordPrompt_1.DiscordPrompt.getExitVisual(); | ||
expect(result).toBeInstanceOf(MessageVisual_1.MessageVisual); | ||
})); | ||
}); | ||
describe('static getRejectVisual', () => { | ||
@@ -122,3 +110,3 @@ it('returns correctly', () => __awaiter(void 0, void 0, void 0, function* () { | ||
yield prompt.handleMessage(message, {}, emitter); | ||
expect(emitter.emit).toHaveBeenCalledWith('exit', message); | ||
expect(emitter.emit).toHaveBeenCalledWith('exit'); | ||
})); | ||
@@ -220,45 +208,2 @@ it('emits message if visual is not a menu', () => __awaiter(void 0, void 0, void 0, function* () { | ||
}); | ||
describe('onInactivity', () => { | ||
beforeEach(() => { | ||
jest.spyOn(prompt, 'sendVisual').mockResolvedValue({}); | ||
}); | ||
it('sends the inactivity visual', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const sendVisual = jest.spyOn(prompt, 'sendVisual'); | ||
const channel = { | ||
foo: 'ade' | ||
}; | ||
const data = { | ||
dfg: 'dfrhgb' | ||
}; | ||
const inactivityiVisual = new MessageVisual_1.MessageVisual('srfg'); | ||
const getInactivityVisual = jest.spyOn(DiscordPrompt_1.DiscordPrompt, 'getInactivityVisual') | ||
.mockResolvedValue(inactivityiVisual); | ||
yield prompt.onInactivity(channel, data); | ||
expect(sendVisual).toHaveBeenCalledWith(inactivityiVisual, channel); | ||
expect(getInactivityVisual).toHaveBeenCalledWith(channel, data); | ||
})); | ||
}); | ||
describe('onExit', () => { | ||
beforeEach(() => { | ||
jest.spyOn(prompt, 'sendVisual').mockResolvedValue({}); | ||
}); | ||
it('sends the exit visual', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const sendVisual = jest.spyOn(prompt, 'sendVisual'); | ||
const message = { | ||
dhr: 'sedg' | ||
}; | ||
const channel = { | ||
foo: 'ade' | ||
}; | ||
const data = { | ||
baz: 'ho' | ||
}; | ||
const exitVisual = new MessageVisual_1.MessageVisual('srfg'); | ||
const getExitVisual = jest.spyOn(DiscordPrompt_1.DiscordPrompt, 'getExitVisual') | ||
.mockResolvedValue(exitVisual); | ||
yield prompt.onExit(message, channel, data); | ||
expect(sendVisual).toHaveBeenCalledWith(exitVisual, channel); | ||
expect(getExitVisual).toHaveBeenCalledWith(message, channel, data); | ||
})); | ||
}); | ||
}); |
{ | ||
"name": "discord.js-prompts", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Create prompts in Discord, just like you would in console!", | ||
@@ -26,3 +26,3 @@ "main": "build/index.js", | ||
"discord.js": "^12.2.0", | ||
"prompt-anything": "^1.4.1" | ||
"prompt-anything": "^2.0.0" | ||
}, | ||
@@ -29,0 +29,0 @@ "devDependencies": { |
107697
2490
+ Addedprompt-anything@2.0.1(transitive)
- Removedprompt-anything@1.4.2(transitive)
Updatedprompt-anything@^2.0.0