Archived
0
0
Fork 0

feat: switch to DJS fork

This commit is contained in:
Daryl Ronningen 2021-12-29 21:38:12 -08:00
parent 7972a6a1d6
commit c066b13446
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B
4 changed files with 226 additions and 91 deletions

View file

@ -23,6 +23,7 @@
"blessed": "^0.1.81", "blessed": "^0.1.81",
"blessed-contrib": "^4.10.1", "blessed-contrib": "^4.10.1",
"config": "^3.3.6", "config": "^3.3.6",
"discord.js": "https://github.com/Relms12345/discord.js.git#commit=f792a34bf7925cbf74e4c5799b74b66da93b3d5f",
"ws": "^8.4.0" "ws": "^8.4.0"
}, },
"devDependencies": { "devDependencies": {

View file

@ -1,14 +1,13 @@
process.env['NODE_CONFIG_DIR'] = process.env['HOME'] + '/.config/chord/'; process.env['NODE_CONFIG_DIR'] = process.env['HOME'] + '/.config/chord/';
process.env['NODE_CONFIG_ENV'] = 'config'; process.env['NODE_CONFIG_ENV'] = 'config';
import axios from 'axios';import blessed from 'blessed'; import blessed from 'blessed';
import blessedContrib from 'blessed-contrib'; import blessedContrib from 'blessed-contrib';
import config from 'config'; import config from 'config';
import { Client } from 'discord.js';
import { Client } from './lib/client'; let currentSelectedChannel: string = '';
let currentSelectedGuild: string = '';
let currentSelectedChannel = 0;
let currentSelectedGuild = 0;
const screen = blessed.screen({ const screen = blessed.screen({
smartCSR: true, smartCSR: true,
@ -161,51 +160,68 @@ const messageBoxInput = blessed.textarea({
screen.append(mainWindow); screen.append(mainWindow);
const client = new Client(config.get('token'), {}); const client = new Client({
waitGuildTimeout: 0,
intents: 32767,
});
client.on('ready', (evt: Record<string, any>) => { client.on('ready', () => {
for (const guild of evt['guilds']) { client.guilds.cache.forEach((val) => {
serverListList.addItem(guild.name); serverListList.addItem(val.name);
} });
screen.render(); screen.render();
}); });
client.on('guild_create', (guild: Record<string, any>) => { client.on('error', (err) => {
serverListList.addItem(guild['name']); throw err;
screen.render();
}); });
client.connect(); client.login(config.get('token'));
serverListList.on('select', (_item, index) => { serverListList.on('select', (item) => {
channelListList.clearItems(); channelListList.clearItems();
currentSelectedGuild = index; const findGuild = client.guilds.cache.find((val) => val.name === item.content);
for (const channel of client.guilds[index]!['channels']) { if (findGuild) {
if (channel.type === 0) currentSelectedGuild = findGuild.id;
channelListList.addItem(channel.name);
findGuild.channels.cache.forEach((val) => {
if (val.type === 'GUILD_TEXT' && val.members.find((val) => val.id === client.user!.id))
channelListList.addItem(val.name);
});
} }
screen.render(); screen.render();
}); });
channelListList.on('select', async (_item, index) => { channelListList.on('select', async (item) => {
chatBoxList.clearItems(); chatBoxList.clearItems();
currentSelectedChannel = index; const findGuild = await client.guilds.fetch(currentSelectedGuild);
const findChannel = findGuild.channels.cache.find((val) => val.name === item.content);
const getChannelMessages = await axios.get(`https://discord.com/api/v9/channels/${client.guilds[currentSelectedGuild]!['channels'][index].id}/messages`, { headers: { Authorization: config.get('token') } }); if (findChannel) {
currentSelectedChannel = findChannel.id;
for (const message of getChannelMessages.data) { if (findChannel.isText()) {
chatBoxList.addItem(message.content); const messages = await findChannel.messages.fetch({ limit: 100 });
messages.reverse().forEach((val) => {
const createdTimeStamp = new Date(val.createdTimestamp);
chatBoxList.addItem(`${createdTimeStamp.toISOString()} (${val.author.username}#${val.author.discriminator}) | ${val.content}`);
});
}
} }
chatBoxList.scrollTo(100);
chatBoxList.select(100);
screen.render(); screen.render();
}); });
screen.key('S-q', () => { screen.key('S-q', () => {
process.exit(0); process.exit(0);
}); });

View file

@ -1,66 +0,0 @@
import { EventEmitter } from 'events';
import os from 'os';
import WebSocket from 'ws';
export class Client extends EventEmitter {
public guilds: Record<string, any>[];
public ws: WebSocket | null;
private _config: object;
private _heartbeatInterval: number;
private _token: string;
public constructor(token: string, config: object) {
super();
this.guilds = [];
this.ws = null;
this._config = config;
this._heartbeatInterval = 0;
this._token = token;
}
public async connect(): Promise<void> {
this.ws = new WebSocket('wss://gateway.discord.gg/');
this.ws.on('close', (_code, reason) => {
throw reason;
});
this.ws.on('message', (data: string) => {
const objectData = JSON.parse(data);
if (objectData.op === 0) {
if (objectData.t === 'GUILD_CREATE') {
this.guilds.push(objectData.d);
this.emit('guild_create', objectData.d);
} else if (objectData.t === 'READY') {
this.guilds = objectData.d.guilds;
this.emit('ready', objectData.d);
}
} else if (objectData.op === 10) {
this._heartbeatInterval = objectData.d.heartbeat_interval;
this.ws!.send(JSON.stringify({
op: 2,
d: {
token: this._token,
intents: 32767,
properties: {
$os: os.platform(),
$browser: 'chord',
$device: 'chord',
},
},
}))
setInterval(() => {
this.ws!.send(JSON.stringify({op: 11}));
}, this._heartbeatInterval);
}
});
}
}

184
yarn.lock
View file

@ -5,6 +5,40 @@ __metadata:
version: 5 version: 5
cacheKey: 8 cacheKey: 8
"@discordjs/builders@npm:^0.11.0":
version: 0.11.0
resolution: "@discordjs/builders@npm:0.11.0"
dependencies:
"@sindresorhus/is": ^4.2.0
discord-api-types: ^0.26.0
ts-mixer: ^6.0.0
tslib: ^2.3.1
zod: ^3.11.6
checksum: 7a25b59bb52d2e3695bca27946a99cf2de95b7edd5be424ea9f4707a465524be21263e25e532e12438e99f9f55fb98b033885c760aeb96424b8c12f663f50760
languageName: node
linkType: hard
"@discordjs/collection@npm:^0.4.0":
version: 0.4.0
resolution: "@discordjs/collection@npm:0.4.0"
checksum: fa8fc4246921f3230eb6c5d6d4dc0caf9dd659fcc903175944edf4fb0a9ed9913fdf164733d3f1e644ef469bc79b0d38a526ee620b92169cb40e79b40b0c716b
languageName: node
linkType: hard
"@sapphire/async-queue@npm:^1.1.9":
version: 1.1.9
resolution: "@sapphire/async-queue@npm:1.1.9"
checksum: 8a4cb79e01948ee9f99f47e9fdfdfd509353d267f9e18bb8fe8e813b5d45f1fb6de08297b4557eb9a76b95bea59abaab67819175238068cc4cbc808d1d183e9d
languageName: node
linkType: hard
"@sindresorhus/is@npm:^4.2.0":
version: 4.2.0
resolution: "@sindresorhus/is@npm:4.2.0"
checksum: 59040dfb75c2eb6ab76e8c7ac10b7f7f6ba740f0b5ac618a89a8bcdbaf923836a8e998078d59d81f6f13f4b6bbe15bfe1bca962c877edcbe9160d1c100c56fd7
languageName: node
linkType: hard
"@types/blessed@npm:^0.1.19": "@types/blessed@npm:^0.1.19":
version: 0.1.19 version: 0.1.19
resolution: "@types/blessed@npm:0.1.19" resolution: "@types/blessed@npm:0.1.19"
@ -21,6 +55,16 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@types/node-fetch@npm:^2.5.12":
version: 2.5.12
resolution: "@types/node-fetch@npm:2.5.12"
dependencies:
"@types/node": "*"
form-data: ^3.0.0
checksum: ad63c85ba6a9477b8e057ec8682257738130d98e8ece4e31141789bd99df9d9147985cc8bc0cb5c8983ed5aa6bb95d46df23d1e055f4ad5cf8b82fc69cf626c7
languageName: node
linkType: hard
"@types/node@npm:*, @types/node@npm:^17.0.4": "@types/node@npm:*, @types/node@npm:^17.0.4":
version: 17.0.4 version: 17.0.4
resolution: "@types/node@npm:17.0.4" resolution: "@types/node@npm:17.0.4"
@ -99,6 +143,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"asynckit@npm:^0.4.0":
version: 0.4.0
resolution: "asynckit@npm:0.4.0"
checksum: 7b78c451df768adba04e2d02e63e2d0bf3b07adcd6e42b4cf665cb7ce899bedd344c69a1dcbce355b5f972d597b25aaa1c1742b52cffd9caccb22f348114f6be
languageName: node
linkType: hard
"axios@npm:^0.24.0": "axios@npm:^0.24.0":
version: 0.24.0 version: 0.24.0
resolution: "axios@npm:0.24.0" resolution: "axios@npm:0.24.0"
@ -207,6 +258,7 @@ __metadata:
blessed: ^0.1.81 blessed: ^0.1.81
blessed-contrib: ^4.10.1 blessed-contrib: ^4.10.1
config: ^3.3.6 config: ^3.3.6
discord.js: "https://github.com/Relms12345/discord.js.git#commit=f792a34bf7925cbf74e4c5799b74b66da93b3d5f"
typescript: ^4.5.4 typescript: ^4.5.4
ws: ^8.4.0 ws: ^8.4.0
languageName: unknown languageName: unknown
@ -249,6 +301,15 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"combined-stream@npm:^1.0.8":
version: 1.0.8
resolution: "combined-stream@npm:1.0.8"
dependencies:
delayed-stream: ~1.0.0
checksum: 49fa4aeb4916567e33ea81d088f6584749fc90c7abec76fd516bf1c5aa5c79f3584b5ba3de6b86d26ddd64bae5329c4c7479343250cfe71c75bb366eae53bb7c
languageName: node
linkType: hard
"config@npm:^3.3.6": "config@npm:^3.3.6":
version: 3.3.6 version: 3.3.6
resolution: "config@npm:3.3.6" resolution: "config@npm:3.3.6"
@ -265,6 +326,37 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"delayed-stream@npm:~1.0.0":
version: 1.0.0
resolution: "delayed-stream@npm:1.0.0"
checksum: 46fe6e83e2cb1d85ba50bd52803c68be9bd953282fa7096f51fc29edd5d67ff84ff753c51966061e5ba7cb5e47ef6d36a91924eddb7f3f3483b1c560f77a0020
languageName: node
linkType: hard
"discord-api-types@npm:^0.26.0":
version: 0.26.0
resolution: "discord-api-types@npm:0.26.0"
checksum: 5c2a3f7309fec3830a8da5e98e5260b25304512ae856c770d783492aa4a8c514a64025bb30ceda0c4381bc749db9545c0d7d5573fa0d60bb1718add27c8b4d7d
languageName: node
linkType: hard
"discord.js@https://github.com/Relms12345/discord.js.git#commit=f792a34bf7925cbf74e4c5799b74b66da93b3d5f":
version: 14.0.0-dev
resolution: "discord.js@https://github.com/Relms12345/discord.js.git#commit=f792a34bf7925cbf74e4c5799b74b66da93b3d5f"
dependencies:
"@discordjs/builders": ^0.11.0
"@discordjs/collection": ^0.4.0
"@sapphire/async-queue": ^1.1.9
"@types/node-fetch": ^2.5.12
"@types/ws": ^8.2.2
discord-api-types: ^0.26.0
form-data: ^4.0.0
node-fetch: ^2.6.1
ws: ^8.4.0
checksum: 1eb73a1f33f1706766112c4011c726b9fc5cd2d2e3655cb245f59f713033238a139c44275ec9f96f7b23d1e9bc38cf466d19277a5fb45526e9ea0fb05cfd823d
languageName: node
linkType: hard
"drawille-blessed-contrib@npm:>=0.0.1": "drawille-blessed-contrib@npm:>=0.0.1":
version: 1.0.0 version: 1.0.0
resolution: "drawille-blessed-contrib@npm:1.0.0" resolution: "drawille-blessed-contrib@npm:1.0.0"
@ -328,6 +420,28 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"form-data@npm:^3.0.0":
version: 3.0.1
resolution: "form-data@npm:3.0.1"
dependencies:
asynckit: ^0.4.0
combined-stream: ^1.0.8
mime-types: ^2.1.12
checksum: b019e8d35c8afc14a2bd8a7a92fa4f525a4726b6d5a9740e8d2623c30e308fbb58dc8469f90415a856698933c8479b01646a9dff33c87cc4e76d72aedbbf860d
languageName: node
linkType: hard
"form-data@npm:^4.0.0":
version: 4.0.0
resolution: "form-data@npm:4.0.0"
dependencies:
asynckit: ^0.4.0
combined-stream: ^1.0.8
mime-types: ^2.1.12
checksum: 01135bf8675f9d5c61ff18e2e2932f719ca4de964e3be90ef4c36aacfc7b9cb2fceb5eca0b7e0190e3383fe51c5b37f4cb80b62ca06a99aaabfcfd6ac7c9328c
languageName: node
linkType: hard
"gl-matrix@npm:^2.1.0": "gl-matrix@npm:^2.1.0":
version: 2.8.1 version: 2.8.1
resolution: "gl-matrix@npm:2.8.1" resolution: "gl-matrix@npm:2.8.1"
@ -448,6 +562,22 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"mime-db@npm:1.51.0":
version: 1.51.0
resolution: "mime-db@npm:1.51.0"
checksum: 613b1ac9d6e725cc24444600b124a7f1ce6c60b1baa654f39a3e260d0995a6dffc5693190217e271af7e2a5612dae19f2a73f3e316707d797a7391165f7ef423
languageName: node
linkType: hard
"mime-types@npm:^2.1.12":
version: 2.1.34
resolution: "mime-types@npm:2.1.34"
dependencies:
mime-db: 1.51.0
checksum: 67013de9e9d6799bde6d669d18785b7e18bcd212e710d3e04a4727f92f67a8ad4e74aee24be28b685adb794944814bde649119b58ee3282ffdbee58f9278d9f3
languageName: node
linkType: hard
"minimist@npm:^1.2.5": "minimist@npm:^1.2.5":
version: 1.2.5 version: 1.2.5
resolution: "minimist@npm:1.2.5" resolution: "minimist@npm:1.2.5"
@ -464,6 +594,15 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"node-fetch@npm:^2.6.1":
version: 2.6.6
resolution: "node-fetch@npm:2.6.6"
dependencies:
whatwg-url: ^5.0.0
checksum: ee8290626bdb73629c59722b75dcf4b9b6a67c1ed7eb9102e368479c4a13b56a48c2bb3ad71571e378e98c8b2c64c820e11f9cd39e4b8557dd138ad571ef9a42
languageName: node
linkType: hard
"nopt@npm:~2.1.2": "nopt@npm:~2.1.2":
version: 2.1.2 version: 2.1.2
resolution: "nopt@npm:2.1.2" resolution: "nopt@npm:2.1.2"
@ -632,6 +771,27 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"tr46@npm:~0.0.3":
version: 0.0.3
resolution: "tr46@npm:0.0.3"
checksum: 726321c5eaf41b5002e17ffbd1fb7245999a073e8979085dacd47c4b4e8068ff5777142fc6726d6ca1fd2ff16921b48788b87225cbc57c72636f6efa8efbffe3
languageName: node
linkType: hard
"ts-mixer@npm:^6.0.0":
version: 6.0.0
resolution: "ts-mixer@npm:6.0.0"
checksum: 791a513c9ca318a979928f5265fd6029858fa21595153a9386063c11239a6b1c352db1e277c19f0544d017a67cf78d120a7438b86b2c828b1115eb607538eff8
languageName: node
linkType: hard
"tslib@npm:^2.3.1":
version: 2.3.1
resolution: "tslib@npm:2.3.1"
checksum: de17a98d4614481f7fcb5cd53ffc1aaf8654313be0291e1bfaee4b4bb31a20494b7d218ff2e15017883e8ea9626599b3b0e0229c18383ba9dce89da2adf15cb9
languageName: node
linkType: hard
"type-fest@npm:^0.21.3": "type-fest@npm:^0.21.3":
version: 0.21.3 version: 0.21.3
resolution: "type-fest@npm:0.21.3" resolution: "type-fest@npm:0.21.3"
@ -659,6 +819,23 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"webidl-conversions@npm:^3.0.0":
version: 3.0.1
resolution: "webidl-conversions@npm:3.0.1"
checksum: c92a0a6ab95314bde9c32e1d0a6dfac83b578f8fa5f21e675bc2706ed6981bc26b7eb7e6a1fab158e5ce4adf9caa4a0aee49a52505d4d13c7be545f15021b17c
languageName: node
linkType: hard
"whatwg-url@npm:^5.0.0":
version: 5.0.0
resolution: "whatwg-url@npm:5.0.0"
dependencies:
tr46: ~0.0.3
webidl-conversions: ^3.0.0
checksum: b8daed4ad3356cc4899048a15b2c143a9aed0dfae1f611ebd55073310c7b910f522ad75d727346ad64203d7e6c79ef25eafd465f4d12775ca44b90fa82ed9e2c
languageName: node
linkType: hard
"wordwrap@npm:>=0.0.1 <0.1.0, wordwrap@npm:~0.0.2": "wordwrap@npm:>=0.0.1 <0.1.0, wordwrap@npm:~0.0.2":
version: 0.0.3 version: 0.0.3
resolution: "wordwrap@npm:0.0.3" resolution: "wordwrap@npm:0.0.3"
@ -704,3 +881,10 @@ __metadata:
checksum: 7152695e16f1a9976658215abab27e55d08b1b97bca901d58b048d2b6e106b5af31efccbdecf9b07af37c8377d8e7e821b494af10b3a68b0ff4ae60331b415b0 checksum: 7152695e16f1a9976658215abab27e55d08b1b97bca901d58b048d2b6e106b5af31efccbdecf9b07af37c8377d8e7e821b494af10b3a68b0ff4ae60331b415b0
languageName: node languageName: node
linkType: hard linkType: hard
"zod@npm:^3.11.6":
version: 3.11.6
resolution: "zod@npm:3.11.6"
checksum: 044ac416450f179a0c88240f27849d2886c777cebade42df10e5f04125b0265cec82d9bd741a7dcb11796b2ea88b32c86be7d36932a4bed6af57002560359db1
languageName: node
linkType: hard