utils.selectionMessage: add support for multiple values
This commit is contained in:
		
							parent
							
								
									c48880ff4f
								
							
						
					
					
						commit
						306ad496fa
					
				
					 1 changed files with 22 additions and 7 deletions
				
			
		| 
						 | 
					@ -160,7 +160,13 @@ async function hastebin(body) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
hf.selectionMessages = hf.selectionMessages || new Eris.Collection();
 | 
					hf.selectionMessages = hf.selectionMessages || new Eris.Collection();
 | 
				
			||||||
async function selectionMessage(msg, heading, options, timeout = 30000) {
 | 
					async function selectionMessage(
 | 
				
			||||||
 | 
					  msg,
 | 
				
			||||||
 | 
					  heading,
 | 
				
			||||||
 | 
					  options,
 | 
				
			||||||
 | 
					  timeout = 30000,
 | 
				
			||||||
 | 
					  maxItems = 1
 | 
				
			||||||
 | 
					) {
 | 
				
			||||||
  const data = {
 | 
					  const data = {
 | 
				
			||||||
    content: heading,
 | 
					    content: heading,
 | 
				
			||||||
    allowedMentions: {
 | 
					    allowedMentions: {
 | 
				
			||||||
| 
						 | 
					@ -177,6 +183,7 @@ async function selectionMessage(msg, heading, options, timeout = 30000) {
 | 
				
			||||||
            type: 3,
 | 
					            type: 3,
 | 
				
			||||||
            custom_id: msg.id,
 | 
					            custom_id: msg.id,
 | 
				
			||||||
            options: [],
 | 
					            options: [],
 | 
				
			||||||
 | 
					            max_values: maxItems,
 | 
				
			||||||
          },
 | 
					          },
 | 
				
			||||||
        ],
 | 
					        ],
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
| 
						 | 
					@ -193,15 +200,15 @@ async function selectionMessage(msg, heading, options, timeout = 30000) {
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  options.slice(0, 20).forEach((value) => {
 | 
					  options.slice(0, 25).forEach((value) => {
 | 
				
			||||||
    data.components[0].components[0].options.push({
 | 
					    data.components[0].components[0].options.push({
 | 
				
			||||||
      label: value.display,
 | 
					      label: value.display,
 | 
				
			||||||
      value: value.key,
 | 
					      value: value.key,
 | 
				
			||||||
      description: value.description,
 | 
					      description: value.description,
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
  if (options.length > 20) {
 | 
					  if (options.length > 25) {
 | 
				
			||||||
    data.content += `\n\nDisplaying 20/${options.length} results`;
 | 
					    data.content += `\n\nDisplaying 25/${options.length} results`;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const displayMessage = await msg.channel.createMessage(data);
 | 
					  const displayMessage = await msg.channel.createMessage(data);
 | 
				
			||||||
| 
						 | 
					@ -235,9 +242,17 @@ async function selectionMessage(msg, heading, options, timeout = 30000) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            displayMessage.delete();
 | 
					            displayMessage.delete();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const result = options.filter(
 | 
					            let result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (maxItems > 1) {
 | 
				
			||||||
 | 
					              result = options
 | 
				
			||||||
 | 
					                .filter((opt) => interaction.data.values.includes(opt.key))
 | 
				
			||||||
 | 
					                .map((opt) => opt.value);
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					              result = options.filter(
 | 
				
			||||||
                (opt) => opt.key == interaction.data.values[0]
 | 
					                (opt) => opt.key == interaction.data.values[0]
 | 
				
			||||||
              )[0].value;
 | 
					              )[0].value;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            resolve(result);
 | 
					            resolve(result);
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue