1
0
mirror of https://github.com/fazo96/telecommander.git synced 2025-01-10 11:34:20 +01:00

we now have panels and the ability to comfortably write messages

This commit is contained in:
Enrico Fasoli 2015-08-29 02:09:03 +00:00
parent 773803b9bb
commit 378fe7f68d

View File

@ -24,6 +24,21 @@ screen.title = "Telecommander"
var defaultStyle = { var defaultStyle = {
fg: 'white', fg: 'white',
border: { fg: 'gray' }, border: { fg: 'gray' },
scrollbar: {
bg: 'blue',
fg: 'red'
}
}
function mkBox(){
return blessed.log({
right: 0,
width: '80%',
height: screen.height-3,
border: { type: 'line' },
scrollable: true,
style: defaultStyle
})
} }
var chats = blessed.list({ var chats = blessed.list({
@ -35,15 +50,7 @@ var chats = blessed.list({
mouse: true, mouse: true,
style: defaultStyle, style: defaultStyle,
}) })
chats.style.selected = { bg: 'black' } chats.style.selected = { bg: 'blue' }
var msgs = blessed.log({
right: 0,
width: '80%',
height: screen.height-3,
border: { type: 'line' },
style: defaultStyle
})
var cmdline = blessed.textbox({ var cmdline = blessed.textbox({
inputOnFocus: true, inputOnFocus: true,
@ -55,18 +62,21 @@ var cmdline = blessed.textbox({
style: defaultStyle style: defaultStyle
}) })
screen.append(chats); var msgBox = { "Status": mkBox() }
screen.append(msgs);
screen.append(cmdline); screen.append(chats);
screen.append(cmdline);
screen.append(msgBox["Status"]);
var msgBox = { }
var contacts = { } var contacts = { }
var client,phone,code,phoneCodeHash,fullName,username,loginResult,uid,authKey var client,phone,code,phoneCodeHash,fullName,username,loginResult,uid,authKey
var registered = false var registered = false
var selectedUser = "Status"
function command(cmd){ function command(cmd){
cmdname = cmd.split(' ')[0] cmdl = cmd.split(' ')
cmdname = cmdl[0]
if(cmdname === 'phone'){ if(cmdname === 'phone'){
phone = cmd.split(' ')[1] phone = cmd.split(' ')[1]
@ -86,7 +96,6 @@ function command(cmd){
}) })
} else if(cmdname === 'code'){ } else if(cmdname === 'code'){
cmdl = cmd.split(' ')
code = cmdl[1] code = cmdl[1]
name = cmdl[2] name = cmdl[2]
lastname = cmdl[3] lastname = cmdl[3]
@ -103,16 +112,43 @@ function command(cmd){
} else if(cmdname === 'init'){ } else if(cmdname === 'init'){
whenReady() whenReady()
} else if(cmdname === 'msg'){
var peer = new telegramLink.type.InputPeerContact({ props: { user_id: selectedUser} })
var randid = parseInt(Math.random() * 1000000000)
client.messages.sendMessage(peer,cmdl[1],randid,function(sent){
log('Send message:',cmdl[1],'to:',selectedUser+':',sent.toPrintable())
})
} }
} }
chats.addItem('Status')
chats.on('select',function(selected){
log('SELECT:',selected.content)
msgBox[selectedUser].hide()
selectedUser = selected.content;
//if(!isNaN(selectedUser)){ // Actual user, not utility window
if(!msgBox[selectedUser]){
msgBox[selectedUser] = mkBox()
screen.append(msgBox[selectedUser])
}
msgBox[selectedUser].show()
})
cmdline.on('submit',function(value){ cmdline.on('submit',function(value){
msgs.add('[ECHO] '+value) msgBox[selectedUser].add('[ECHO] '+value)
if(selectedUser == "Status"){
command(value) command(value)
} else {
// Send Message
var peer = new telegramLink.type.InputPeerContact({ props: { user_id: selectedUser} })
var randid = parseInt(Math.random() * 1000000000)
client.messages.sendMessage(peer,value,randid,function(sent){
log('Send message:',value,'to:',selectedUser+':',sent.toPrintable())
msgBox[selectedUser].add('You: '+value)
})
}
cmdline.clearValue() cmdline.clearValue()
cmdline.focus() cmdline.focus()
}) })
cmdline.focus() cmdline.focus()
cmdline.key(['escape','C-c'], function(ch,key){ cmdline.key(['escape','C-c'], function(ch,key){
if(client){ if(client){
@ -122,12 +158,13 @@ cmdline.key(['escape','C-c'], function(ch,key){
}) })
} else process.exit(0); } else process.exit(0);
}); });
//cmdline.focus()
screen.render(); screen.render();
function log(){ function log(){
args = Array.prototype.slice.call(arguments) args = Array.prototype.slice.call(arguments)
msg = args.join(' ') msg = args.join(' ')
msgs.add(msg) msgBox["Status"].add(msg)
logger.info(msg) logger.info(msg)
} }
@ -178,11 +215,19 @@ function whenReady(){
function downloadData(){ function downloadData(){
log('Downloading data...') log('Downloading data...')
client.contacts.getContacts('',function(cont){ client.contacts.getContacts('',function(cont){
contacts = cont //log('\nContacts:\n',JSON.stringify(cont)+'\n')
log('\nContacts:\n',JSON.stringify(cont)+'\n') chats.clearItems()
chats.add("Status")
cont.users.list.forEach(function(user,index){
contacts[user.id] = user
chats.addItem(''+user.id)
log('Added user: '+user.id)
})
fs.writeFile(cfgDir+'contacts.json',JSON.stringify(cont.users.list[0]))
}) })
client.messages.getDialogs(0,-1,10,function(dialogs){ client.messages.getDialogs(0,-1,10,function(dialogs){
log('\nDialogs:\n',JSON.stringify(dialogs)+'\n') //log('\nDialogs:\n',JSON.stringify(dialogs)+'\n')
fs.writeFile(cfgDir+'dialogs.json',JSON.stringify(dialogs))
}) })
} }