Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2e7d5d6b7 | ||
|
|
88cc6b09ae | ||
|
|
646fed75a6 | ||
|
|
0b5476a1c8 | ||
|
|
8510dd40ee | ||
|
|
ee5d675f98 | ||
|
|
2a3f53c4c3 | ||
|
|
cc71c296b2 | ||
|
|
b98af9f0c7 | ||
|
|
4fdcd70703 | ||
|
|
f690d798bc | ||
|
|
dd6e4f54b1 |
46
README.md
46
README.md
@@ -27,7 +27,7 @@ Heres some things you might expect to work that don't. Plus some other things I
|
||||
- No automation of messages, no sending of messages through shell commands
|
||||
- FaceBook obviously doesn't endorse or like these kinds of apps and they're likely to break when FaceBook changes stuff in their web app
|
||||
|
||||
## Installation / Usage
|
||||
## Installation
|
||||
|
||||
How to get it running and how to use it
|
||||
|
||||
@@ -52,6 +52,46 @@ Some ways to install via package managers are supported but the installed versio
|
||||
|
||||
- `https://aur.archlinux.org/packages/whatscli/`
|
||||
|
||||
## Usage
|
||||
|
||||
Most information, all commands and key bindings are availabe through the in-app help, simply type `/help` and/or `/commands`.
|
||||
|
||||
### Login
|
||||
|
||||
When starting up, whatscli will immediately try to connect to the WhatsApp server to log in. Keep your phone ready to scan the appearing QR code in WhatsApp on your Phone. If you don't manage to scan the code quick enough just restart the application. If you can not see the whole QR code, reduce the font size of your terminal or increase the window size.
|
||||
|
||||
After scanning the QR code the chats should be populated. After you have done this once, whatscli will be able to log into WhatsApp automatically on start. To log out of WhapsApp completely type `/logout`.
|
||||
|
||||
### Messaging / Commands
|
||||
|
||||
Select a chat on the left and start typing in the input field at the bottom to send messages. Switch between the chat list and the input fiel with `<Tab>`.
|
||||
|
||||
For issuing commands the same input field is used. By default commands are prefixed with `/`. You can for example use the `/sendimage /path/to/file.jpg` command to send images, see `/help` for more commands.
|
||||
|
||||
When paths are given for commands you don't need to surround the path in quotes, even if it contains spaces. Also don't prefix spaces with backslashes (as the copy-paste function of MacOS does for example).
|
||||
|
||||
### Messages
|
||||
|
||||
When pressing `Ctrl-w` (default mapping) you enter "message selection mode" which allows selecting a single message and performing operations on them. For example pressing `o` while a message is selected allows opening any attachments through an external application.
|
||||
|
||||
#### Image display
|
||||
|
||||
You can display images in whatscli using external programs that convert the image to UTF characters. I found that `jp2a` works well for jpeg images, it is available through package managers on most systems. However the "image quality" leaves a lot to be desired. The [PIXterm](https://github.com/eliukblau/pixterm) app allows displaying true-color versions of the images which are quite recognizable already.
|
||||
|
||||
To configure the used command and its parameters edit the `show_command` parameter in `whatscli.config`, see `/help` for the config file location.
|
||||
|
||||
#### Copy-Pasting User IDs
|
||||
|
||||
Some commands such as the `/add` and `/remove` require a "user id" as their input. You can copy the user ID of a selected chat or a selected message to the clipboard with `Ctrl-c` (default mapping) and easily append them to the current input using `Ctrl-v`.
|
||||
|
||||
### Notifications
|
||||
|
||||
The app supports basic desktop notifications through the `gen2brain/beeep` library, to enable it set `enable_notifications = true` in `whatscli.config`. Set `use_terminal_bell = true` to ring your terminal's bell instead of sending a desktop notification.
|
||||
|
||||
### Configuration
|
||||
|
||||
Most key bindings, colors and other options can be configured in the `whatscli.config` file, the `/help` command shows its location.
|
||||
|
||||
## Development
|
||||
|
||||
This app started as my first attempt at writing something in go. Some areas that are marked with `TODO` can still be improved but work mostly. If you want to contribute features or improve the code thats great, send a PR and we can discuss.
|
||||
@@ -71,3 +111,7 @@ Session manager is designed "object like", the MessageDatabase in `messages/stor
|
||||
In `messages/messages.go` most interfaces and data structures for communication are kept.
|
||||
|
||||
The `config/settings.go` keeps a singleton `Config` struct with the config that is loaded via the gopkg.in/ini.v1 library when the app starts. This makes it easy to quickly add new configuration items with default values that can be used across the app.
|
||||
|
||||
## License
|
||||
|
||||
This software is released under MIT license. Remember that this gives you all freedom except for slapping your name on it.
|
||||
|
||||
@@ -25,7 +25,9 @@ type General struct {
|
||||
CmdPrefix string
|
||||
ShowCommand string
|
||||
EnableNotifications bool
|
||||
UseTerminalBell bool
|
||||
NotificationTimeout int64
|
||||
BacklogMsgQuantity int
|
||||
}
|
||||
|
||||
type Keymap struct {
|
||||
@@ -76,7 +78,9 @@ var Config = IniFile{
|
||||
CmdPrefix: "/",
|
||||
ShowCommand: "jp2a --color",
|
||||
EnableNotifications: false,
|
||||
UseTerminalBell: false,
|
||||
NotificationTimeout: 60,
|
||||
BacklogMsgQuantity: 10,
|
||||
},
|
||||
&Keymap{
|
||||
SwitchPanels: "Tab",
|
||||
|
||||
4
main.go
4
main.go
@@ -17,7 +17,7 @@ import (
|
||||
"gitlab.com/tslocum/cbind"
|
||||
)
|
||||
|
||||
var VERSION string = "v1.0.5"
|
||||
var VERSION string = "v1.0.7"
|
||||
|
||||
var sndTxt string = ""
|
||||
var currentReceiver messages.Chat = messages.Chat{}
|
||||
@@ -427,7 +427,7 @@ func PrintCommands() {
|
||||
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"quit [::-]or[::b]", config.Config.Keymap.CommandQuit, "[::-] = Exit app")
|
||||
fmt.Fprintln(textView, "")
|
||||
fmt.Fprintln(textView, "[-::-]Chat[-::-]")
|
||||
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"backlog [::-]or[::b]", config.Config.Keymap.CommandBacklog, "[::-] = load next 10 previous messages")
|
||||
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"backlog [::-]or[::b]", config.Config.Keymap.CommandBacklog, "[::-] = load next", config.Config.General.BacklogMsgQuantity, "previous messages")
|
||||
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"read [::-]or[::b]", config.Config.Keymap.CommandRead, "[::-] = mark new messages in chat as read")
|
||||
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"upload[::-] /path/to/file = Upload any file as document")
|
||||
fmt.Fprintln(textView, "[::b] "+cmdPrefix+"sendimage[::-] /path/to/file = Send image message")
|
||||
|
||||
@@ -89,8 +89,8 @@ func (sm *SessionManager) runManager() error {
|
||||
if int64(msg.Info.Timestamp) > time.Now().Unix()-30 {
|
||||
if int64(msg.Info.Timestamp) > sm.lastSent.Unix()+config.Config.General.NotificationTimeout {
|
||||
sm.db.NewUnreadChat(msg.Info.RemoteJid)
|
||||
if config.Config.General.EnableNotifications && !msg.Info.FromMe {
|
||||
err := beeep.Notify(sm.db.GetIdShort(msg.Info.RemoteJid), msg.Text, "")
|
||||
if !msg.Info.FromMe {
|
||||
err := notify(sm.db.GetIdShort(msg.Info.RemoteJid), msg.Text)
|
||||
if err != nil {
|
||||
sm.uiHandler.PrintError(err)
|
||||
}
|
||||
@@ -101,8 +101,8 @@ func (sm *SessionManager) runManager() error {
|
||||
// notify if message is younger than 30 sec and not in focus
|
||||
if int64(msg.Info.Timestamp) > time.Now().Unix()-30 {
|
||||
sm.db.NewUnreadChat(msg.Info.RemoteJid)
|
||||
if config.Config.General.EnableNotifications && !msg.Info.FromMe {
|
||||
err := beeep.Notify(sm.db.GetIdShort(msg.Info.RemoteJid), msg.Text, "")
|
||||
if !msg.Info.FromMe {
|
||||
err := notify(sm.db.GetIdShort(msg.Info.RemoteJid), msg.Text)
|
||||
if err != nil {
|
||||
sm.uiHandler.PrintError(err)
|
||||
}
|
||||
@@ -279,7 +279,7 @@ func (sm *SessionManager) execCommand(command Command) {
|
||||
sm.uiHandler.PrintText("[" + config.Config.Colors.Negative + "]Unknown command: [-]" + cmd)
|
||||
case "backlog":
|
||||
if sm.currentReceiver != "" {
|
||||
count := 10
|
||||
count := config.Config.General.BacklogMsgQuantity
|
||||
if currentMsgs, ok := sm.db.textMessages[sm.currentReceiver]; ok {
|
||||
if len(currentMsgs) > 0 {
|
||||
firstMsg := currentMsgs[0]
|
||||
@@ -985,3 +985,15 @@ func writeSession(session whatsapp.Session) error {
|
||||
func removeSession() error {
|
||||
return os.Remove(config.GetSessionFilePath())
|
||||
}
|
||||
|
||||
// notify will send a notification via beeep if EnableNotification is true. If
|
||||
// UseTerminalBell is true it will send a terminal bell instead.
|
||||
func notify(title, message string) error {
|
||||
if !config.Config.General.EnableNotifications {
|
||||
return nil
|
||||
} else if config.Config.General.UseTerminalBell {
|
||||
_, err := fmt.Printf("\a")
|
||||
return err
|
||||
}
|
||||
return beeep.Notify(title, message, "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user