remove legacy libbrainlet

This commit is contained in:
hippoz 2021-09-14 13:13:58 +03:00
parent fb18dae0a8
commit fe124316a4
Signed by untrusted user who does not match committer: hippoz
GPG key ID: 7C52899193467641
6 changed files with 0 additions and 500 deletions

View file

@ -1,76 +0,0 @@
const Client = require('./index');
const secret = require('./bridgebotsecret');
const fetch = require('node-fetch');
const Discord = require('discord.js');
const LISTEN_ON = '5fce94aa37c98b23bcd140a0';
const DISCORD_LISTEN_ON = '785494888766373909';
const PREFIX = '::';
const ADMIN_ID = '5fc828ea4e96e00725c17fd7';
let discordWebhook;
const main = async () => {
const client = new Client('https://b.hippoz.xyz', {
throwErrors: true
});
const discord = new Discord.Client();
const res = await fetch(`${client.url}/api/v1/users/token/create`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: secret.brainlet.user.username,
password: secret.brainlet.user.password
})
});
const json = await res.json();
if (!res.ok || json.error) throw new Error('Failed to generate token from API endpoint');
await client.setToken(json.token);
await client.gatewayConnect();
client.gateway.on('connect', () => {
discord.on('ready', async () => {
const channel = discord.channels.cache.get(DISCORD_LISTEN_ON);
const webhooks = await channel.fetchWebhooks();
discordWebhook = webhooks.first();
if (!discordWebhook) throw new Error('No webhook in selected channel');
console.log(`[*] [DISCORD] Logged in as ${discord.user.tag}!`);
});
discord.login(secret.discord.token);
const channel = client.gateway.subscribeToChannelChat(LISTEN_ON);
discord.on('message', (e) => {
if (e.webhookID) return;
if (e.author.bot) return;
client.gateway.sendMessage(LISTEN_ON, e.content, {
nickAuthor: { username: e.author.username }
});
});
client.gateway.on('message', async (e) => {
if (e.author._id === client.user._id) return;
e.content = e.content.replace(/@/g, '');
await discordWebhook.send(e.content, {
username: e.author.username
});
});
});
};
main();

View file

@ -1,11 +0,0 @@
module.exports = {
discord: {
token: 'Nzg1NDk0MjgxOTI2MjEzNjYz.X84qjg.3gAdgnp_VmTSLvgwYmCBceLGHcA'
},
brainlet: {
user: {
username: 'e',
password: 'e'
}
}
}

View file

@ -1,88 +0,0 @@
const io = require('socket.io-client');
const EventEmitter = require('events');
class GatewayConnection extends EventEmitter {
constructor(url) {
super();
this.isConnected = false;
this.socket = null;
this.url = url;
}
}
GatewayConnection.prototype.disconnect = function() {
if (this.socket) this.socket.disconnect();
this.socket = null;
this.isConnected = false;
};
GatewayConnection.prototype.connect = function(token) {
console.log('[*] [gateway] [handshake] Trying to connect to gateway');
this.socket = io(`${this.url}/gateway`, {
query: {
token
},
transports: ['websocket']
});
this.socket.on('connect', () => {
this.socket.once('hello', (debugInfo) => {
console.log('[*] [gateway] [handshake] Got hello from server, sending yoo...', debugInfo);
this.socket.emit('yoo');
this.isConnected = true;
this.debugInfo = debugInfo;
this.emit('connect', { message: 'CONNECT_RECEIVED_HELLO' });
console.log('[*] [gateway] [handshake] Assuming that server received yoo and that connection is completed.');
});
})
this.socket.on('error', (e) => {
console.log('[E] [gateway] Gateway error', e);
this.isConnected = false;
this.socket = null;
this.emit('disconnect', { message: 'DISCONNECT_ERR' });
});
this.socket.on('disconnectNotification', (e) => {
console.log('[E] [gateway] Received disconnect notfication', e);
this.isConnected = false;
this.socket = null;
this.emit('disconnect', { message: 'DISCONNECT_NOTIF', reason: e });
});
this.socket.on('disconnect', (e) => {
console.log('[E] [gateway] Disconnected from gateway: ', e);
this.isConnected = false;
this.emit('disconnect', { message: 'DISCONNECT', reason: e });
});
this.socket.on('message', (e) => this.emit('message', e));
this.socket.on('refreshClient', (e) => this.emit('refreshClient', e));
this.socket.on('clientListUpdate', (e) => this.emit('clientListUpdate', e));
};
GatewayConnection.prototype.sendMessage = function(channelId, content, { nickAuthor, destUser }) {
if (!this.isConnected) return 1;
if (content.length >= 2000) return 1;
this.socket.emit('message', {
channel: {
_id: channelId
},
nickAuthor,
destUser,
content
});
};
GatewayConnection.prototype.subscribeToChannelChat = function(channelId) {
if (!this.isConnected) return;
const request = [channelId];
console.log('[*] [gateway] Subscribing to channel(s)', request);
this.socket.emit('subscribe', request);
return channelId;
};
module.exports = GatewayConnection;

View file

@ -1,84 +0,0 @@
const GatewayConnection = require('./gatewayconnection');
const fetch = require('node-fetch');
class Client {
constructor(url, config={}) {
this.token = null;
this.user = null;
this.isLoggedIn = false;
this.url = url;
this.config = config;
this.gateway = null;
}
}
Client.prototype.gatewayConnect = async function() {
if (!this.token) throw new Error('Attempt to connect to gateway without being authenticated');
this.gateway = new GatewayConnection(this.url);
this.gateway.connect(this.token);
};
Client.prototype.gatewayDisconnect = async function() {
if (this.gateway) this.gateway.disconnect();
this.gateway = null;
};
Client.prototype.sendAuthenticatedRequest = async function(endpoint, options) {
if (!this.token) throw new Error('Attempt to send authenticated request without being authenticated');
options.headers = {
cookie: `token=${this.token}`,
...options.headers
};
let res;
let json;
let isOK = false;
try {
res = await fetch(`${this.url}${endpoint}`, options);
json = await res.json();
} catch(e) {
throw new Error(`Request to ${endpoint} failed with error`, e);
}
if (res.ok && !json.error) {
isOK = true;
} else {
if (this.config.throwErrors) {
throw new Error(`Request to ${endpoint} failed with status ${res.status}`);
}
}
return { res, json, isOK };
};
Client.prototype.setToken = async function(token) {
this.token = token;
const { json, isOK } = await this.sendAuthenticatedRequest('/api/v1/users/current/info', {
method: 'GET',
headers: {
'Accept': 'application/json',
}
});
if (!isOK) throw new Error('Failed to get user info for setToken');
this.user = json.user;
this.userLoggedIn = true;
console.log(`[*] Logged in as ${this.user.username}`);
};
Client.prototype.unsetToken = async function() {
this.token = null;
this.user = null;
this.gatewayDisconnect();
this.userLoggedIn = false;
};
module.exports = Client;

View file

@ -1,224 +0,0 @@
{
"name": "libbrainlet",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@discordjs/collection": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz",
"integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ=="
},
"@discordjs/form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
"@types/component-emitter": {
"version": "1.2.10",
"resolved": "https://registry.npmjs.org/@types/component-emitter/-/component-emitter-1.2.10.tgz",
"integrity": "sha512-bsjleuRKWmGqajMerkzox19aGbscQX5rmmvvXl3wlIp5gMG1HgkiwPxsN5p070fBDKTNSPgojVbuY1+HWMbFhg=="
},
"abort-controller": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
"requires": {
"event-target-shim": "^5.0.0"
}
},
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
},
"backo2": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz",
"integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc="
},
"base64-arraybuffer": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.4.tgz",
"integrity": "sha1-mBjHngWbE1X5fgQooBfIOOkLqBI="
},
"combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"requires": {
"delayed-stream": "~1.0.0"
}
},
"component-bind": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz",
"integrity": "sha1-AMYIq33Nk4l8AAllGx06jh5zu9E="
},
"component-emitter": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz",
"integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg=="
},
"debug": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
"requires": {
"ms": "^2.1.1"
}
},
"delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
},
"discord.js": {
"version": "12.5.1",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.1.tgz",
"integrity": "sha512-VwZkVaUAIOB9mKdca0I5MefPMTQJTNg0qdgi1huF3iwsFwJ0L5s/Y69AQe+iPmjuV6j9rtKoG0Ta0n9vgEIL6w==",
"requires": {
"@discordjs/collection": "^0.1.6",
"@discordjs/form-data": "^3.0.1",
"abort-controller": "^3.0.0",
"node-fetch": "^2.6.1",
"prism-media": "^1.2.2",
"setimmediate": "^1.0.5",
"tweetnacl": "^1.0.3",
"ws": "^7.3.1"
},
"dependencies": {
"ws": {
"version": "7.4.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.1.tgz",
"integrity": "sha512-pTsP8UAfhy3sk1lSk/O/s4tjD0CRwvMnzvwr4OKGX7ZvqZtUyx4KIJB5JWbkykPoc55tixMGgTNoh3k4FkNGFQ=="
}
}
},
"engine.io-client": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-4.0.4.tgz",
"integrity": "sha512-and4JRvjv+BQ4WBLopYUFePxju3ms3aBRk0XjaLdh/t9TKv2LCKtKKWFRoRzIfUZsu3U38FcYqNLuXhfS16vqw==",
"requires": {
"base64-arraybuffer": "0.1.4",
"component-emitter": "~1.3.0",
"debug": "~4.1.0",
"engine.io-parser": "~4.0.1",
"has-cors": "1.1.0",
"parseqs": "0.0.6",
"parseuri": "0.0.6",
"ws": "~7.2.1",
"xmlhttprequest-ssl": "~1.5.4",
"yeast": "0.1.2"
}
},
"engine.io-parser": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-4.0.1.tgz",
"integrity": "sha512-v5aZK1hlckcJDGmHz3W8xvI3NUHYc9t8QtTbqdR5OaH3S9iJZilPubauOm+vLWOMMWzpE3hiq92l9lTAHamRCg=="
},
"event-target-shim": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ=="
},
"has-cors": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz",
"integrity": "sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk="
},
"mime-db": {
"version": "1.44.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz",
"integrity": "sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg=="
},
"mime-types": {
"version": "2.1.27",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.27.tgz",
"integrity": "sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w==",
"requires": {
"mime-db": "1.44.0"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node-fetch": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
},
"parseqs": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/parseqs/-/parseqs-0.0.6.tgz",
"integrity": "sha512-jeAGzMDbfSHHA091hr0r31eYfTig+29g3GKKE/PPbEQ65X0lmMwlEoqmhzu0iztID5uJpZsFlUPDP8ThPL7M8w=="
},
"parseuri": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/parseuri/-/parseuri-0.0.6.tgz",
"integrity": "sha512-AUjen8sAkGgao7UyCX6Ahv0gIK2fABKmYjvP4xmy5JaKvcbTRueIqIPHLAfq30xJddqSE033IOMUSOMCcK3Sow=="
},
"prism-media": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.3.tgz",
"integrity": "sha512-fSrR66n0l6roW9Rx4rSLMyTPTjRTiXy5RVqDOurACQ6si1rKHHKDU5gwBJoCsIV0R3o9gi+K50akl/qyw1C74A=="
},
"setimmediate": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
},
"socket.io-client": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-3.0.3.tgz",
"integrity": "sha512-kwCJAKb6JMqE9ZYXg78Dgt8rYLSwtJ/g/LJqpb/pOTFRZMSr1cKAsCaisHZ+IBwKHBY7DYOOkjtkHqseY3ZLpw==",
"requires": {
"@types/component-emitter": "^1.2.10",
"backo2": "1.0.2",
"component-bind": "1.0.0",
"component-emitter": "~1.3.0",
"debug": "~4.1.0",
"engine.io-client": "~4.0.0",
"parseuri": "0.0.6",
"socket.io-parser": "~4.0.1"
}
},
"socket.io-parser": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.0.2.tgz",
"integrity": "sha512-Bs3IYHDivwf+bAAuW/8xwJgIiBNtlvnjYRc4PbXgniLmcP1BrakBoq/QhO24rgtgW7VZ7uAaswRGxutUnlAK7g==",
"requires": {
"@types/component-emitter": "^1.2.10",
"component-emitter": "~1.3.0",
"debug": "~4.1.0"
}
},
"tweetnacl": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="
},
"ws": {
"version": "7.2.5",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.2.5.tgz",
"integrity": "sha512-C34cIU4+DB2vMyAbmEKossWq2ZQDr6QEyuuCzWrM9zfw1sGc0mYiJ0UnG9zzNykt49C2Fi34hvr2vssFQRS6EA=="
},
"xmlhttprequest-ssl": {
"version": "1.5.5",
"resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz",
"integrity": "sha1-wodrBhaKrcQOV9l+gRkayPQ5iz4="
},
"yeast": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz",
"integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk="
}
}
}

View file

@ -1,17 +0,0 @@
{
"name": "libbrainlet",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": "^12.5.1",
"node-fetch": "^2.6.1",
"socket.io-client": "^3.0.3"
}
}