1
0
Fork 0
out-of-your-element-fork-th.../d2m/discord-client.js

52 lines
1.6 KiB
JavaScript
Raw Normal View History

2023-04-25 20:06:08 +00:00
// @ts-check
2022-12-07 00:10:31 +00:00
const { SnowTransfer } = require("snowtransfer")
const { Client: CloudStorm } = require("cloudstorm")
2023-03-05 16:05:35 +00:00
const passthrough = require("../passthrough")
const { sync } = passthrough
2023-04-25 20:06:08 +00:00
/** @type {typeof import("./discord-packets")} */
const discordPackets = sync.require("./discord-packets")
2022-12-07 00:10:31 +00:00
class DiscordClient {
/**
* @param {string} discordToken
*/
constructor(discordToken) {
this.discordToken = discordToken
this.snow = new SnowTransfer(discordToken)
this.cloud = new CloudStorm(discordToken, {
2023-04-25 20:06:08 +00:00
shards: [0],
2022-12-07 00:10:31 +00:00
reconnect: true,
snowtransferInstance: this.snow,
intents: [
"DIRECT_MESSAGES", "DIRECT_MESSAGE_REACTIONS", "DIRECT_MESSAGE_TYPING",
"GUILDS", "GUILD_EMOJIS_AND_STICKERS", "GUILD_MESSAGES", "GUILD_MESSAGE_REACTIONS", "GUILD_MESSAGE_TYPING", "GUILD_WEBHOOKS",
"MESSAGE_CONTENT"
],
ws: {
compress: false,
encoding: "json"
}
})
2023-03-05 16:05:35 +00:00
this.ready = false
/** @type {import("discord-api-types/v10").APIUser} */
2022-12-07 20:34:05 +00:00
// @ts-ignore avoid setting as or null because we know we need to wait for ready anyways
2022-12-07 00:10:31 +00:00
this.user = null
2023-03-05 16:05:35 +00:00
/** @type {Pick<import("discord-api-types/v10").APIApplication, "id" | "flags">} */
2022-12-07 20:34:05 +00:00
// @ts-ignore
2022-12-07 00:10:31 +00:00
this.application = null
2023-03-05 16:05:35 +00:00
/** @type {Map<string, import("discord-api-types/v10").APIChannel>} */
2022-12-07 00:10:31 +00:00
this.channels = new Map()
2023-03-05 16:05:35 +00:00
/** @type {Map<string, import("discord-api-types/v10").APIGuild>} */
2022-12-07 20:34:05 +00:00
this.guilds = new Map()
2023-03-05 16:05:35 +00:00
/** @type {Map<string, Array<string>>} */
2022-12-07 20:34:05 +00:00
this.guildChannelMap = new Map()
2023-04-25 20:06:08 +00:00
this.cloud.on("event", message => discordPackets.onPacket(this, message))
2023-03-05 16:05:35 +00:00
this.cloud.on("error", console.error)
2022-12-07 00:10:31 +00:00
}
}
module.exports = DiscordClient