2023-04-25 20:06:08 +00:00
|
|
|
// @ts-check
|
|
|
|
|
2023-10-15 11:12:00 +00:00
|
|
|
const registration = require("../matrix/read-registration")
|
|
|
|
const { Endpoints, SnowTransfer } = require("snowtransfer")
|
2022-12-07 00:10:31 +00:00
|
|
|
const { Client: CloudStorm } = require("cloudstorm")
|
|
|
|
|
2023-10-15 11:12:00 +00:00
|
|
|
// @ts-ignore
|
|
|
|
Endpoints.BASE_HOST = registration.ooye.discord_origin; Endpoints.CDN_URL = registration.ooye.discord_cdn_origin
|
|
|
|
|
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-09-03 13:38:30 +00:00
|
|
|
* @param {string} listen "full", "half", "no" - whether to set up the event listeners for OOYE to operate
|
2022-12-07 00:10:31 +00:00
|
|
|
*/
|
2023-09-03 13:38:30 +00:00
|
|
|
constructor(discordToken, listen = "full") {
|
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-09-03 13:38:30 +00:00
|
|
|
if (listen !== "no") {
|
|
|
|
this.cloud.on("event", message => discordPackets.onPacket(this, message, listen))
|
2023-08-15 05:20:31 +00:00
|
|
|
}
|
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
|