Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ you can use the following commands:
* $add <component>: adds a component to the list
* $multi-add <element> <element> - 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 <page>: lists all the components \in the channel\'s list on given page
* $log: a log of the versions
* $poll <active_time_in_minutes>: 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
Expand Down Expand Up @@ -93,7 +93,7 @@ To connect on:

### :jack_o_lantern: Contributors Hacktoberfest 2020:

<!-- readme: contributors -start -->
<!-- readme: contributors -start -->
<table>
<tr>
<td align="center">
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ListBot",
"version": "3.1.0",
"version": "3.2.0",
"description": "",
"main": "src/index.js",
"scripts": {
Expand Down
36 changes: 27 additions & 9 deletions src/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<page>',
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."
)
Expand All @@ -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'))
Expand All @@ -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()
},
}