-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zuxi
committed
Jun 7, 2024
1 parent
fe1ac1c
commit a485bd9
Showing
11 changed files
with
1,058 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SECRET=discord bot token because this isnt a self bot | ||
USERTOKENSECRET=DISCORDTOKEN you win need to get this yourself this is only used to generate the images and request are cached to not spam the api | ||
REDIS_CONNECTION_URI=Only if you use redis will you need this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
### VSCODE DIDNT CREATE THIS FILE SO CHATGPT DID :) | ||
|
||
# Node.js dependency directories | ||
node_modules/ | ||
|
||
# Optional npm cache directory | ||
.npm/ | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Dependency directories | ||
jspm_packages/ | ||
|
||
# Logs | ||
logs/ | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/en/knowledge/errors/diagnostic-reports/) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids/ | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov/ | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage/ | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output/ | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt/ | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components/ | ||
|
||
# Editor directories and files | ||
.idea/ | ||
.vscode/ | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
# IDE or Editor specific files | ||
*.iml | ||
*.sublime-project | ||
*.sublime-workspace | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# Next.js build output | ||
.next/ | ||
|
||
# Nuxt.js build output | ||
.nuxt/ | ||
|
||
# Gatsby files | ||
.cache/ | ||
public/ | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# Docusaurus cache | ||
.docusaurus/ | ||
|
||
# Temporary files | ||
*.tmp | ||
*.temp | ||
|
||
# MacOS files | ||
.DS_Store | ||
*.DS_Store | ||
|
||
# Windows files | ||
Thumbs.db | ||
ehthumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require("dotenv").config(); | ||
|
||
module.exports = { | ||
OP: { | ||
// only store the important opcodes only. | ||
// https://discord.com/developers/docs/topics/opcodes-and-status-codes | ||
dispatch: 0, | ||
heartbeat: 1, | ||
identify: 2, | ||
presenceUpdate: 3, | ||
resume: 6, | ||
reconnect: 7, | ||
invalidSession: 9, | ||
HELLO: 10, | ||
heartbeatACK: 11 | ||
}, | ||
|
||
Constants: { | ||
// i still have no idea. | ||
// dont change this unless you know what you're doing. | ||
seq: 13373333, | ||
|
||
// default, discord will figure it out. | ||
heartbeatTimeout: 1000 * 30, | ||
|
||
// https://www.remote.tools/remote-work/how-to-find-discord-id | ||
userMonitoredID: "459742547305299981", | ||
|
||
// for resuming. so your app wont ded immediately, so you have to send the request again. (afaik) | ||
sessionID: null, | ||
|
||
// setinterval func | ||
heartbeatInterval: null | ||
}, | ||
}; | ||
|
||
module.exports.Identification = { | ||
token: process.env.SECRET, // your bot token. | ||
v: 9, // https://discord.com/developers/docs/topics/gateway#gateways-gateway-versions | ||
intents: 1 << 1 | 1 << 8, // https://discord.com/developers/docs/topics/gateway#list-of-intents | ||
properties: { | ||
"$os": process.platform, | ||
"$browser": "ZUXI_EXPOSED_SECRETS", | ||
"$device": "13373333" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"383226320970055681": "bc45e1c85351ce0bafcb9245b3762e75" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
const WebSocket = require("ws"); | ||
const config = require("./config"); | ||
const { extractTopActivity } = require("./utils"); | ||
|
||
// supported non-browser (for Server-side) only. | ||
let ws = new WebSocket(`wss://gateway.discord.gg/?v=${config.Identification.v}&encoding=json`); | ||
|
||
|
||
ws.on("message", (raw) => { | ||
// raw Websocket data is made out of Buffer. so you have to convert it into JSON. devhuman-readable. | ||
|
||
if (!raw) return; | ||
|
||
let data; | ||
try { | ||
data = JSON.parse(Buffer.from(raw).toString("utf-8")); | ||
} catch (err) { | ||
data = null; | ||
return console.error(err); | ||
}; | ||
|
||
// failed parsing the JSON, well just break it. | ||
if (!data) return; | ||
// console.log(data); | ||
|
||
let identifyRequest = JSON.stringify({op: config.OP.identify, d: config.Identification}); | ||
let heartbeat = JSON.stringify({op: config.OP.heartbeat, d: config.Constants.seq}); | ||
|
||
switch(data.op) { | ||
case config.OP.dispatch: | ||
if (data.t === "READY") { | ||
config.Constants.sessionID = data.d.session_id; | ||
console.log("ready."); | ||
}; | ||
break; | ||
|
||
case config.OP.heartbeat: | ||
ws.send(heartbeat); | ||
console.log("heartbeat."); | ||
break; | ||
|
||
case config.OP.invalidSession: | ||
config.Constants.seq = 0; | ||
config.Constants.sessionID = null; | ||
ws.send(identifyRequest); | ||
console.warn("invalid session, identifying."); | ||
break; | ||
|
||
case config.OP.reconnect: | ||
if (!ws) return; | ||
|
||
clearInterval(config.Constants.heartbeatInterval); | ||
config.Constants.heartbeatInterval = null; | ||
|
||
if (ws.readyState !== ws.CLOSED /*&& ws.readyState !== ws.CLOSING*/) { | ||
try { | ||
if (config.Constants.sessionID) { | ||
if (ws.readyState === ws.OPEN) { | ||
console.log("reconnecting."); | ||
ws.close(4901, "reconnect."); | ||
} | ||
|
||
else { | ||
console.warn("terminated."); | ||
ws.terminate(); | ||
} | ||
} else { | ||
console.log("session continued."); | ||
ws.close(1000, "continue."); | ||
}; | ||
} catch (error) { | ||
console.error(error); | ||
}; | ||
}; | ||
|
||
ws = null; | ||
break; | ||
|
||
case config.OP.HELLO: | ||
if (data.d.heartbeat_interval > 0) { | ||
if (config.Constants.heartbeatInterval) clearInterval(config.Constants.heartbeatInterval); | ||
config.Constants.heartbeatInterval = setInterval(() => ws.send(heartbeat), data.d.heartbeat_interval); | ||
}; | ||
|
||
if (config.Constants.sessionID) { | ||
console.log("resuming the connection."); | ||
ws.send(JSON.stringify({ | ||
op: config.OP.resume, | ||
d: { | ||
token: config.Identification.token, | ||
session_id: config.Constants.sessionID, | ||
seq: config.Constants.seq | ||
} | ||
})); | ||
} else { | ||
ws.send(identifyRequest); | ||
ws.send(heartbeat); | ||
}; | ||
break; | ||
|
||
// you and i dont need to know this. | ||
case config.OP.heartbeatACK: | ||
break; | ||
|
||
default: | ||
console.log(data); | ||
break; | ||
}; | ||
|
||
if ( | ||
data.t === "PRESENCE_UPDATE" && | ||
data.d.user.id === config.Constants.userMonitoredID && | ||
data.op === config.OP.dispatch | ||
) { | ||
// for lurking | ||
//console.log(require("util").inspect(data, false, null, false)); | ||
extractTopActivity(JSON.stringify(data.d)) | ||
// return redis.set("activity.ray1337", result) | ||
// .catch(console.error); | ||
}; | ||
}); | ||
|
||
ws.on("error", console.error); | ||
|
||
ws.on("close", (code, reason) => { | ||
console.log(code, Buffer.from(reason).toString()); | ||
}); |
Oops, something went wrong.