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
|
2023-07-10 22:10:47 +00:00
|
|
|
* @param {boolean} listen whether to set up the event listeners for OOYE to operate
|
2022-12-07 00:10:31 +00:00
|
|
|
*/
|
2023-08-15 05:20:31 +00:00
|
|
|
constructor(discordToken, listen = true) {
|
2022-12-07 00:10:31 +00:00
|
|
|
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-08-15 05:20:31 +00:00
|
|
|
if (listen) {
|
|
|
|
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
|