From 3173d640b4857b321b377e3ab41e60db3243bf91 Mon Sep 17 00:00:00 2001 From: Sean Hinchee Date: Wed, 26 Dec 2018 19:14:18 -0600 Subject: [PATCH] add all sorts of fixes, factotum support, etc. all thanks to halfwit ? --- TODO | 6 +++--- commands.go | 6 ++++-- config.go | 39 ++++++--------------------------------- main.go | 14 +++++++++++--- 4 files changed, 24 insertions(+), 41 deletions(-) diff --git a/TODO b/TODO index 52cc3a0a3cae01187ba3bd9bee48e8f49dcb687f..d3fcb6c98ccb871b71c06458d0ca383363612128 100644 --- a/TODO +++ b/TODO @@ -16,7 +16,7 @@ Features: * verify proper permissions -rw------- 0600 for discord.cfg -* if ``` entered, allow multi-line message (composition) +* [done] if ``` entered, allow multi-line message (composition) * flag for larger backlog loading @@ -25,7 +25,7 @@ Features: * [done-ish] fix pm's * when opening a pm, drops back to channel dialogue -* aux/statusmsg backgrounds and doesn't steal input +* [done] aux/statusmsg backgrounds and doesn't steal input * fix :m not displaying more than loaded backlog @@ -33,5 +33,5 @@ Features: * add [b] go back to pm's menu from within pm's -* fix :n printing to chat +* [done] fix :n printing to chat diff --git a/commands.go b/commands.go index d79b1183c9a2e76f22081f84f7a7a6fad1d3f666..23f938a3ab340b2602ea66c326cce0264aa59be6 100644 --- a/commands.go +++ b/commands.go @@ -80,7 +80,7 @@ func ParseForCommands(line string) string { Msg(InfoMsg, "Printing last %d messages!\n", Amount) State.RetrieveMessages(Amount) PrintMessages(Amount) - return line + return "" case ":u": session := State.Session user := session.User @@ -88,8 +88,10 @@ func ParseForCommands(line string) string { _, err := State.Session.DiscordGo.UserUpdate(user.Email, session.Password, newName, user.Avatar, "") if err != nil { Msg(ErrorMsg, "[:u] Argument Error: %s\n", err) + return "" } - return line + Msg(TextMsg, "name -> %s\n", newName) + return "" } return line } diff --git a/config.go b/config.go index e43b9702abe9c5c9b064a529e1aec58ad7a44107..d1a4c472be011630620fdd7191d98bb2652de221 100644 --- a/config.go +++ b/config.go @@ -8,16 +8,17 @@ import ( "os" "os/user" // "golang.org/x/crypto/ssh/terminal" + "bitbucket.org/mischief/libauth" ) //Configuration is a struct that contains all configuration fields type Configuration struct { Username string `json:"username"` - Password string `json:"password"` MessageDefault bool `json:"messagedefault"` Messages int `json:"messages"` CompletionChar string `json:"completionchar"` TimeCompChar string `json:"timecompchar"` + password string } // Config is the global configuration of discord-cli @@ -64,34 +65,6 @@ func CreateConfig() { scan.Scan() EmptyStruct.Username = scan.Text() - fmt.Print("Input your password: ") - //password, err := terminal.ReadPassword(0) - - plan9 := true - /* Plan 9 raw mode for rio */ - consctl, err := Rawon() - if err != nil { - fmt.Println("Failed to set rawon") - plan9 = false - } - - password := "" - - if plan9 { - - password = GetCons() - - err = RawOff(consctl) - if err != nil { - fmt.Println("\nFailed to set rawoff") - fmt.Print(err, "\n") - } - } else { - /* Maybe put linux terminal raw mode in here one day */ - fmt.Println("Skipping raw input for Plan 9") - } - - EmptyStruct.Password = string(password) EmptyStruct.Messages = 10 EmptyStruct.MessageDefault = true EmptyStruct.CompletionChar = ">" @@ -131,9 +104,9 @@ func CheckState() { if Config.Username == "" { log.Fatalln("No Username Specified, please edit " + usr.HomeDir + "/lib/disco.cfg") } - - if Config.Password == "" { - log.Fatalln("No Password Specified, please edit " + usr.HomeDir + "/lib/disco.cfg") + userPwd, err := libauth.Getuserpasswd("proto=pass service=discord user=%s server=discordapp.com", Config.Username) + if err != nil { + log.Fatal(err) } - + Config.password = userPwd.Password } diff --git a/main.go b/main.go index 1d63c72546331d1370bb5e628c3eef039e2b344a..0451abf8c4dc505629b037877f2945d17ec80bab 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "bufio" "flag" "fmt" + "io" "log" "os" "regexp" @@ -55,7 +56,7 @@ func main() { Msg(HeaderMsg, "disco version: %s\n\n", Version) //NewSession - Session = DiscordState.NewSession(Config.Username, Config.Password) //Please don't abuse + Session = DiscordState.NewSession(Config.Username, Config.password) //Please don't abuse err := Session.Start() if err != nil { log.Println("Session Failed") @@ -77,7 +78,11 @@ func main() { for { //fmt.Print("> ") //line, _ := rl.Readline() - line, _ := reader.ReadString('\n') + line, err := reader.ReadString('\n') + + if err == io.EOF { + break + } // ``` if strings.HasPrefix(line, "```") { @@ -95,7 +100,10 @@ func main() { continue } - line = line[:len(line)-1] + n := len(line) + if n > 0 { + line = line[:n-1] + } //QUIT if line == ":q" {