Archived
0
0
Fork 0

feat: added ability to send messages

This commit is contained in:
Daryl Ronningen 2021-12-29 22:10:13 -08:00
parent c066b13446
commit 71ae08bf10
Signed by: Daryl Ronningen
GPG key ID: FD23F0C934A5EC6B

View file

@ -147,17 +147,38 @@ const userListList = blessed.list({
},
});
const messageBoxInput = blessed.textarea({
const messageBoxForm = blessed.form({
parent: messageBox,
top: 0,
left: 0,
width: '99%',
width: '98%',
height: '87%',
mouse: true,
});
const messageBoxInput = blessed.textarea({
parent: messageBoxForm,
top: 0,
left: 0,
width: '90%',
height: '87%',
keys: true,
vi: true,
mouse: true,
});
const messageBoxSubmit = blessed.button({
parent: messageBoxForm,
top: 0,
left: '95%',
width: '4%',
height: '87%',
keys: true,
vi: true,
mouse: true,
content: 'Send',
});
screen.append(mainWindow);
const client = new Client({
@ -199,8 +220,7 @@ serverListList.on('select', (item) => {
channelListList.on('select', async (item) => {
chatBoxList.clearItems();
const findGuild = await client.guilds.fetch(currentSelectedGuild);
const findChannel = findGuild.channels.cache.find((val) => val.name === item.content);
const findChannel = client.channels.cache.find((val) => val.isText() && val.type === 'GUILD_TEXT' && val.name === item.content);
if (findChannel) {
currentSelectedChannel = findChannel.id;
@ -216,11 +236,25 @@ channelListList.on('select', async (item) => {
}
}
chatBoxList.scrollTo(100);
chatBoxList.setScrollPerc(100);
chatBoxList.select(100);
screen.render();
});
messageBoxSubmit.on('press', async () => {
const findChannel = await client.channels.fetch(currentSelectedChannel);
if (findChannel && findChannel.isText()) {
const msg = await findChannel.send(messageBoxInput.value);
chatBoxList.addItem(`${new Date(msg.createdTimestamp).toISOString()} (${msg.author.username}#${msg.author.discriminator}) | ${msg.content}`);
chatBoxList.setScrollPerc(100);
messageBoxInput.setValue('');
}
screen.render();
});
screen.key('S-q', () => {
process.exit(0);
@ -246,6 +280,10 @@ screen.key('S-m', () => {
messageBoxInput.focus();
});
screen.key('S-r', () => {
messageBoxSubmit.focus();
});
serverListList.focus();
screen.render();