mirror of
https://gitdab.com/cadence/out-of-your-element.git
synced 2025-09-10 04:12:50 +02:00
rearranging and experiments
This commit is contained in:
parent
11e5cd7f77
commit
6990957c9e
12 changed files with 156 additions and 26 deletions
51
d2m/discord-client.js
Normal file
51
d2m/discord-client.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
// @ts-check
|
||||
|
||||
const { SnowTransfer } = require("snowtransfer")
|
||||
const { Client: CloudStorm } = require("cloudstorm")
|
||||
|
||||
const passthrough = require("../passthrough")
|
||||
const { sync } = passthrough
|
||||
|
||||
/** @type {typeof import("./discord-packets")} */
|
||||
const discordPackets = sync.require("./discord-packets")
|
||||
|
||||
class DiscordClient {
|
||||
/**
|
||||
* @param {string} discordToken
|
||||
*/
|
||||
constructor(discordToken) {
|
||||
this.discordToken = discordToken
|
||||
this.snow = new SnowTransfer(discordToken)
|
||||
this.cloud = new CloudStorm(discordToken, {
|
||||
shards: [0],
|
||||
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"
|
||||
}
|
||||
})
|
||||
this.ready = false
|
||||
/** @type {import("discord-api-types/v10").APIUser} */
|
||||
// @ts-ignore avoid setting as or null because we know we need to wait for ready anyways
|
||||
this.user = null
|
||||
/** @type {Pick<import("discord-api-types/v10").APIApplication, "id" | "flags">} */
|
||||
// @ts-ignore
|
||||
this.application = null
|
||||
/** @type {Map<string, import("discord-api-types/v10").APIChannel>} */
|
||||
this.channels = new Map()
|
||||
/** @type {Map<string, import("discord-api-types/v10").APIGuild>} */
|
||||
this.guilds = new Map()
|
||||
/** @type {Map<string, Array<string>>} */
|
||||
this.guildChannelMap = new Map()
|
||||
this.cloud.on("event", message => discordPackets.onPacket(this, message))
|
||||
this.cloud.on("error", console.error)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DiscordClient
|
Loading…
Add table
Add a link
Reference in a new issue