done
This commit is contained in:
commit
dd48c9bc50
|
@ -0,0 +1,21 @@
|
|||
# Rena Client
|
||||
This is a CLI client for Deekchat. It looks super cool.
|
||||
|
||||
## Why
|
||||
nokiaposting.
|
||||
|
||||
## Singular piece of shit screenshot
|
||||
![screenshot](screenshot.png)
|
||||
|
||||
## Installation
|
||||
```sh
|
||||
# install nodejs and npm too lazy to type it out here its 2am
|
||||
# once you got this piece of junk installed run that thing
|
||||
git clone https://git.lolcat.ca/lolcat/rena_client
|
||||
npm install neo-blessed ws node-fetch@v2 form-data he
|
||||
|
||||
# to run just use
|
||||
node client.js
|
||||
|
||||
# ok good night xoxo
|
||||
```
|
|
@ -0,0 +1,674 @@
|
|||
const blessed = require("neo-blessed");
|
||||
|
||||
var screen =
|
||||
blessed.screen({
|
||||
smartCSR: true
|
||||
});
|
||||
|
||||
screen.key(['escape', 'C-c'], function(ch, key) {
|
||||
return process.exit(0);
|
||||
});
|
||||
|
||||
var screen_msg =
|
||||
blessed.message({
|
||||
parent:screen,
|
||||
top:'center',
|
||||
left:'center',
|
||||
height:'shrink',
|
||||
width:'shrink',
|
||||
align:'center',
|
||||
tags:true,
|
||||
hidden:true,
|
||||
border:'line'
|
||||
});
|
||||
|
||||
const fs = require("fs");
|
||||
|
||||
// Read config
|
||||
var config_file = fs.readFileSync("./settings.conf", "utf8");
|
||||
|
||||
config_file = config_file.split("\n");
|
||||
config = {};
|
||||
|
||||
for(i=0; i<config_file.length; i++){
|
||||
|
||||
config_file[i] = config_file[i].trim();
|
||||
|
||||
if(
|
||||
config_file[i] == "" ||
|
||||
config_file[i][0] == "#"
|
||||
){
|
||||
continue;
|
||||
}
|
||||
|
||||
var tmp = config_file[i].split("=");
|
||||
|
||||
config[tmp[0]] = tmp[1];
|
||||
}
|
||||
|
||||
const websocket = require("ws");
|
||||
const fetch = require("node-fetch");
|
||||
const formdata = require("form-data");
|
||||
const he = require("he");
|
||||
|
||||
const emitter = require("events");
|
||||
const deek = new emitter();
|
||||
|
||||
var channels = [];
|
||||
var channel_index = 0;
|
||||
var ws = [];
|
||||
var previous_msg = [];
|
||||
|
||||
var headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0",
|
||||
Origin: "https://deek.chat"
|
||||
};
|
||||
|
||||
/*
|
||||
Helper functions
|
||||
*/
|
||||
function removehtml(html){
|
||||
|
||||
html =
|
||||
he.decode(
|
||||
blessed.escape(html)
|
||||
.replace(
|
||||
/<img title='([^"]*)' src='[^"]+' class='emoji'>/g,
|
||||
"{light-gray-fg}:$1:{/light-gray-fg}"
|
||||
)
|
||||
.replace(
|
||||
/<[^>]+>/ig,
|
||||
""
|
||||
)
|
||||
);
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
/*
|
||||
Websocket functions
|
||||
*/
|
||||
async function send(channel, text){
|
||||
|
||||
if(typeof channel == "object"){
|
||||
|
||||
channel = channel.channel;
|
||||
}
|
||||
|
||||
for(var i=0; i<channels.length; i++){
|
||||
|
||||
if(channels[i].id === channel){
|
||||
|
||||
var arraypos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
channels[arraypos].ws.send(JSON.stringify({
|
||||
type: "messageEnd",
|
||||
data: {
|
||||
message: text
|
||||
}
|
||||
}));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
Handshake
|
||||
*/
|
||||
async function handshake(){
|
||||
|
||||
/*
|
||||
Get cookie
|
||||
*/
|
||||
screen_msg.display("{light-gray-fg}Logging in as {bold}" + config.username + "{/bold}...{/light-gray-fg}");
|
||||
|
||||
const form = new formdata();
|
||||
|
||||
form.append("name", config.username);
|
||||
form.append("password", config.password);
|
||||
form.append("submit", "log+in");
|
||||
|
||||
try{
|
||||
var login = await fetch(
|
||||
"https://deek.chat/login/submit",
|
||||
{
|
||||
method: "POST",
|
||||
redirect: "manual",
|
||||
body: form,
|
||||
headers: headers
|
||||
}
|
||||
);
|
||||
}catch(err){
|
||||
|
||||
deek.emit("error", "Could not connect to Deekchat");
|
||||
return;
|
||||
}
|
||||
|
||||
var cookie = await login.headers.get("set-cookie");
|
||||
|
||||
var api_token = cookie.match(/api_token=([^;]+)/);
|
||||
var session_id = cookie.match(/session_id=([^;]+)/);
|
||||
|
||||
if(
|
||||
api_token === null ||
|
||||
session_id === null
|
||||
){
|
||||
|
||||
deek.emit("error", "Could not get api_token or session_id!!");
|
||||
return;
|
||||
}
|
||||
|
||||
headers.cookie = "session_id=" + session_id[1] + "; api_token=" + api_token[1];
|
||||
|
||||
|
||||
/*
|
||||
Scrape channel list
|
||||
*/
|
||||
var subscribed = await fetch(
|
||||
"https://deek.chat/rooms/fetch/subscribed",
|
||||
{
|
||||
method: "GET",
|
||||
headers: headers
|
||||
}
|
||||
);
|
||||
|
||||
var res = await subscribed.buffer();
|
||||
res = JSON.parse(res.toString("utf8"));
|
||||
|
||||
shittierloop:
|
||||
for(var i=0; i<res.length; i++){
|
||||
|
||||
for(var k=0; k<channels.length; k++){
|
||||
|
||||
if(channels[k].id === res[i].room.id){
|
||||
|
||||
continue shittierloop;
|
||||
}
|
||||
}
|
||||
|
||||
channels.push({
|
||||
name: res[i].room.name,
|
||||
id: res[i].room.id,
|
||||
users: []
|
||||
});
|
||||
}
|
||||
|
||||
var items = [];
|
||||
var item_map = [];
|
||||
for(var i=0; i<channels.length; i++){
|
||||
|
||||
items.push(channels[i].name + " (id:" + channels[i].id + ")");
|
||||
item_map.push(channels[i].id);
|
||||
}
|
||||
|
||||
var list =
|
||||
blessed.list({
|
||||
parent:screen,
|
||||
label:'{bold}{cyan-fg}Pick a channel{/cyan-fg}{/bold}',
|
||||
tags:true,
|
||||
keys:true,
|
||||
border:'line',
|
||||
scrollbar:{
|
||||
ch:'',
|
||||
track:{
|
||||
bg:'cyan'
|
||||
},
|
||||
style:{
|
||||
inverse:true
|
||||
}
|
||||
},
|
||||
style:{
|
||||
item:{
|
||||
hover:{
|
||||
bg:'blue'
|
||||
}
|
||||
},
|
||||
selected:{
|
||||
bg:'blue',
|
||||
bold:true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
list.setItems(items);
|
||||
list.focus();
|
||||
screen.render();
|
||||
|
||||
list.on("select", async function(element, selected){
|
||||
|
||||
screen.remove(list);
|
||||
screen_msg.display("{light-gray-fg}Connecting to {bold}#" + items[selected] + "{/bold}{/light-gray-fg}");
|
||||
|
||||
/*
|
||||
Scrape users
|
||||
*/
|
||||
var users = await fetch(
|
||||
"https://deek.chat/users/" + item_map[selected],
|
||||
{
|
||||
method: "GET",
|
||||
headers: headers
|
||||
}
|
||||
);
|
||||
|
||||
var res = await users.buffer();
|
||||
res = JSON.parse(res.toString("utf8"));
|
||||
|
||||
if(res === null){
|
||||
|
||||
res = [];
|
||||
}
|
||||
|
||||
for(var k=0; k<res.length; k++){
|
||||
|
||||
channels[selected].users.push({
|
||||
name: res[k].name,
|
||||
id: res[k].id,
|
||||
phoneposter: res[k].isMobile,
|
||||
country: {
|
||||
name: res[k].countryName,
|
||||
code: res[k].countryIso.toUpperCase()
|
||||
},
|
||||
picture: res[k].profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + res[k].profilePicture
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
Get previous messages
|
||||
*/
|
||||
previous_msg = await fetch(
|
||||
"https://deek.chat/message/fetch/" + item_map[selected],
|
||||
{
|
||||
method: "GET",
|
||||
headers: headers
|
||||
}
|
||||
);
|
||||
|
||||
previous_msg = await previous_msg.buffer();
|
||||
previous_msg = JSON.parse(previous_msg.toString("utf8"));
|
||||
channel_index = item_map[selected];
|
||||
|
||||
/*
|
||||
Connect to websocket serbers
|
||||
*/
|
||||
|
||||
channels[selected].ws = new websocket(
|
||||
"wss://deek.chat/ws/" + item_map[selected],
|
||||
{
|
||||
protocolVersion: 13,
|
||||
encoding: "utf8",
|
||||
headers: headers
|
||||
}
|
||||
);
|
||||
|
||||
channels[selected].ws.once("open", function(){
|
||||
|
||||
deek.emit("login", channels[selected]);
|
||||
});
|
||||
|
||||
channels[selected].ws.once("close", function(){
|
||||
|
||||
deek.emit("close", channels[selected]);
|
||||
});
|
||||
|
||||
channels[selected].ws.on("message", function(message, isbin){
|
||||
|
||||
if(isbin){ return; }
|
||||
|
||||
var m = JSON.parse(message.toString("utf8"));
|
||||
|
||||
if(typeof m.type == "undefined"){
|
||||
return;
|
||||
}
|
||||
|
||||
switch(m.type){
|
||||
|
||||
case "messageEnd":
|
||||
for(var k=0; k<m.data.message.mentions.length; k++){
|
||||
|
||||
m.data.message.mentions[k].id = m.data.message.mentions[k].userId;
|
||||
delete m.data.message.mentions[k].userId;
|
||||
}
|
||||
|
||||
for(var k=0; k<m.data.message.replies.length; k++){
|
||||
|
||||
m.data.message.replies[k].id = m.data.message.replies[k].userId;
|
||||
m.data.message.replies[k].message = m.data.message.replies[k].replyMessageId;
|
||||
delete m.data.message.replies[k].userId;
|
||||
delete m.data.message.replies[k].replyMessageId;
|
||||
}
|
||||
|
||||
m.data.message.files = m.data.message.files === null ? [] : m.data.message.files;
|
||||
var files = [];
|
||||
|
||||
for(var k=0; k<m.data.message.files.length; k++){
|
||||
|
||||
files.push("https://deek.chat/storage/files/" + m.data.message.files[k].name);
|
||||
}
|
||||
|
||||
deek.emit(
|
||||
"message",
|
||||
{
|
||||
text: removehtml(m.data.message.text),
|
||||
id: m.data.message.id,
|
||||
files: files,
|
||||
mentions: m.data.message.mentions,
|
||||
replies: m.data.message.replies,
|
||||
channel: m.roomId
|
||||
},
|
||||
{
|
||||
name: m.data.message.name,
|
||||
id: m.userId,
|
||||
picture: m.data.message.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.data.message.profilePicture
|
||||
}
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
case "files":
|
||||
|
||||
m.message.files = m.message.files === null ? [] : m.message.files;
|
||||
var files = [];
|
||||
|
||||
for(var k=0; k<m.message.files.length; k++){
|
||||
|
||||
files.push("https://deek.chat/storage/files/" + m.message.files[k].name);
|
||||
}
|
||||
|
||||
deek.emit(
|
||||
"message",
|
||||
{
|
||||
text: removehtml(m.message.text),
|
||||
id: m.message.id,
|
||||
files: files,
|
||||
mentions: m.message.mentions,
|
||||
replies: m.message.replies,
|
||||
channel: m.roomId
|
||||
},
|
||||
{
|
||||
name: m.message.name == "" ? null : m.message.name,
|
||||
id: m.userId,
|
||||
picture: m.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.profilePicture
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
case "enter":
|
||||
var payload = {
|
||||
name: m.name,
|
||||
id: m.id,
|
||||
phoneposter: m.isMobile,
|
||||
country: {
|
||||
name: m.countryName,
|
||||
code: m.countryIso.toUpperCase()
|
||||
},
|
||||
picture: m.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + m.profilePicture
|
||||
};
|
||||
|
||||
channels[selected].users.push(payload);
|
||||
|
||||
deek.emit(
|
||||
"enter",
|
||||
payload
|
||||
);
|
||||
break;
|
||||
|
||||
case "exit":
|
||||
var payload = {
|
||||
name: m.name,
|
||||
id: m.id,
|
||||
phoneposter: null,
|
||||
picture: null,
|
||||
country: {
|
||||
name: null,
|
||||
code: null
|
||||
}
|
||||
}
|
||||
|
||||
for(var i=0; i<channels[selected].users.length; i++){
|
||||
|
||||
if(channels[selected].users[i].id == m.id){
|
||||
|
||||
payload = channels[selected].users[i];
|
||||
channels[selected].users.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
deek.emit(
|
||||
"exit",
|
||||
payload
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
//console.warn(m);
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
User defined FUN-ctions!!!
|
||||
*/
|
||||
function appendmessage(msg, user, render = true){
|
||||
|
||||
var filetext = "";
|
||||
|
||||
for(var i=0; i<msg.files.length; i++){
|
||||
|
||||
if(i === 0){
|
||||
|
||||
filetext += "\n{light-blue-fg}";
|
||||
}else{
|
||||
|
||||
filetext += "\n";
|
||||
}
|
||||
|
||||
filetext += msg.files[i];
|
||||
}
|
||||
|
||||
messagelist.pushLine(
|
||||
"{bold}{red-fg}<" + blessed.escape(user.name) + ">{/red-fg}{/bold} " +
|
||||
msg.text.trim()
|
||||
.replace(
|
||||
/^>[^>].*/gm,
|
||||
function(match){
|
||||
return "{light-green-fg}" + match + "{/light-green-fg}"
|
||||
}
|
||||
)
|
||||
.replace(
|
||||
/^<[^<].*/gm,
|
||||
function(match){
|
||||
return "{light-red-fg}" + match + "{/light-red-fg}"
|
||||
}
|
||||
) +
|
||||
filetext
|
||||
);
|
||||
|
||||
if(render){
|
||||
messagelist.setScrollPerc(100);
|
||||
screen.render();
|
||||
}
|
||||
}
|
||||
|
||||
deek.on("login", function(channel){
|
||||
|
||||
messagelist =
|
||||
blessed.box({
|
||||
parent:screen,
|
||||
label:'{bold}{cyan-fg}#' + channel.name + '{/cyan-fg}{/bold}',
|
||||
tags:true,
|
||||
border:'line',
|
||||
width:"100%",
|
||||
top:0,
|
||||
left:0,
|
||||
bottom:1,
|
||||
scrollable:true,
|
||||
scrollbar:{
|
||||
ch:'',
|
||||
track:{
|
||||
bg:'cyan'
|
||||
},
|
||||
style:{
|
||||
inverse:true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var input =
|
||||
blessed.textarea({
|
||||
parent:screen,
|
||||
bottom:0,
|
||||
height:1,
|
||||
inputOnFocus:true
|
||||
});
|
||||
|
||||
/*
|
||||
Append messages to list
|
||||
*/
|
||||
for(var i=0; i<previous_msg.length; i++){
|
||||
|
||||
for(var k=0; k<previous_msg[i].messages.length; k++){
|
||||
|
||||
var files = [];
|
||||
|
||||
for(var w=0; w<previous_msg[i].messages[k].files.length; w++){
|
||||
|
||||
files.push(
|
||||
"https://deek.chat/storage/files/" + previous_msg[i].messages[k].files[w].name
|
||||
);
|
||||
}
|
||||
|
||||
appendmessage(
|
||||
{
|
||||
text: removehtml(previous_msg[i].messages[k].text),
|
||||
id: previous_msg[i].messages[k].id,
|
||||
files: files,
|
||||
mentions: previous_msg[i].messages[k].mentions,
|
||||
replies: previous_msg[i].messages[k].replies,
|
||||
channel: channel_index
|
||||
},
|
||||
{
|
||||
name: previous_msg[i].messages[k].user.name,
|
||||
id: previous_msg[i].messages[k].user.id,
|
||||
picture: previous_msg[i].messages[k].user.profilePicture == "" ? null : "https://deek.chat/storage/profilePictures/" + previous_msg[i].messages[k].user.profilePicture
|
||||
},
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
messagelist.pushLine("{light-gray-fg} * Connected to channel " + channel.name + " (id:" + channel.id + "){/light-gray-fg}");
|
||||
|
||||
input.focus();
|
||||
messagelist.setScrollPerc(100);
|
||||
screen.render();
|
||||
|
||||
input.key(['up', 'down'], function(ch, key){
|
||||
|
||||
if(key.name == "up"){
|
||||
|
||||
messagelist.scroll(-1);
|
||||
}else{
|
||||
|
||||
messagelist.scroll(1);
|
||||
}
|
||||
screen.render();
|
||||
});
|
||||
|
||||
input.key(['escape', 'C-c'], function(ch, key) {
|
||||
return process.exit(0);
|
||||
});
|
||||
|
||||
input.key("enter", async function(){
|
||||
|
||||
var sendmessage = this.getValue().trim();
|
||||
if(sendmessage == ""){
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var check = false;
|
||||
if(sendmessage[0] == "/"){
|
||||
|
||||
var cmd = sendmessage.split(" ")[0];
|
||||
|
||||
switch(cmd){
|
||||
|
||||
case "/help":
|
||||
|
||||
messagelist.pushLine("local command => {bold}/help{/bold}\n{light-gray-fg} * Client side commands:\n * /help\n * /list\n * /exit{/light-gray-fg}");
|
||||
check = true;
|
||||
break;
|
||||
|
||||
case "/list":
|
||||
|
||||
var users = "";
|
||||
for(var i=0; i<channel.users.length; i++){
|
||||
|
||||
if(i !== 0){
|
||||
|
||||
users += ", ";
|
||||
}
|
||||
|
||||
users += channel.users[i].name + " (" + channel.users[i].country.name + ")";
|
||||
}
|
||||
|
||||
messagelist.pushLine("local command => {bold}/list{/bold}\n{light-gray-fg} * There are " + i + " deekers online:\n * " + users + "{/light-gray-fg}");
|
||||
|
||||
check = true;
|
||||
break;
|
||||
|
||||
case "/exit":
|
||||
process.exit(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(check === false){
|
||||
send(channel.id, sendmessage);
|
||||
}
|
||||
|
||||
this.clearValue();
|
||||
messagelist.setScrollPerc(100);
|
||||
screen.render();
|
||||
});
|
||||
});
|
||||
|
||||
deek.on("enter", async function(user){
|
||||
|
||||
messagelist.pushLine("{light-gray-fg} * {bold}" + blessed.escape(user.name) + "{/bold} from " + user.country.name + " has joined{/light-gray-fg}");
|
||||
messagelist.setScrollPerc(100);
|
||||
screen.render();
|
||||
});
|
||||
|
||||
deek.on("exit", async function(user){
|
||||
|
||||
messagelist.pushLine("{light-gray-fg} * {bold}" + blessed.escape(user.name) + "{/bold} has left{/light-gray-fg}");
|
||||
messagelist.setScrollPerc(100);
|
||||
screen.render();
|
||||
});
|
||||
|
||||
deek.on("message", async function(msg, user){
|
||||
|
||||
appendmessage(msg, user);
|
||||
});
|
||||
|
||||
deek.on("close", async function(channel){
|
||||
|
||||
messagelist.pushLine("{light-red-fg}It's over. Disconnected from channel " + channel.name + " (id:" + channel.id + "){/light-red-fg}");
|
||||
messagelist.setScrollPerc(100);
|
||||
screen.render();
|
||||
});
|
||||
|
||||
deek.on("error", async function(message){
|
||||
|
||||
screen_msg.display("{light-red-fg}{bold}Serber error{/bold}\n" + message + ".\nUse CTRL+C to exit{/light-red-fg}");
|
||||
screen.render();
|
||||
});
|
||||
|
||||
// connect to serber
|
||||
handshake();
|
Binary file not shown.
After Width: | Height: | Size: 359 KiB |
|
@ -0,0 +1,6 @@
|
|||
# Rena Client configuartion file
|
||||
# Now with 100% less accidently commited passwords
|
||||
# Create an account by visiting https://deek.chat
|
||||
|
||||
username=your_user_name_here
|
||||
password=your_password_here
|
Loading…
Reference in New Issue