-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
126 lines (123 loc) · 2.83 KB
/
main.js
File metadata and controls
126 lines (123 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const config = require("./config.json")
const Client = require("./sdk");
const blessed = require("blessed");
const client = new Client(config.instance);
const util = require("util");
function splitLongStringToArray(inputString, maxLength = 48) {
const words = inputString.split(' ');
const result = [];
let currentLine = '';
words.forEach(word => {
if (currentLine.length + word.length + 1 > maxLength) {
result.push(currentLine.trim());
currentLine = word + ' ';
} else {
currentLine += word + ' ';
}
});
if (currentLine) {
result.push(currentLine.trim());
}
return result;
}
let activeChannel = null;
const screen = blessed.screen({
smartCSR: true
})
const style = {
border: {
type: 'line',
},
tags: true,
keys: true,
style: {
border: {
fg: 'grey'
},
focus: {
fg: 'white'
},
selected: {
bg: 'white',
fg: 'black'
}
}
}
const channelsList = blessed.list({
height: '100%',
width: '15%',
...style
});
channelsList.on("select", async data => {
data = data.getText();
if(!data.startsWith("#")) return;
const messages = await client.fetchMessages(client.index[channelsList.getItemIndex(data)]);
activeChannel = client.index[channelsList.getItemIndex(data)]
messagesBox.setContent('');
messages.forEach(m => {
splitLongStringToArray(m.content).forEach(c => messagesBox.add(`${m.author_id}: ${c}`))
})
screen.render();
})
client.on("MESSAGE_CREATE", m => {
m = m.message;
if(activeChannel == m.channel_id){
splitLongStringToArray(m.content).forEach(c => messagesBox.add(`${m.author_id}: ${c}`))
}
})
screen.key("escape", () => {
process.exit(0);
})
const messagesBox = blessed.log({
left: '15%',
height: '98%',
width: '65%',
...style,
})
const messagebox = blessed.textbox({
height: '6%',
width: '65%',
left: '15%',
top: '95%',
...style
});
client.index = [];
client.on("ready", () => {
channelsList.add("Private");
client.index.push("Private");
client.channels.forEach(c => {
channelsList.add("#" + c.name);
client.index.push(c.mention);
})
client.guilds.forEach(g => {
client.index.push(g.name);
channelsList.add(g.name);
g.channels.forEach(c => {
channelsList.add("#" + c.name)
client.index.push(c.mention);
})
})
screen.render();
})
channelsList.key('right', () => {
messagebox.focus()
messagebox.readInput(() => {
client.sendTextMessage(activeChannel,messagebox.getValue());
messagebox.clearValue();
})
})
messagebox.key('left', ()=>{
channelsList.focus();
})
const membersBox = blessed.list({
left: '85%',
height: '100%',
width: '15%',
...style
})
screen.append(channelsList)
screen.append(messagesBox);
screen.append(membersBox);
screen.append(messagebox);
client.login(config.token);
screen.render();