parent
897d064699
commit
573ed8d162
@ -1,4 +1,5 @@ |
||||
node_modules/ |
||||
config.json |
||||
auth.json |
||||
test.js |
||||
test.js |
||||
/.idea/ |
@ -1 +0,0 @@ |
||||
guild.js |
@ -1,13 +1,13 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<module type="WEB_MODULE" version="4"> |
||||
<component name="NewModuleRootManager"> |
||||
<content url="file://$MODULE_DIR$"> |
||||
<excludeFolder url="file://$MODULE_DIR$/.tmp" /> |
||||
<excludeFolder url="file://$MODULE_DIR$/temp" /> |
||||
<excludeFolder url="file://$MODULE_DIR$/tmp" /> |
||||
</content> |
||||
<orderEntry type="inheritedJdk" /> |
||||
<orderEntry type="sourceFolder" forTests="false" /> |
||||
<orderEntry type="module" module-name="death" /> |
||||
</component> |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<module type="WEB_MODULE" version="4"> |
||||
<component name="NewModuleRootManager"> |
||||
<content url="file://$MODULE_DIR$"> |
||||
<excludeFolder url="file://$MODULE_DIR$/temp" /> |
||||
<excludeFolder url="file://$MODULE_DIR$/.tmp" /> |
||||
<excludeFolder url="file://$MODULE_DIR$/tmp" /> |
||||
</content> |
||||
<orderEntry type="inheritedJdk" /> |
||||
<orderEntry type="sourceFolder" forTests="false" /> |
||||
<orderEntry type="module" module-name="Natsukiv13" /> |
||||
</component> |
||||
</module> |
@ -1,6 +1,7 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="DiscordProjectSettings"> |
||||
<option name="show" value="PROJECT_FILES" /> |
||||
<option name="show" value="ASK" /> |
||||
<option name="description" value="" /> |
||||
</component> |
||||
</project> |
@ -1,6 +0,0 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="JavaScriptLibraryMappings"> |
||||
<includedPredefinedLibrary name="Node.js Core" /> |
||||
</component> |
||||
</project> |
@ -1,9 +1,9 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="ProjectModuleManager"> |
||||
<modules> |
||||
<module fileurl="file://$PROJECT_DIR$/.idea/Natsuki.iml" filepath="$PROJECT_DIR$/.idea/Natsuki.iml" /> |
||||
<module fileurl="file://$USER_HOME$/WebstormProjects/death/.idea/death.iml" filepath="$USER_HOME$/WebstormProjects/death/.idea/death.iml" /> |
||||
</modules> |
||||
</component> |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project version="4"> |
||||
<component name="ProjectModuleManager"> |
||||
<modules> |
||||
<module fileurl="file://$PROJECT_DIR$/.idea/Natsuki.iml" filepath="$PROJECT_DIR$/.idea/Natsuki.iml" /> |
||||
<module fileurl="file://$PROJECT_DIR$/../Natsukiv13/.idea/Natsukiv13.iml" filepath="$PROJECT_DIR$/../Natsukiv13/.idea/Natsukiv13.iml" /> |
||||
</modules> |
||||
</component> |
||||
</project> |
File diff suppressed because it is too large
Load Diff
@ -1,36 +1,36 @@ |
||||
import { TextChannel, Message, MessageEmbed, Client, ReactionCollector } from 'discord.js'; |
||||
export declare class Pagination { |
||||
channel: TextChannel; |
||||
message: Message; |
||||
pages: MessageEmbed[]; |
||||
originalMessage: Message; |
||||
currentPage: number; |
||||
client: Client; |
||||
loopPages: boolean; |
||||
controllers: ControllerData; |
||||
timeoutInterval: any; |
||||
constructor(channel: TextChannel, pages: MessageEmbed[], originalMessage: Message, client: Client, loopPages?: boolean, message?: Message); |
||||
setPage(page: number): Promise<Pagination>; |
||||
nextPage(): Promise<Pagination>; |
||||
prevPage(): Promise<Pagination>; |
||||
addPage(page: MessageEmbed): Pagination; |
||||
replacePage(index: number, page: MessageEmbed): Pagination; |
||||
setControllers(endTime: number, user?: 'any' | string, extraControls?: ExtraControls): Promise<Pagination>; |
||||
updateControllers(): Promise<Pagination>; |
||||
endControllers(): Promise<Pagination>; |
||||
start(options?: { |
||||
endTime?: number; |
||||
startPage?: number; |
||||
user?: 'any' | string; |
||||
}): Promise<Pagination>; |
||||
stop(): Promise<Pagination>; |
||||
} |
||||
interface ExtraControls { |
||||
} |
||||
interface ControllerData { |
||||
endTime: number; |
||||
enabled: boolean; |
||||
lastInteraction: Date; |
||||
collector: ReactionCollector; |
||||
} |
||||
export {}; |
||||
import { TextChannel, Message, MessageEmbed, Client, ReactionCollector } from 'discord.js'; |
||||
export declare class Pagination { |
||||
channel: TextChannel; |
||||
message: Message; |
||||
pages: MessageEmbed[]; |
||||
originalMessage: Message; |
||||
currentPage: number; |
||||
client: Client; |
||||
loopPages: boolean; |
||||
controllers: ControllerData; |
||||
timeoutInterval: any; |
||||
constructor(channel: TextChannel, pages: MessageEmbed[], originalMessage: Message, client: Client, loopPages?: boolean, message?: Message); |
||||
setPage(page: number): Promise<Pagination>; |
||||
nextPage(): Promise<Pagination>; |
||||
prevPage(): Promise<Pagination>; |
||||
addPage(page: MessageEmbed): Pagination; |
||||
replacePage(index: number, page: MessageEmbed): Pagination; |
||||
setControllers(endTime: number, user?: 'any' | string, extraControls?: ExtraControls): Promise<Pagination>; |
||||
updateControllers(): Promise<Pagination>; |
||||
endControllers(): Promise<Pagination>; |
||||
start(options?: { |
||||
endTime?: number; |
||||
startPage?: number; |
||||
user?: 'any' | string; |
||||
}): Promise<Pagination>; |
||||
stop(): Promise<Pagination>; |
||||
} |
||||
interface ExtraControls { |
||||
} |
||||
interface ControllerData { |
||||
endTime: number; |
||||
enabled: boolean; |
||||
lastInteraction: Date; |
||||
collector: ReactionCollector; |
||||
} |
||||
export {}; |
||||
|
@ -1,134 +1,135 @@ |
||||
"use strict"; |
||||
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
exports.Pagination = void 0; |
||||
class Pagination { |
||||
constructor(channel, pages, originalMessage, client, loopPages, message) { |
||||
this.loopPages = true; |
||||
this.controllers = { enabled: false, endTime: null, collector: null, lastInteraction: null }; |
||||
this.channel = channel; |
||||
this.pages = pages; |
||||
this.originalMessage = message; |
||||
this.client = client; |
||||
this.currentPage = 0; |
||||
if (message) { |
||||
this.message = message; |
||||
} |
||||
if (loopPages) { |
||||
this.loopPages = loopPages; |
||||
} |
||||
} |
||||
; |
||||
async setPage(page) { |
||||
if (this.pages.length < page + 1) { } |
||||
if (!this.message) { |
||||
let tempm = await this.channel.send("One moment...") |
||||
.catch(() => { this.originalMessage.reply("There seemed to be a problem doing that..."); return this; }); |
||||
if (tempm instanceof Pagination) { |
||||
return this; |
||||
} |
||||
else { |
||||
this.message = tempm; |
||||
} |
||||
} |
||||
await this.message.edit('', this.pages[page] |
||||
.setFooter(`Natsuki | Page ${page + 1} of ${this.pages.length}`, this.client.user.avatarURL()) |
||||
.setTimestamp()); |
||||
this.currentPage = page; |
||||
return this; |
||||
} |
||||
; |
||||
async nextPage() { |
||||
await this.setPage(typeof this.currentPage === "number" |
||||
? this.currentPage + 1 == this.pages.length |
||||
? this.loopPages |
||||
? 0 |
||||
: this.currentPage |
||||
: this.currentPage + 1 |
||||
: 0); |
||||
return this; |
||||
} |
||||
; |
||||
async prevPage() { |
||||
await this.setPage(typeof this.currentPage === "number" |
||||
? this.currentPage === 0 |
||||
? this.loopPages |
||||
? this.pages.length - 1 |
||||
: 0 |
||||
: this.currentPage - 1 |
||||
: this.pages.length - 1); |
||||
return this; |
||||
} |
||||
; |
||||
addPage(page) { |
||||
this.pages.push(page); |
||||
return this; |
||||
} |
||||
; |
||||
replacePage(index, page) { |
||||
if (index < 0) { |
||||
throw new RangeError("replacePage() param 'index' must be a value greater than 0"); |
||||
} |
||||
if (index > this.pages.length - 1) { |
||||
throw new RangeError("replacePage() param 'index' must be a value corresponding to an index that already exists in this instance's pages."); |
||||
} |
||||
this.pages[index] = page; |
||||
return this; |
||||
} |
||||
; |
||||
async setControllers(endTime, user, extraControls) { |
||||
if (this.controllers.enabled) { |
||||
return; |
||||
} |
||||
await this.message.react('⬅'); |
||||
await this.message.react('➡'); |
||||
await this.message.react('⏹'); |
||||
let emoji = ['⬅', '➡', '⏹']; |
||||
let filter = user && user.toLowerCase().trim() !== 'any' |
||||
? (r, u) => { return u.id === user.trim() && emoji.includes(r.emoji.name); } |
||||
: (r) => { return emoji.includes(r.emoji.name); }; |
||||
this.controllers.collector = this.message.createReactionCollector(filter, { time: 450000 }); |
||||
this.controllers.collector.on('collect', async (r) => { |
||||
let functions = { |
||||
'⬅': () => { return this.prevPage(); }, |
||||
'➡': () => { return this.nextPage(); }, |
||||
'⏹': () => { return this.endControllers(); } |
||||
}; |
||||
this.controllers.lastInteraction = new Date(); |
||||
return functions[r.emoji.name](); |
||||
}); |
||||
this.controllers.enabled = true; |
||||
this.controllers.endTime = endTime; |
||||
this.controllers.lastInteraction = new Date(); |
||||
this.timeoutInterval = setInterval(() => { |
||||
if (new Date().getTime() - this.controllers.lastInteraction.getTime() > this.controllers.endTime && this.controllers.enabled) { |
||||
return this.endControllers(); |
||||
} |
||||
}, this.controllers.endTime); |
||||
return this; |
||||
} |
||||
; |
||||
async updateControllers() { return this; } |
||||
; |
||||
async endControllers() { |
||||
await this.message.reactions.removeAll(); |
||||
this.controllers.collector.stop(); |
||||
let fe = this.message.embeds[0]; |
||||
fe.setDescription(`${fe.description}\n\n*This menu has ended, start a new one to interact with it!*`); |
||||
fe.setFooter(`${fe.footer.text} | Menu ended`, this.client.user.avatarURL()); |
||||
await this.message.edit(fe); |
||||
clearInterval(this.timeoutInterval); |
||||
return this; |
||||
} |
||||
; |
||||
async start(options) { |
||||
await this.setPage(options && options.startPage ? options.startPage : 0); |
||||
await this.setControllers(options && options.endTime ? options.endTime : 60, options && options.user ? options.user : 'any'); |
||||
return this; |
||||
} |
||||
; |
||||
async stop() { |
||||
return await this.endControllers(); |
||||
} |
||||
; |
||||
} |
||||
exports.Pagination = Pagination; |
||||
"use strict"; |
||||
Object.defineProperty(exports, "__esModule", { value: true }); |
||||
exports.Pagination = void 0; |
||||
class Pagination { |
||||
constructor(channel, pages, originalMessage, client, loopPages, message) { |
||||
this.loopPages = true; |
||||
this.controllers = { enabled: false, endTime: null, collector: null, lastInteraction: null }; |
||||
this.channel = channel; |
||||
this.pages = pages; |
||||
this.originalMessage = message; |
||||
this.client = client; |
||||
this.currentPage = 0; |
||||
if (message) { |
||||
this.message = message; |
||||
} |
||||
if (loopPages) { |
||||
this.loopPages = loopPages; |
||||
} |
||||
} |
||||
; |
||||
async setPage(page) { |
||||
if (this.pages.length < page + 1) { } |
||||
if (!this.message) { |
||||
let tempm = await this.channel.send("One moment...") |
||||
.catch(() => { this.originalMessage.reply("There seemed to be a problem doing that..."); return this; }); |
||||
if (tempm instanceof Pagination) { |
||||
return this; |
||||
} |
||||
else { |
||||
this.message = tempm; |
||||
} |
||||
} |
||||
await this.message.edit({ content: '', embeds: [this.pages[page] |
||||
.setFooter(`Natsuki | Page ${page + 1} of ${this.pages.length}`, this.client.user.avatarURL()) |
||||
.setTimestamp()] |
||||
}); |
||||
this.currentPage = page; |
||||
return this; |
||||
} |
||||
; |
||||
async nextPage() { |
||||
await this.setPage(typeof this.currentPage === "number" |
||||
? this.currentPage + 1 == this.pages.length |
||||
? this.loopPages |
||||
? 0 |
||||
: this.currentPage |
||||
: this.currentPage + 1 |
||||
: 0); |
||||
return this; |
||||
} |
||||
; |
||||
async prevPage() { |
||||
await this.setPage(typeof this.currentPage === "number" |
||||
? this.currentPage === 0 |
||||
? this.loopPages |
||||
? this.pages.length - 1 |
||||
: 0 |
||||
: this.currentPage - 1 |
||||
: this.pages.length - 1); |
||||
return this; |
||||
} |
||||
; |
||||
addPage(page) { |
||||
this.pages.push(page); |
||||
return this; |
||||
} |
||||
; |
||||
replacePage(index, page) { |
||||
if (index < 0) { |
||||
throw new RangeError("replacePage() param 'index' must be a value greater than 0"); |
||||
} |
||||
if (index > this.pages.length - 1) { |
||||
throw new RangeError("replacePage() param 'index' must be a value corresponding to an index that already exists in this instance's pages."); |
||||
} |
||||
this.pages[index] = page; |
||||
return this; |
||||
} |
||||
; |
||||
async setControllers(endTime, user, extraControls) { |
||||
if (this.controllers.enabled) { |
||||
return; |
||||
} |
||||
await this.message.react('⬅'); |
||||
await this.message.react('➡'); |
||||
await this.message.react('⏹'); |
||||
let emoji = ['⬅', '➡', '⏹']; |
||||
let filter = user && user.toLowerCase().trim() !== 'any' |
||||
? (r, u) => { return u.id === user.trim() && emoji.includes(r.emoji.name); } |
||||
: (r) => { return emoji.includes(r.emoji.name); }; |
||||
this.controllers.collector = this.message.createReactionCollector({ filter, time: 450000 }); |
||||
this.controllers.collector.on('collect', async (r) => { |
||||
let functions = { |
||||
'⬅': () => { return this.prevPage(); }, |
||||
'➡': () => { return this.nextPage(); }, |
||||
'⏹': () => { return this.endControllers(); } |
||||
}; |
||||
this.controllers.lastInteraction = new Date(); |
||||
return functions[r.emoji.name](); |
||||
}); |
||||
this.controllers.enabled = true; |
||||
this.controllers.endTime = endTime; |
||||
this.controllers.lastInteraction = new Date(); |
||||
this.timeoutInterval = setInterval(() => { |
||||
if (new Date().getTime() - this.controllers.lastInteraction.getTime() > this.controllers.endTime && this.controllers.enabled) { |
||||
return this.endControllers(); |
||||
} |
||||
}, this.controllers.endTime); |
||||
return this; |
||||
} |
||||
; |
||||
async updateControllers() { return this; } |
||||
; |
||||
async endControllers() { |
||||
await this.message.reactions.removeAll(); |
||||
this.controllers.collector.stop(); |
||||
let fe = this.message.embeds[0]; |
||||
fe.setDescription(`${fe.description}\n\n*This menu has ended, start a new one to interact with it!*`); |
||||
fe.setFooter(`${fe.footer.text} | Menu ended`, this.client.user.avatarURL()); |
||||
await this.message.edit({ embeds: [fe] }); |
||||
clearInterval(this.timeoutInterval); |
||||
return this; |
||||
} |
||||
; |
||||
async start(options) { |
||||
await this.setPage(options && options.startPage ? options.startPage : 0); |
||||
await this.setControllers(options && options.endTime ? options.endTime : 60, options && options.user ? options.user : 'any'); |
||||
return this; |
||||
} |
||||
; |
||||
async stop() { |
||||
return await this.endControllers(); |
||||
} |
||||
; |
||||
} |
||||
exports.Pagination = Pagination; |
||||
|
Loading…
Reference in new issue