From fe06ac115ff581aab969093b71ecac218b3148dd Mon Sep 17 00:00:00 2001 From: Sean Hinchee Date: Mon, 24 Jul 2017 22:12:03 -0500 Subject: [PATCH] cleaning up source --- README.md | 16 +++++++++++-- config.go | 20 ++++++---------- helper.go | 71 +------------------------------------------------------ 3 files changed, 22 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index 7705e4519e5b269f8c3898b54c12b5ffb1f13405..b5d6dfefdfabc092392b67f6856faf79fe675977 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# disco ­ [Discord](https://discord.gg) client for 9Front +# disco: [Discord](https://discord.gg) client for 9Front Hacked up version of theboxmage's [discord-cli](https://github.com/theboxmage/discordcli) -JSON config is in `$home/lib/disco-cfg.json` for setting password, should be made automatically after first run. +JSON config is in `$home/lib//lib/disco.cfg` for setting password, should be made automatically after first run. ## Install @@ -12,6 +12,8 @@ JSON config is in `$home/lib/disco-cfg.json` for setting password, should be mad ## Problems +* You might have to run `mk` or `mk install` twice + * JSON * Does not create accounts for you, this still needs to be done in a browser/app @@ -20,3 +22,13 @@ JSON config is in `$home/lib/disco-cfg.json` for setting password, should be mad * Cutting and pasting text might break things +## Commands +Commands available in chat: + +| Command | Function | +| ------------- |-------------| +| :q | Quits discord-cli | +| :g | Change listening Guild| +| :c | Change listening Channel inside Guild | +| :m [n] | Display last [n] messages: ex. `:m 2` displays last two messages | +| :p | Pulls up the private channel menu | diff --git a/config.go b/config.go index 5193d876e0a95f8da2f8d11e1ef1463a65f3224b..4a4adb580de596dfe302d1115a9a3a5226c7206a 100644 --- a/config.go +++ b/config.go @@ -22,9 +22,9 @@ type Configuration struct { // Config is the global configuration of discord-cli var Config Configuration -//GetConfig retrieves configuration file from ~./config/discord-cli, if it doesn't exist it calls CreateConfig() +//GetConfig retrieves configuration file from $home/lib/disco.cfg, if it doesn't exist it calls CreateConfig() func GetConfig() { - //Get User +//Get User Start: usr, err := user.Current() if err != nil { @@ -32,7 +32,7 @@ Start: } //Get File - file, err := os.Open(usr.HomeDir + "/lib/disco-cfg.json") + file, err := os.Open(usr.HomeDir + "/lib/disco.cfg") if err != nil { log.Println("Creating new config file") CreateConfig() @@ -48,7 +48,7 @@ Start: } } -//CreateConfig creates folder inside $HOME and makes a new empty configuration file +//CreateConfig creates folder inside $home and makes a new empty configuration file func CreateConfig() { //Get User usr, err := user.Current() @@ -69,14 +69,8 @@ func CreateConfig() { EmptyStruct.Messages = 10 EmptyStruct.MessageDefault = true - //Create Folder - err = os.MkdirAll(usr.HomeDir+"/.config/discord-cli/", os.ModePerm) - if err != nil { - log.Fatalln(err) - } - //Create File - file, err := os.Create(usr.HomeDir + "/.config/discord-cli/config.json") + file, err := os.Create(usr.HomeDir + "/lib/disco.cfg") if err != nil { log.Fatalln(err) } @@ -105,11 +99,11 @@ func CheckState() { } if Config.Username == "" { - log.Fatalln("No Username Specified, please edit " + usr.HomeDir + "/.config/discord-cli/config.json") + log.Fatalln("No Username Specified, please edit " + usr.HomeDir + "/lib/disco.cfg") } if Config.Password == "" { - log.Fatalln("No Password Specified, please edit " + usr.HomeDir + "/.config/discord-cli/config.json") + log.Fatalln("No Password Specified, please edit " + usr.HomeDir + "/lib/disco.cfg") } } diff --git a/helper.go b/helper.go index 7458276c2dd3b3d377d5cd5cb6b2c0ac46c87192..10838ebce7fff5abc4ea6d2037a17e1b31ed11da 100644 --- a/helper.go +++ b/helper.go @@ -1,22 +1,17 @@ package main import ( -// "encoding/binary" "log" -// "math" "os" "os/exec" "strings" "time" "fmt" - -// "bitbucket.org/henesy/disco/color" "bitbucket.org/henesy/disco/DiscordGo" ) //HexColor is a struct gives RGB values type HexColor struct { -// Color color.Attribute R int G int B int @@ -24,35 +19,11 @@ type HexColor struct { //Msg is a composition of Color.New printf functions func Msg(MsgType, format string, a ...interface{}) { - - // TODO: Add support for changing color by configuration - -/* Error := color.New(color.FgRed, color.Bold) - Info := color.New(color.FgYellow, color.Bold) - Head := color.New(color.FgCyan, color.Bold) - Text := color.New(color.FgWhite) - - switch MsgType { - - case "Error": - Error.Printf(format, a...) - case "Info": - Info.Printf(format, a...) - case "Head": - Head.Printf(format, a...) - case "Text": - Text.Printf(format, a...) - default: - Text.Printf(format, a...) - }*/ fmt.Printf(format, a...) } -//Clear clears the terminal => This barely works, please fix +//Clear clears the terminal => This barely works, please fix → Nope func Clear() { - - // TODO: ADD support for multiple operating systems and terminals. Linux = clear, Windows = cls, have to do research for OSX and BSD. - c := exec.Command("clear") c.Stdout = os.Stdout c.Run() @@ -122,52 +93,12 @@ func MessagePrint(Time, Username, Content string) { //var Color color.Attribute TimeStamp, _ := time.Parse(time.RFC3339, Time) LocalTime := TimeStamp.Local().Format("2006/01/02 15:04:05") - /* - if val, ok := State.MemberRole[Username]; ok { - Color = ColorMatch(val.Color) - } - UserName := color.New(Color).SprintFunc() - */ log.SetFlags(0) log.Printf("%s > %s > %s\n", LocalTime, Username, Content) log.SetFlags(log.LstdFlags) } -/* -//ColorMatch compares HEX->DEC colorcoding and returns the closest ANSI color -func ColorMatch(colorinput int) color.Attribute { - var Result float64 - var ColorResult color.Attribute - Result = 10000 - - log.Println(colorinput) - - var ANSIColors []HexColor - ANSIColors = append(ANSIColors, HexColor{color.FgRed, 255, 0, 0}) - ANSIColors = append(ANSIColors, HexColor{color.FgGreen, 0, 128, 0}) - ANSIColors = append(ANSIColors, HexColor{color.FgYellow, 255, 255, 0}) - ANSIColors = append(ANSIColors, HexColor{color.FgBlue, 0, 0, 255}) - ANSIColors = append(ANSIColors, HexColor{color.FgMagenta, 255, 0, 255}) - ANSIColors = append(ANSIColors, HexColor{color.FgCyan, 0, 255, 255}) - ANSIColors = append(ANSIColors, HexColor{color.FgWhite, 255, 255, 255}) - HexNumber := [4]byte{} - binary.BigEndian.PutUint32(HexNumber[:], uint32(colorinput)) - InputStruct := HexColor{color.FgBlack, int(HexNumber[1]), int(HexNumber[2]), int(HexNumber[3])} - - for _, acolor := range ANSIColors { - DiffSum := dis(acolor.R, InputStruct.R) + dis(acolor.G, InputStruct.G) + dis(acolor.B, InputStruct.B) - TestResult := math.Sqrt(DiffSum) - if TestResult < Result { - Result = TestResult - ColorResult = acolor.Color - } - } - - return ColorResult -} -*/ - func dis(a, b int) float64 { return float64((a - b) * (a - b)) }