mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
@@ -1,3 +1,4 @@
|
||||
const Long = require('long');
|
||||
const snekfetch = require('snekfetch');
|
||||
const Constants = require('./Constants');
|
||||
const ConstantsHttp = Constants.DefaultOptions.http;
|
||||
@@ -290,6 +291,23 @@ class Util {
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort by discord's position then ID thing
|
||||
* @param {Collection} collection Collection of objects to sort
|
||||
* @returns {Collection}
|
||||
*/
|
||||
static discordSort(collection) {
|
||||
return collection
|
||||
.sort((a, b) => a.rawPosition - b.rawPosition || Long.fromString(a.id).sub(Long.fromString(b.id)).toNumber());
|
||||
}
|
||||
|
||||
static setPosition(item, position, relative, sorted, route, handle, reason) {
|
||||
let updatedItems = sorted.array();
|
||||
Util.moveElementInArray(updatedItems, item, position, relative);
|
||||
updatedItems = updatedItems.map((r, i) => ({ id: r.id, position: i }));
|
||||
return route.patch({ data: updatedItems, reason }).then(handle || (x => x));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Util;
|
||||
|
||||
Reference in New Issue
Block a user