|
|
|
|
@@ -10,14 +10,16 @@ import (
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type textHandler struct{}
|
|
|
|
|
type waMsg struct {
|
|
|
|
|
Wid string
|
|
|
|
|
Text string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var VERSION string = "v0.4.1"
|
|
|
|
|
|
|
|
|
|
var sendChannel chan waMsg
|
|
|
|
|
var textChannel chan whatsapp.TextMessage
|
|
|
|
|
var contactChannel chan whatsapp.Contact
|
|
|
|
|
|
|
|
|
|
var sndTxt string = ""
|
|
|
|
|
var currentReceiver string = ""
|
|
|
|
|
@@ -25,6 +27,8 @@ var textView *tview.TextView
|
|
|
|
|
var treeView *tview.TreeView
|
|
|
|
|
var textInput *tview.InputField
|
|
|
|
|
var topBar *tview.TextView
|
|
|
|
|
|
|
|
|
|
//var infoBar *tview.TextView
|
|
|
|
|
var connection *whatsapp.Conn
|
|
|
|
|
var msgStore messages.MessageDatabase
|
|
|
|
|
|
|
|
|
|
@@ -68,7 +72,11 @@ func main() {
|
|
|
|
|
|
|
|
|
|
topBar = tview.NewTextView()
|
|
|
|
|
topBar.SetDynamicColors(true)
|
|
|
|
|
topBar.SetText("[::b] WhatsCLI v0.2.1 [-][::d]Help: /name NewName = name current contact | /quit = exit app | /load = reload contacts | <Tab> = switch input/contacts | <Up/Dn> = scroll history")
|
|
|
|
|
topBar.SetText("[::b] WhatsCLI " + VERSION + " [-::d]Help: /name NewName | /addname 123456 NewName | /quit | <Tab> = contacts/message | <Up/Dn> = scroll")
|
|
|
|
|
|
|
|
|
|
//infoBar = tview.NewTextView()
|
|
|
|
|
//infoBar.SetDynamicColors(true)
|
|
|
|
|
//infoBar.SetText("🔋: ??%")
|
|
|
|
|
|
|
|
|
|
textView = tview.NewTextView().
|
|
|
|
|
SetDynamicColors(true).
|
|
|
|
|
@@ -78,6 +86,8 @@ func main() {
|
|
|
|
|
app.Draw()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
fmt.Fprint(textView, "[::b]WhatsCLI "+VERSION+"\n\n[-][-::u]Commands:[-::-]\n/name NewName = name current contact\n/addname number NewName = name by number\n/load = reload contacts\n/quit = exit app\n\n[-::u]Keys:[-::-]\n<Tab> = switch input/contacts\n<Up/Dn> = scroll history")
|
|
|
|
|
|
|
|
|
|
//textView.SetBorder(true)
|
|
|
|
|
|
|
|
|
|
textInput = tview.NewInputField()
|
|
|
|
|
@@ -118,6 +128,7 @@ func main() {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
gridLayout.AddItem(topBar, 0, 0, 1, 4, 0, 0, false)
|
|
|
|
|
//gridLayout.AddItem(infoBar, 0, 0, 1, 1, 0, 0, false)
|
|
|
|
|
gridLayout.AddItem(MakeTree(), 1, 0, 2, 1, 0, 0, false)
|
|
|
|
|
gridLayout.AddItem(textView, 1, 1, 1, 3, 0, 0, false)
|
|
|
|
|
gridLayout.AddItem(textInput, 2, 1, 1, 3, 0, 0, false)
|
|
|
|
|
@@ -148,6 +159,19 @@ func EnterCommand(key tcell.Key) {
|
|
|
|
|
app.Stop()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if strings.Index(sndTxt, "/addname ") == 0 {
|
|
|
|
|
//command
|
|
|
|
|
parts := strings.Split(sndTxt, " ")
|
|
|
|
|
if len(parts) < 3 {
|
|
|
|
|
fmt.Fprint(textView, "\nUse /addname 1234567 NewName")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
messages.SetIdName(parts[1]+messages.CONTACTSUFFIX, strings.TrimPrefix(sndTxt, "/addname "+parts[1]+" "))
|
|
|
|
|
SetDisplayedContact(currentReceiver)
|
|
|
|
|
LoadContacts()
|
|
|
|
|
textInput.SetText("")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if currentReceiver == "" {
|
|
|
|
|
fmt.Fprint(textView, "\nNo recipient set")
|
|
|
|
|
return
|
|
|
|
|
@@ -229,26 +253,6 @@ func SetDisplayedContact(wid string) {
|
|
|
|
|
textView.SetText(msgStore.GetMessagesString(wid))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HandleError implements the handler interface for go-whatsapp
|
|
|
|
|
func (t textHandler) HandleError(err error) {
|
|
|
|
|
// TODO : handle go routine here
|
|
|
|
|
fmt.Fprint(textView, "\nerror in textHandler : %v", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HandleTextMessage implements the text message handler interface for go-whatsapp
|
|
|
|
|
func (t textHandler) HandleTextMessage(msg whatsapp.TextMessage) {
|
|
|
|
|
textChannel <- msg
|
|
|
|
|
if msg.Info.RemoteJid != currentReceiver {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
PrintTextMessage(msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func PrintTextMessage(msg whatsapp.TextMessage) {
|
|
|
|
|
fmt.Fprint(textView, messages.GetTextMessageString(&msg))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// StartTextReceiver starts the handler for the text messages received
|
|
|
|
|
func StartTextReceiver() error {
|
|
|
|
|
var wac = GetConnection()
|
|
|
|
|
@@ -260,6 +264,7 @@ func StartTextReceiver() error {
|
|
|
|
|
wac.AddHandler(handler)
|
|
|
|
|
sendChannel = make(chan waMsg)
|
|
|
|
|
textChannel = make(chan whatsapp.TextMessage)
|
|
|
|
|
contactChannel = make(chan whatsapp.Contact)
|
|
|
|
|
for {
|
|
|
|
|
select {
|
|
|
|
|
case msg := <-sendChannel:
|
|
|
|
|
@@ -268,6 +273,8 @@ func StartTextReceiver() error {
|
|
|
|
|
if msgStore.AddTextMessage(rcvd) {
|
|
|
|
|
app.QueueUpdateDraw(LoadContacts)
|
|
|
|
|
}
|
|
|
|
|
case contact := <-contactChannel:
|
|
|
|
|
messages.SetIdName(contact.Jid, contact.Name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprint(textView, "\n"+"closing the receiver")
|
|
|
|
|
@@ -297,3 +304,88 @@ func SendText(wid string, text string) {
|
|
|
|
|
//fmt.Fprint(textView, "\nSent msg with ID: %v", msgID)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type textHandler struct{}
|
|
|
|
|
|
|
|
|
|
// HandleError implements the handler interface for go-whatsapp
|
|
|
|
|
func (t textHandler) HandleError(err error) {
|
|
|
|
|
// TODO : handle go routine here
|
|
|
|
|
fmt.Fprint(textView, "\nerror in textHandler : %v", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// HandleTextMessage implements the text message handler interface for go-whatsapp
|
|
|
|
|
func (t textHandler) HandleTextMessage(msg whatsapp.TextMessage) {
|
|
|
|
|
textChannel <- msg
|
|
|
|
|
if msg.Info.RemoteJid != currentReceiver {
|
|
|
|
|
//fmt.Print("\a")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
PrintTextMessage(msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func PrintTextMessage(msg whatsapp.TextMessage) {
|
|
|
|
|
fmt.Fprint(textView, messages.GetTextMessageString(&msg))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t textHandler) HandleImageMessage(message whatsapp.ImageMessage) {
|
|
|
|
|
msg := whatsapp.TextMessage{
|
|
|
|
|
Info: whatsapp.MessageInfo{
|
|
|
|
|
RemoteJid: message.Info.RemoteJid,
|
|
|
|
|
SenderJid: message.Info.SenderJid,
|
|
|
|
|
FromMe: message.Info.FromMe,
|
|
|
|
|
Timestamp: message.Info.Timestamp,
|
|
|
|
|
},
|
|
|
|
|
Text: "[IMAGE] " + message.Caption,
|
|
|
|
|
}
|
|
|
|
|
t.HandleTextMessage(msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t textHandler) HandleDocumentMessage(message whatsapp.DocumentMessage) {
|
|
|
|
|
msg := whatsapp.TextMessage{
|
|
|
|
|
Info: whatsapp.MessageInfo{
|
|
|
|
|
RemoteJid: message.Info.RemoteJid,
|
|
|
|
|
SenderJid: message.Info.SenderJid,
|
|
|
|
|
FromMe: message.Info.FromMe,
|
|
|
|
|
Timestamp: message.Info.Timestamp,
|
|
|
|
|
},
|
|
|
|
|
Text: "[DOCUMENT] " + message.Title,
|
|
|
|
|
}
|
|
|
|
|
t.HandleTextMessage(msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t textHandler) HandleVideoMessage(message whatsapp.VideoMessage) {
|
|
|
|
|
msg := whatsapp.TextMessage{
|
|
|
|
|
Info: whatsapp.MessageInfo{
|
|
|
|
|
RemoteJid: message.Info.RemoteJid,
|
|
|
|
|
SenderJid: message.Info.SenderJid,
|
|
|
|
|
FromMe: message.Info.FromMe,
|
|
|
|
|
Timestamp: message.Info.Timestamp,
|
|
|
|
|
},
|
|
|
|
|
Text: "[VIDEO] " + message.Caption,
|
|
|
|
|
}
|
|
|
|
|
t.HandleTextMessage(msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t textHandler) HandleAudioMessage(message whatsapp.AudioMessage) {
|
|
|
|
|
msg := whatsapp.TextMessage{
|
|
|
|
|
Info: whatsapp.MessageInfo{
|
|
|
|
|
RemoteJid: message.Info.RemoteJid,
|
|
|
|
|
SenderJid: message.Info.SenderJid,
|
|
|
|
|
FromMe: message.Info.FromMe,
|
|
|
|
|
Timestamp: message.Info.Timestamp,
|
|
|
|
|
},
|
|
|
|
|
Text: "[AUDIO]",
|
|
|
|
|
}
|
|
|
|
|
t.HandleTextMessage(msg)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t textHandler) HandleNewContact(contact whatsapp.Contact) {
|
|
|
|
|
contactChannel <- contact
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//func (t textHandler) HandleBatteryMessage(msg whatsapp.BatteryMessage) {
|
|
|
|
|
// app.QueueUpdate(func() {
|
|
|
|
|
// infoBar.SetText("🔋: " + string(msg.Percentage) + "%")
|
|
|
|
|
// })
|
|
|
|
|
//}
|
|
|
|
|
|