@@ -252,10 +252,6 @@ async function run(ctx, argv) {
|
||||
const loginMs = discordLoginTimeoutMs(ctx, argv)
|
||||
|
||||
const intents = [GatewayIntentBits.Guilds]
|
||||
if (GatewayIntentBits.GuildMessages)
|
||||
intents.push(GatewayIntentBits.GuildMessages)
|
||||
if (GatewayIntentBits.DirectMessages)
|
||||
intents.push(GatewayIntentBits.DirectMessages)
|
||||
if (wantsMessageContent && GatewayIntentBits.MessageContent) {
|
||||
intents.push(GatewayIntentBits.MessageContent)
|
||||
}
|
||||
@@ -353,6 +349,55 @@ async function run(ctx, argv) {
|
||||
})
|
||||
}
|
||||
|
||||
function discordRedactWs(s) {
|
||||
return String(s || '').replace(/"token"\s*:\s*"[^"]*"/g, '"token":"***"')
|
||||
}
|
||||
function discordHookGateway(c) {
|
||||
let tries = 0
|
||||
const iv = setInterval(function () {
|
||||
tries++
|
||||
const mgr = c.ws && c.ws._ws
|
||||
const shards = mgr && mgr.shards
|
||||
let hooked = false
|
||||
if (shards && typeof shards.values === 'function') {
|
||||
const it = shards.values()
|
||||
let n = it.next()
|
||||
while (!n.done) {
|
||||
const conn = n.value && n.value.connection
|
||||
if (conn && !conn.__bareOsHooked) {
|
||||
conn.__bareOsHooked = true
|
||||
hooked = true
|
||||
if (typeof conn.send === 'function') {
|
||||
const origSend = conn.send.bind(conn)
|
||||
conn.send = function (data) {
|
||||
ctx.console.log(
|
||||
'discord-bot: ws send ' +
|
||||
discordRedactWs(data).slice(0, 180)
|
||||
)
|
||||
return origSend(data)
|
||||
}
|
||||
}
|
||||
const prev = conn.onmessage
|
||||
conn.onmessage = function (ev) {
|
||||
const d = ev && ev.data
|
||||
const text =
|
||||
typeof d === 'string'
|
||||
? d
|
||||
: d && typeof d.toString === 'function'
|
||||
? d.toString()
|
||||
: String(d)
|
||||
ctx.console.log('discord-bot: ws recv ' + text.slice(0, 180))
|
||||
if (typeof prev === 'function') return prev.apply(this, arguments)
|
||||
}
|
||||
}
|
||||
n = it.next()
|
||||
}
|
||||
}
|
||||
if (hooked || tries > 80) clearInterval(iv)
|
||||
}, 25)
|
||||
}
|
||||
discordHookGateway(client)
|
||||
|
||||
let loggingIn = true
|
||||
let loginTimer = null
|
||||
let loginTick = null
|
||||
|
||||
Reference in New Issue
Block a user