diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.eslintignore @@ -0,0 +1 @@ +build diff --git a/CHANGELOG b/CHANGELOG index 33f6df9..d13f05b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,4 +2,5 @@ 1.0.1 - Added a random function. Added a confirmation on the Add and Remove Function 1.1.0 - Added the Poll function. WIP 2.0 - Bot was completely revamped. Database now functioning -3.0 - Bot got spookier on #Hacktoberfest2020. Added Add-Many, Remove-Many, Clear and Remind commands. Also lots of bug fixes and code optimization \ No newline at end of file +3.0 - Bot got spookier on #Hacktoberfest2020. Added Add-Many, Remove-Many, Clear and Remind commands. Also lots of bug fixes and code optimization +3.2.0 - Added page selection to list command. \ No newline at end of file diff --git a/README.md b/README.md index 11bdb2f..36197d5 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ you can use the following commands: * $add : adds a component to the list * $multi-add - adds mutiple elements \in a list * $help: shows you a message with the available commands - * $list: lists all the components \in the channel\'s list + * $list : lists all the components \in the channel\'s list on given page * $log: a log of the versions * $poll : creates a poll on 5 random items of the list. If attribute is not supplied the poll has no limitation of time. * $random: gives you a random component from the list @@ -93,7 +93,7 @@ To connect on: ### :jack_o_lantern: Contributors Hacktoberfest 2020: - +
diff --git a/package.json b/package.json index a5b2fa6..af79c3d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ListBot", - "version": "3.1.0", + "version": "3.2.0", "description": "", "main": "src/index.js", "scripts": { diff --git a/src/commands/list.js b/src/commands/list.js index 2f9a17e..963bca2 100644 --- a/src/commands/list.js +++ b/src/commands/list.js @@ -6,19 +6,19 @@ const MAX_EMBED_SIZE = 1800 module.exports = { name: 'list', - description: 'Lists all the elements of the list', - execute: async (message) => { + usage: '', + description: 'Lists all the elements of the list on given page', + execute: async (message, [page]) => { let { channel } = message let channelName = channel.name + let chosenPage = page ? Number(page) : 1 let dbChannel = await ChannelRepository.findOrCreate(channel) - if (!dbChannel.items || dbChannel.items.length === 0) { const emptyMessage = Util.embedMessage( `List empty for \`${channelName}\``, message.author, '0xffff00', - message.author.tag, Style.error( "No items found, please use the 'add {element}' command to put your first item." ) @@ -28,13 +28,15 @@ module.exports = { } let fields = [] + let tempFields = [] let size = 0 + let currentPage = 1 function send() { if (fields.length === 0) return let embeddedMessage = Util.embedMessage( - `List for \`${channelName}\``, + `List for \`${channelName}\` page ${chosenPage} / ${currentPage}`, message.author, '0xffff00', Style.markDown(fields.join('\n')) @@ -46,16 +48,32 @@ module.exports = { let line = `${i + 1}. < ${item.content} >\n${item.author}\n---` let len = line.length if (size + len >= MAX_EMBED_SIZE) { - size = 0 + if (currentPage === chosenPage) fields = tempFields - send() - fields = [] + currentPage += 1 + size = 0 + tempFields = [] } - fields.push(line) + tempFields.push(line) size += len }) + if (currentPage < chosenPage) { + const emptyMessage = Util.embedMessage( + `No items on page ${chosenPage} for ${channelName}`, + message.author, + '0xffff00', + Style.error( + `No items found, there are only ${currentPage} pages.` + ) + ) + channel.send(emptyMessage) + return + } + + if (fields.length === 0) fields = tempFields + send() }, }