initial commit

Change-Id: I4522eab57911a084cd0c5b796a57dee462e71a7d
diff --git a/index.ts b/index.ts
new file mode 100644
index 0000000..6c5e4f3
--- /dev/null
+++ b/index.ts
@@ -0,0 +1,86 @@
+import { ChannelType, Client, Collection, Guild, GuildChannel, GuildEmoji, GuildInvitableChannelResolvable, IntentsBitField, TextChannel } from 'discord.js';
+import { writeFileSync, readdirSync, readFileSync } from 'fs'
+
+
+
+async function uploadEmoji(guild: Guild, toUpload: {name: string, attachment: Buffer}): Promise<GuildEmoji> {
+    const emoji = await guild.emojis.create(toUpload)
+
+    return emoji;
+}
+
+async function propogateGuilds(client: Client<true>): Promise<Collection<string, Guild>> {
+    let guilds = client.guilds.cache.filter((guild) => guild.ownerId == client.user.id);
+
+    if (guilds.size < 10) {
+        await client.guilds.create({
+            name: `BlueprintRadar Emoji ${guilds.size + 1}`
+        });
+        propogateGuilds(client);
+    }
+
+    return guilds;
+}
+
+
+const client = new Client({
+    intents: [
+        IntentsBitField.Flags.GuildEmojisAndStickers,
+        IntentsBitField.Flags.Guilds
+    ]
+});
+
+client.once('ready', async (client) => {
+
+    let emojis: Collection<string, string> = new Collection();
+
+    const dir = readdirSync("./deduplicated", {
+        withFileTypes: true
+    }).filter(file => file.isFile());
+    const emojiFiles = dir.filter(file => file.name.endsWith('.png'));
+
+    let currentEmojiIndex = 0;
+
+    const guilds = await propogateGuilds(client);
+
+    for (const [_id, guild] of guilds) {
+        if (guild.invites.cache.size > 0) {
+            console.log(`${guild.name}: ${guild.invites.cache.first()?.url}`);
+        } else {
+            if (guild.channels.cache.size === 0) await guild.channels.create({name: 'invite-channel', type: ChannelType.GuildText });
+            const channels = guild.channels.cache.filter(channel => !(channel.type == ChannelType.GuildCategory)) as Collection<string, GuildInvitableChannelResolvable>;
+            const invite = await guild.invites.create(channels.first()!, {
+                temporary: false
+            });
+            console.log(`${guild.name}: ${invite.url}`);
+        }
+
+        for (const [_, emoji] of guild.emojis.cache) {
+            await emoji.delete();
+        }
+
+        let emojiCount = 50;
+
+        while (emojiCount > 0) {
+            let emoji = emojiFiles[currentEmojiIndex];
+            let attachment = readFileSync(emoji.path);
+            let name = emoji.name.split('.')[0]
+            const outEmoji = await uploadEmoji(guild, {name, attachment});
+
+            emojis.set(name, outEmoji.id);
+
+            emojiCount--;
+            currentEmojiIndex++;
+        }
+
+    }
+
+    let json: Record<string, string> = {};
+    for (const [k,v] of emojis) {
+        json[k] = v;
+    }
+
+    writeFileSync('./out.json', JSON.stringify(json));
+})
+
+client.login(process.env.TOKEN)
\ No newline at end of file