Skip to content

Instantly share code, notes, and snippets.

@almeidx
Last active May 2, 2023 00:18
Show Gist options
  • Save almeidx/45cba208a1983c7b7e5555d9691ab834 to your computer and use it in GitHub Desktop.
Save almeidx/45cba208a1983c7b7e5555d9691ab834 to your computer and use it in GitHub Desktop.
import { Client, ChannelType } from './packages/discord.js/src/index.js';
const client = new Client({
intents: 1,
});
client.on('ready', async () => {
console.log('Ready!');
const guild = client.guilds.cache.get('GUILD_ID');
const channels = [...guild.channels.cache.values()].filter((channel) => !channel.isThread());
console.log('channels: ', channels.length);
let position = 0;
console.time('new, 100k');
for (let idx = 0; idx < 100_000; idx++) {
for (const channel_ of channels) {
const selfIsCategory = channel_.type === ChannelType.GuildCategory;
const movableTypes = [ChannelType.GuildText, ChannelType.GuildAnnouncement, ChannelType.GuildForum];
const movableSelf = movableTypes.includes(channel_.type);
position += channel_.guild.channels.cache.reduce(
(acc, channel) =>
acc +
((movableSelf ? movableTypes.includes(channel.type) : channel.type === channel_.type) &&
(selfIsCategory || channel.parent === channel_.parent)
? channel_.rawPosition === channel.rawPosition
? BigInt(channel_.id) < BigInt(channel.id)
: channel_.rawPosition > channel.rawPosition
: 0),
0,
);
// const sorted = channel_.guild._sortedChannels(channel_);
// position += [...sorted.values()].indexOf(sorted.get(channel_.id));
}
}
console.timeEnd('new, 100k');
console.log(position);
});
client.login();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment