initial rewrite commit

no functionality besides rc file loading and printing token
This commit is contained in:
Cynthia Foxwell 2023-05-31 20:16:58 -06:00
commit 7152ea59fa
5 changed files with 165 additions and 0 deletions

52
README.md Normal file
View file

@ -0,0 +1,52 @@
# comcord (`rewrite-go`)
A CLI-based client for Discord inspired by [SDF](https://sdf.org)'s [commode](https://sdf.org/?tutorials/comnotirc).
## Why?
1. All CLI/TUI Discord clients are outdated/unmaintained or have flaws.
2. I've been spending more time in commode on SDF and have been accustomed to the experience.
## Usage
TODO
## Rewrite Design Decisions
Go is more portable than Node.js
## TODO
- [ ] Send mode
- [ ] Commands
- [ ] Quit (q)
- [ ] Switch guilds (G)
- [ ] Switch channels (g)
- [ ] List online users in guild (w)
- [ ] Emote (e)
- Just sends message surrounded in `*`'s
- [ ] Finger (f)
- Shows presence data if available
- Creation date, join date, ID, etc
- [ ] Room history (r)
- [ ] Extended room history (R)
- [ ] List channels (l)
- [ ] List guilds (L)
- [ ] Clear (c)
- [ ] Surf channels forwards (>)
- [ ] Surf channels backwards (<)
- [ ] AFK toggle (A)
- [ ] Send DM (s)
- [ ] Answer DM (a)
- [ ] Message Receiving
- Markdown styling
- [ ] Emotes
- [ ] Timestamp parsing
- [ ] Mentions parsing
- [ ] Embeds in the style of commode's posted links
- [ ] Messages wrapped in `*`'s or `_`'s parsed as emotes
- [ ] Inline DMs to replicate commode's private messages
- [ ] Replies
- [ ] Group DMs
- [ ] Message sending
- [ ] Puts incoming messages into queue whilst in send mode
- [ ] Configuration
- [ ] Write token from argv into rc file if rc file doesn't exist
- [ ] Default guild/channel
- [ ] Threads
- [ ] External rich presence when using bot accounts

10
go.mod Normal file
View file

@ -0,0 +1,10 @@
module github.com/Cynosphere/comcord
go 1.20
require (
github.com/bwmarrin/discordgo v0.27.1 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
)

12
go.sum Normal file
View file

@ -0,0 +1,12 @@
github.com/bwmarrin/discordgo v0.27.1 h1:ib9AIc/dom1E/fSIulrBwnez0CToJE113ZGt4HoliGY=
github.com/bwmarrin/discordgo v0.27.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

44
main.go Normal file
View file

@ -0,0 +1,44 @@
package main
import (
"fmt"
"os"
"strings"
"github.com/bwmarrin/discordgo"
)
func main() {
var config map[string]string = make(map[string]string)
var token string
homeDir, homeErr := os.UserHomeDir()
if homeErr != nil {
panic(homeErr)
}
RCPATH := GetRCPath()
_, rcErr := os.Stat(RCPATH)
if !os.IsNotExist(rcErr) {
fmt.Printf("%% Reading %s ...\n", strings.Replace(RCPATH, homeDir, "~", 1))
config = LoadRCFile()
}
if len(os.Args) > 1 {
token = os.Args[1]
if os.IsNotExist(rcErr) {
fmt.Println("% Writing token to ~/.comcordrc")
config["token"] = token
SaveRCFile(config)
}
} else {
configToken, tokenInConfig := config["token"]
if tokenInConfig {
token = configToken
} else {
fmt.Println("No token provided.")
os.Exit(1)
}
}
fmt.Println(token)
}

47
rcfile.go Normal file
View file

@ -0,0 +1,47 @@
package main
import (
"os"
"path/filepath"
"strings"
)
func GetRCPath() string {
homeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
return filepath.Join(homeDir, ".comcordrc")
}
func LoadRCFile() map[string]string {
config := make(map[string]string)
file, err := os.ReadFile(GetRCPath())
if err != nil {
panic(err)
}
lines := strings.Split(string(file), "\n")
for _, line := range lines {
kvs := strings.Split(line, "=")
if len(kvs) == 2 {
config[kvs[0]] = kvs[1]
}
}
return config
}
func SaveRCFile(config map[string]string) {
out := ""
for key, value := range config {
out = out + key + "=" + value + "\n"
}
err := os.WriteFile(GetRCPath(), []byte(out), 0644)
if err != nil {
panic(err)
}
}