From 4b91a1e7e92886f3dc1aa78260a26da681173b11 Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Tue, 30 May 2023 21:03:44 -0600 Subject: [PATCH] oceanic -> dysnomia --- README.md | 15 ++- package.json | 4 +- pnpm-lock.yaml | 173 +++++++++++--------------------- src/commands/afk.js | 4 +- src/commands/emote.js | 9 +- src/commands/history.js | 10 +- src/commands/listChannels.js | 8 +- src/commands/listGuilds.js | 4 +- src/commands/listUsers.js | 11 +- src/commands/privateMessages.js | 14 +-- src/commands/send.js | 7 +- src/index.js | 102 ++++++++----------- src/lib/messages.js | 8 +- src/lib/presence.js | 22 ++-- 14 files changed, 169 insertions(+), 222 deletions(-) diff --git a/README.md b/README.md index 9479673..54387d9 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,15 @@ A CLI-based client for Discord inspired by [SDF](https://sdf.org)'s [commode](ht ## Usage 1. `pnpm i` 2. `node src/index.js ` + Your token will be then stored in `.comcordrc` after the first launch. ### User Accounts -User accounts are *partially* supported via `allowUserAccounts=true` in your `.comcordrc`. +User accounts are _partially_ supported via `allowUserAccounts=true` in your `.comcordrc`. This is use at your own risk, despite spoofing the official client. I am not responsible for any banned accounts. #### Guild members not populating -This is due to Oceanic not implementing Lazy Guilds as they are user account specific. **DO NOT bother Oceanic to implement it!** They are purely a bot-focused library. +This is due to most libraries not implementing Lazy Guilds, as bots do not need lazy guilds to function. If you are willing to implement Lazy Guilds based off of [unofficial documentation](https://luna.gitlab.io/discord-unofficial-docs/lazy_guilds.html) and my already existing horrible hacks to make user accounts work in the first place, feel free to send a PR (on GitLab, GitHub repo is a read only mirror). @@ -24,9 +25,9 @@ and my already existing horrible hacks to make user accounts work in the first p You **MUST** grant your bot all Privileged Gateway Intents. ## Design Decisions -* Node.js was chosen currently due to familiarity. -* Oceanic was chosen due to familiarity and the nature of everything not being abstracted out to 200 different classes unlike discord.js. -* "Jank" by design. While I don't expect anyone to actually use comcord on serial terminals or teletypes other than for meme factor, the option is still there. +- Node.js was chosen currently due to familiarity. +- Dysnomia was chosen due to familiarity and the nature of everything not being abstracted out to 200 different classes unlike discord.js. +- "Jank" by design. While I don't expect anyone to actually use comcord on serial terminals or teletypes other than for meme factor, the option is still there. ## TODO - [x] Commands @@ -70,3 +71,7 @@ You **MUST** grant your bot all Privileged Gateway Intents. - [ ] Threads - [x] Not have the token just be in argv - [x] Not have everything in one file + +## Repository +If you're viewing this on GitHub or GitLab, you are viewing a read only mirror. +The main repository is located on [Gitdab](https://gitdab.com/Cynosphere/comcord) and is push mirrored to the other two. diff --git a/package.json b/package.json index 923a5ad..a0a794e 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "author": "Cynosphere", "license": "MIT", "dependencies": { + "@projectdysnomia/dysnomia": "^0.1.2", "chalk": "4.1.2", - "discord-rpc": "^4.0.1", - "oceanic.js": "^1.1.2" + "discord-rpc": "^4.0.1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 274b347..22c8dc5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,71 +1,66 @@ -lockfileVersion: 5.4 - -specifiers: - chalk: 4.1.2 - discord-rpc: ^4.0.1 - oceanic.js: ^1.1.2 +lockfileVersion: '6.0' dependencies: - chalk: 4.1.2 - discord-rpc: 4.0.1 - oceanic.js: 1.1.2 + '@projectdysnomia/dysnomia': + specifier: ^0.1.2 + version: 0.1.2 + chalk: + specifier: 4.1.2 + version: 4.1.2 + discord-rpc: + specifier: ^4.0.1 + version: 4.0.1 packages: - /@discordjs/voice/0.11.0: - resolution: {integrity: sha512-6+9cj1dxzBJm7WJ9qyG2XZZQ8rcLl6x2caW0C0OxuTtMLAaEDntpb6lqMTFiBg/rDc4Rd59g1w0gJmib33CuHw==} - engines: {node: '>=16.9.0'} - requiresBuild: true + /@projectdysnomia/dysnomia@0.1.2: + resolution: {integrity: sha512-F64G64JwFWn/QUFqkhsyBvXJ0Du3E6Y0yu8tSrcukAnSeW8qV+reKqeQnMmHcQWYopwuYM8Q6OF/VX6VKggtOA==} + engines: {node: '>=10.4.0'} + peerDependencies: + '@discordjs/opus': ^0.9.0 + erlpack: github:discord/erlpack || github:abalabahaha/erlpack + eventemitter3: ^5.0.0 + pako: ^2.1.0 + sodium-native: ^4.0.1 + zlib-sync: ^0.1.8 + peerDependenciesMeta: + '@discordjs/opus': + optional: true + erlpack: + optional: true + eventemitter3: + optional: true + pako: + optional: true + sodium-native: + optional: true + zlib-sync: + optional: true dependencies: - '@types/ws': 8.5.3 - discord-api-types: 0.36.3 - prism-media: 1.3.4 - tslib: 2.4.0 - ws: 8.9.0 + ws: 8.13.0 + optionalDependencies: + opusscript: 0.0.8 + tweetnacl: 1.0.3 transitivePeerDependencies: - - '@discordjs/opus' - bufferutil - - ffmpeg-static - - node-opus - - opusscript - utf-8-validate dev: false - optional: true - /@types/node/18.8.3: - resolution: {integrity: sha512-0os9vz6BpGwxGe9LOhgP/ncvYN5Tx1fNcd2TM3rD/aCGBkysb+ZWpXEocG24h6ZzOi13+VB8HndAQFezsSOw1w==} - dev: false - optional: true - - /@types/ws/8.5.3: - resolution: {integrity: sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==} - dependencies: - '@types/node': 18.8.3 - dev: false - optional: true - - /ansi-styles/4.3.0: + /ansi-styles@4.3.0: resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} engines: {node: '>=8'} dependencies: color-convert: 2.0.1 dev: false - /bindings/1.5.0: + /bindings@1.5.0: resolution: {integrity: sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==} dependencies: file-uri-to-path: 1.0.0 dev: false optional: true - /busboy/1.6.0: - resolution: {integrity: sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==} - engines: {node: '>=10.16.0'} - dependencies: - streamsearch: 1.1.0 - dev: false - - /chalk/4.1.2: + /chalk@4.1.2: resolution: {integrity: sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==} engines: {node: '>=10'} dependencies: @@ -73,23 +68,18 @@ packages: supports-color: 7.2.0 dev: false - /color-convert/2.0.1: + /color-convert@2.0.1: resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} engines: {node: '>=7.0.0'} dependencies: color-name: 1.1.4 dev: false - /color-name/1.1.4: + /color-name@1.1.4: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} dev: false - /discord-api-types/0.36.3: - resolution: {integrity: sha512-bz/NDyG0KBo/tY14vSkrwQ/n3HKPf87a0WFW/1M9+tXYK+vp5Z5EksawfCWo2zkAc6o7CClc0eff1Pjrqznlwg==} - dev: false - optional: true - - /discord-rpc/4.0.1: + /discord-rpc@4.0.1: resolution: {integrity: sha512-HOvHpbq5STRZJjQIBzwoKnQ0jHplbEWFWlPDwXXKm/bILh4nzjcg7mNqll0UY7RsjFoaXA7e/oYb/4lvpda2zA==} dependencies: node-fetch: 2.6.7 @@ -102,22 +92,22 @@ packages: - utf-8-validate dev: false - /file-uri-to-path/1.0.0: + /file-uri-to-path@1.0.0: resolution: {integrity: sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==} dev: false optional: true - /has-flag/4.0.0: + /has-flag@4.0.0: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} engines: {node: '>=8'} dev: false - /node-addon-api/1.7.2: + /node-addon-api@1.7.2: resolution: {integrity: sha512-ibPK3iA+vaY1eEjESkQkM0BbCqFOaZMiXRTtdB0u7b4djtY6JnsjvPdUHVMg6xQt3B8fpTTWHI9A+ADjM9frzg==} dev: false optional: true - /node-fetch/2.6.7: + /node-fetch@2.6.7: resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==} engines: {node: 4.x || >=6.0.0} peerDependencies: @@ -129,82 +119,41 @@ packages: whatwg-url: 5.0.0 dev: false - /oceanic.js/1.1.2: - resolution: {integrity: sha512-aABMK2UERHvyiwjWFx5m5ZZY7oPUHmVSOhICadZh/vqyxvGf48p+aqGlRu9bEtN6XZYPZJecQi/9IPN+phXn1Q==} - engines: {node: '>=16.16.0'} - dependencies: - undici: 5.11.0 - ws: 8.9.0 - optionalDependencies: - '@discordjs/voice': 0.11.0 - transitivePeerDependencies: - - '@discordjs/opus' - - bufferutil - - ffmpeg-static - - node-opus - - opusscript - - utf-8-validate - dev: false - - /prism-media/1.3.4: - resolution: {integrity: sha512-eW7LXORkTCQznZs+eqe9VjGOrLBxcBPXgNyHXMTSRVhphvd/RrxgIR7WaWt4fkLuhshcdT5KHL88LAfcvS3f5g==} - peerDependencies: - '@discordjs/opus': ^0.8.0 - ffmpeg-static: ^5.0.2 || ^4.2.7 || ^3.0.0 || ^2.4.0 - node-opus: ^0.3.3 - opusscript: ^0.0.8 - peerDependenciesMeta: - '@discordjs/opus': - optional: true - ffmpeg-static: - optional: true - node-opus: - optional: true - opusscript: - optional: true + /opusscript@0.0.8: + resolution: {integrity: sha512-VSTi1aWFuCkRCVq+tx/BQ5q9fMnQ9pVZ3JU4UHKqTkf0ED3fKEPdr+gKAAl3IA2hj9rrP6iyq3hlcJq3HELtNQ==} + requiresBuild: true dev: false optional: true - /streamsearch/1.1.0: - resolution: {integrity: sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==} - engines: {node: '>=10.0.0'} - dev: false - - /supports-color/7.2.0: + /supports-color@7.2.0: resolution: {integrity: sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==} engines: {node: '>=8'} dependencies: has-flag: 4.0.0 dev: false - /tr46/0.0.3: + /tr46@0.0.3: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} dev: false - /tslib/2.4.0: - resolution: {integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==} + /tweetnacl@1.0.3: + resolution: {integrity: sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==} + requiresBuild: true dev: false optional: true - /undici/5.11.0: - resolution: {integrity: sha512-oWjWJHzFet0Ow4YZBkyiJwiK5vWqEYoH7BINzJAJOLedZ++JpAlCbUktW2GQ2DS2FpKmxD/JMtWUUWl1BtghGw==} - engines: {node: '>=12.18'} - dependencies: - busboy: 1.6.0 - dev: false - - /webidl-conversions/3.0.1: + /webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} dev: false - /whatwg-url/5.0.0: + /whatwg-url@5.0.0: resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==} dependencies: tr46: 0.0.3 webidl-conversions: 3.0.1 dev: false - /ws/7.5.9: + /ws@7.5.9: resolution: {integrity: sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==} engines: {node: '>=8.3.0'} peerDependencies: @@ -217,12 +166,12 @@ packages: optional: true dev: false - /ws/8.9.0: - resolution: {integrity: sha512-Ja7nszREasGaYUYCI2k4lCKIRTt+y7XuqVoHR44YpI49TtryyqbqvDMn5eqfW7e6HzTukDRIsXqzVHScqRcafg==} + /ws@8.13.0: + resolution: {integrity: sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==} engines: {node: '>=10.0.0'} peerDependencies: bufferutil: ^4.0.1 - utf-8-validate: ^5.0.2 + utf-8-validate: '>=5.0.2' peerDependenciesMeta: bufferutil: optional: true diff --git a/src/commands/afk.js b/src/commands/afk.js index 70fc347..88931d0 100644 --- a/src/commands/afk.js +++ b/src/commands/afk.js @@ -4,13 +4,13 @@ const {updatePresence} = require("../lib/presence"); addCommand("A", "toggles AFK mode", function () { if (comcord.state.afk == true) { comcord.state.afk = false; - comcord.client.shards.forEach((shard) => (shard.presence.afk = false)); comcord.client.editStatus("online"); + comcord.client.editAFK(false); console.log(""); } else { comcord.state.afk = true; - comcord.client.shards.forEach((shard) => (shard.presence.afk = true)); comcord.client.editStatus("idle"); + comcord.client.editAFK(true); console.log(""); } diff --git a/src/commands/emote.js b/src/commands/emote.js index d909c6d..153a4a9 100644 --- a/src/commands/emote.js +++ b/src/commands/emote.js @@ -13,13 +13,12 @@ addCommand("e", "emote", function () { } else { try { process.stdout.write("\n"); - await comcord.client.guilds - .get(comcord.state.currentGuild) - .channels.get(comcord.state.currentChannel) - .createMessage({content: `*${input}*`}); + await comcord.client.createMessage(comcord.state.currentChannel, { + content: `*${input}*`, + }); console.log(`<${comcord.client.user.username} ${input}>`); } catch (err) { - console.log(""); + console.log(``); } } }); diff --git a/src/commands/history.js b/src/commands/history.js index 14d123a..7067b07 100644 --- a/src/commands/history.js +++ b/src/commands/history.js @@ -8,10 +8,10 @@ async function getHistory(limit = 20) { return; } - const messages = await comcord.client.guilds - .get(comcord.state.currentGuild) - .channels.get(comcord.state.currentChannel) - .getMessages({limit}); + const messages = await comcord.client.getMessages( + comcord.state.currentChannel, + {limit} + ); messages.reverse(); console.log("--Beginning-Review".padEnd(72, "-")); @@ -33,7 +33,7 @@ async function getExtendedHistory(input) { try { await getHistory(input); } catch (err) { - console.log(""); + console.log(``); } } diff --git a/src/commands/listChannels.js b/src/commands/listChannels.js index 7c18345..14863f5 100644 --- a/src/commands/listChannels.js +++ b/src/commands/listChannels.js @@ -8,12 +8,14 @@ function listChannels() { let longest = 0; const guild = comcord.client.guilds.get(comcord.state.currentGuild); - const channels = [...guild.channels.values()].filter((c) => c.type == 0); + const channels = Array.from(guild.channels.values()).filter( + (c) => c.type == 0 || c.type == 5 + ); channels.sort((a, b) => a.position - b.position); for (const channel of channels) { const perms = channel.permissionsOf(comcord.client.user.id); - const private = !perms.has("VIEW_CHANNEL"); + const private = !perms.has("readMessageHistory"); if (channel.name.length + (private ? 1 : 0) > longest) longest = Math.min(25, channel.name.length + (private ? 1 : 0)); @@ -26,7 +28,7 @@ function listChannels() { const topic = channel.topic != null ? channel.topic.replace(/\n/g, " ") : ""; const perms = channel.permissionsOf(comcord.client.user.id); - const private = !perms.has("VIEW_CHANNEL"); + const private = !perms.has("viewChannel"); const name = (private ? "*" : "") + channel.name; diff --git a/src/commands/listGuilds.js b/src/commands/listGuilds.js index 9feffff..e194b89 100644 --- a/src/commands/listGuilds.js +++ b/src/commands/listGuilds.js @@ -7,7 +7,9 @@ function listGuilds() { for (const guild of comcord.client.guilds.values()) { if (guild.name.length > longest) longest = guild.name.length; - const online = [...guild.members.values()].filter((m) => m.presence).length; + const online = Array.from(guild.members.values()).filter( + (m) => m.status + ).length; guilds.push({name: guild.name, members: guild.memberCount, online}); } diff --git a/src/commands/listUsers.js b/src/commands/listUsers.js index 27f1bd8..4b99c04 100644 --- a/src/commands/listUsers.js +++ b/src/commands/listUsers.js @@ -39,12 +39,13 @@ function listUsers() { `\n[you are in '${guild.name}' in '${channel.name}' among ${guild.memberCount}]\n` ); - const online = [...guild.members.values()].filter((m) => m.presence); - online.sort((a, b) => a.tag.localeCompare(b.tag)); + const online = Array.from(guild.members.values()).filter((m) => m.status); + online.sort((a, b) => a.username.localeCompare(b.username)); let longest = 0; for (const member of online) { - const name = member.tag; + // FIXME: remove discrim stuff after username migration finished + const name = member.username; if (name.length + 3 > longest) longest = name.length + 3; } @@ -52,8 +53,8 @@ function listUsers() { let index = 0; for (const member of online) { - const name = member.tag; - const status = getStatus(member.presence.status); + const name = member.username; + const status = getStatus(member.status); const nameAndStatus = (member.user.bot ? chalk.yellow(name) : chalk.reset(name)) + status; diff --git a/src/commands/privateMessages.js b/src/commands/privateMessages.js index b7d0d6a..a85d0ea 100644 --- a/src/commands/privateMessages.js +++ b/src/commands/privateMessages.js @@ -7,14 +7,14 @@ const {listUsers} = require("./listUsers"); function startDM(user) { startPrompt(":msg> ", async function (input) { if (input == "") { - console.log(`\n`); + console.log(`\n`); } else { try { - const channel = await user.createDM(); + const channel = await comcord.client.getDMChannel(user.id); await channel.createMessage({content: input}); - console.log(chalk.bold.green(`\n`)); + console.log(chalk.bold.green(`\n`)); } catch (err) { - console.log("\n"); + console.log(`\n`); } } }); @@ -25,7 +25,7 @@ addCommand("s", "send private", function () { startPrompt(":to> ", function (who) { let target; for (const user of comcord.client.users.values()) { - if (user.tag == who) { + if (user.username == who) { target = user; break; } @@ -42,7 +42,9 @@ addCommand("s", "send private", function () { addCommand("a", "answer a send", function () { if (comcord.state.lastDM) { - console.log(chalk.bold.green(``)); + console.log( + chalk.bold.green(``) + ); startDM(comcord.state.lastDM); } else { // FIXME: figure out the actual message in com diff --git a/src/commands/send.js b/src/commands/send.js index 2d04907..bc83806 100644 --- a/src/commands/send.js +++ b/src/commands/send.js @@ -21,10 +21,9 @@ function sendMode() { } else { try { process.stdout.write("\n"); - await comcord.client.guilds - .get(comcord.state.currentGuild) - .channels.get(comcord.state.currentChannel) - .createMessage({content: input}); + await comcord.client.createMessage(comcord.state.currentChannel, { + content: input, + }); if (comcord.state.afk == true) { comcord.state.afk = false; diff --git a/src/index.js b/src/index.js index c95a040..3c4503c 100644 --- a/src/index.js +++ b/src/index.js @@ -1,13 +1,14 @@ -const {Client, Constants} = require("oceanic.js"); +const {Client, Constants, Channel} = require("@projectdysnomia/dysnomia"); const DiscordRPC = require("discord-rpc"); const chalk = require("chalk"); const fs = require("fs"); +const os = require("os"); const rcfile = require("./lib/rcfile"); const config = {}; if (fs.existsSync(rcfile.path)) { - console.log("% Reading " + rcfile.path + " ..."); + console.log(`% Reading ${rcfile.path.replace(os.homedir(), "~")} ...`); rcfile.readFile(config); } @@ -42,31 +43,19 @@ global.comcord = { }, commands: {}, }; -const client = new Client({ - auth: - (config.allowUserAccounts == "true" ? "" : "Bot ") + - (token ?? config.token), - defaultImageFormat: "png", - defaultImageSize: 1024, - gateway: { - intents: ["ALL"], - maxShards: 1, - concurrency: 1, - presence: { - status: "online", - activities: [ - { - name: "comcord", - type: 0, - application_id: CLIENT_ID, - timestamps: { - start: comcord.state.startTime, - }, - }, - ], +const client = new Client( + (config.allowUserAccounts == "true" ? "" : "Bot ") + (token ?? config.token), + { + defaultImageFormat: "png", + defaultImageSize: 1024, + gateway: { + intents: Object.values(Constants.Intents), }, - }, -}); + allowedMentions: { + everyone: false, + }, + } +); comcord.client = client; const rpc = new DiscordRPC.Client({transport: "ipc"}); comcord.rpc = rpc; @@ -93,7 +82,8 @@ process.stdin.setEncoding("utf8"); client.once("ready", function () { console.log( - "Logged in as: " + chalk.yellow(`${client.user.tag} (${client.user.id})`) + "Logged in as: " + + chalk.yellow(`${client.user.username} (${client.user.id})`) ); comcord.state.nameLength = client.user.username.length + 2; @@ -135,6 +125,7 @@ rpc.on("connected", function () { }); let retryingRPC = false; rpc.once("ready", function () { + rpc.transport.on("error", function () {}); rpc.transport.on("close", function () { comcord.state.rpcConnected = false; if (!retryingRPC) { @@ -158,20 +149,19 @@ rpc.on("error", function () {}); client.on("messageCreate", async function (msg) { if (msg.author.id === client.user.id) return; - if (msg.channelID && !msg.channel) { - try { - const dmChannel = await msg.author.createDM(); - if (dmChannel.id === msg.channelID) { - msg.channel = dmChannel; - } - } catch { - // - } + if ( + !(msg.channel instanceof Channel) && + msg.author.id != client.user.id && + !msg.guildID + ) { + const newChannel = await client.getDMChannel(msg.author.id); + if (msg.channel.id == newChannel.id) msg.channel = newChannel; } + if (!(msg.channel instanceof Channel)) return; + if ( - (msg.channel ? msg.channel.id : msg.channelID) == - comcord.state.currentChannel || + msg.channel.id == comcord.state.currentChannel || msg.channel?.recipient != null ) { if (comcord.state.inPrompt) { @@ -188,20 +178,19 @@ client.on("messageCreate", async function (msg) { client.on("messageUpdate", async function (msg, old) { if (msg.author.id === client.user.id) return; - if (msg.channelID && !msg.channel) { - try { - const dmChannel = await msg.author.createDM(); - if (dmChannel.id === msg.channelID) { - msg.channel = dmChannel; - } - } catch { - // - } + if ( + !(msg.channel instanceof Channel) && + msg.author.id != client.user.id && + !msg.guildID + ) { + const newChannel = await client.getDMChannel(msg.author.id); + if (msg.channel.id == newChannel.id) msg.channel = newChannel; } + if (!(msg.channel instanceof Channel)) return; + if ( - (msg.channel ? msg.channel.id : msg.channelID) == - comcord.state.currentChannel || + msg.channel.id == comcord.state.currentChannel || msg.channel?.recipient != null ) { if (old && msg.content == old.content) return; @@ -253,7 +242,10 @@ if ( config.allowUserAccounts == "true" && !(token ?? config.token).startsWith("Bot ") ) { - if (fetch == null) { + console.log("User account support pending rewrite."); + process.exit(1); + + /*if (fetch == null) { console.log("Node v18+ needed for user account support."); process.exit(1); } @@ -270,14 +262,6 @@ if ( const newConnect = new client.connect.constructor(connectLines.join("\n")); client.connect = newConnect.bind(client); - // gross hack - global.Constants_1 = Constants; - try { - global.Erlpack = require("erlpack"); - } catch { - global.Erlpack = false; - } - console.log("% Injecting headers into request handler"); client.rest.handler.options.userAgent = `Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) discord/${superProperties.client_version} Chrome/91.0.4472.164 Electron/13.6.6 Safari/537.36`; client.rest.handler._request = client.rest.handler.request.bind( @@ -328,7 +312,7 @@ if ( console.log("% Connecting to gateway now"); await client.connect(); - })(); + })();*/ } else { client.connect(); } diff --git a/src/lib/messages.js b/src/lib/messages.js index 63b71db..ab26ade 100644 --- a/src/lib/messages.js +++ b/src/lib/messages.js @@ -155,7 +155,6 @@ function replaceTimestamps(_, time, format = "f") { function formatMessage({ name, - tag, content, bot, attachments, @@ -252,10 +251,10 @@ function formatMessage({ if (dm) { if (noColor) { - console.log(`*${tag}* ${content}\x07`); + console.log(`*${name}* ${content}\x07`); } else { console.log( - chalk.bold.red(`*${tag}*`) + chalk.reset(" " + content + "\x07") + chalk.bold.red(`*${name}*`) + chalk.reset(" " + content + "\x07") ); } } else if ( @@ -331,7 +330,6 @@ function processMessage(msg, options = {}) { if (msg.content.match(REGEX_CODEBLOCK)) { formatMessage({ name: msg.author.username, - tag: msg.author.tag, bot: msg.author.bot, content: msg.content.replace( REGEX_CODEBLOCK_GLOBAL, @@ -349,7 +347,6 @@ function processMessage(msg, options = {}) { const line = lines[index]; formatMessage({ name: msg.author.username, - tag: msg.author.tag, bot: msg.author.bot, content: line + @@ -366,7 +363,6 @@ function processMessage(msg, options = {}) { } else { formatMessage({ name: msg.author.username, - tag: msg.author.tag, bot: msg.author.bot, content: msg.content + (msg.editedTimestamp != null ? " (edited)" : ""), attachments: msg.attachments, diff --git a/src/lib/presence.js b/src/lib/presence.js index b7f8302..ccfde7f 100644 --- a/src/lib/presence.js +++ b/src/lib/presence.js @@ -15,7 +15,7 @@ function updatePresence() { const activity = { startTimestamp: comcord.state.startTime, smallImageKey: `https://cdn.discordapp.com/avatars/${comcord.client.user.id}/${comcord.client.user.avatar}.png?size=1024`, - smallImageText: comcord.client.user.tag, + smallImageText: comcord.client.user.username, buttons: [ { label: "comcord Repo", @@ -39,6 +39,17 @@ function updatePresence() { // } } + + comcord.client.editStatus(comcord.state.afk ? "idle" : "online", [ + { + name: "comcord", + type: 0, + application_id: CLIENT_ID, + timestamps: { + start: comcord.state.startTime, + }, + }, + ]); } else { const activity = { application_id: CLIENT_ID, @@ -65,12 +76,9 @@ function updatePresence() { activity.state = "AFK"; } - comcord.client.shards.forEach((shard) => { - if (shard.ready) { - shard.presence.activities = [activity]; - shard.sendPresenceUpdate(); - } - }); + comcord.client.editStatus(comcord.state.afk ? "idle" : "online", [ + activity, + ]); } }