From 6253e6bee83073ea1d5d4ade9e2d4d7076cb8303 Mon Sep 17 00:00:00 2001 From: Sean Hinchee Date: Wed, 16 Jan 2019 21:14:49 -0600 Subject: [PATCH] run go (vet fmt) --- commands.go | 4 ++-- config.go | 59 +++++++++++++++++++++++++++-------------------------- events.go | 2 +- main.go | 6 +++--- menu.go | 58 ++++++++++++++++++++++++++-------------------------- 5 files changed, 65 insertions(+), 64 deletions(-) diff --git a/commands.go b/commands.go index e312d225514152480f31dd90dd932d26b09c61b5..554bcacfaae2c42731405f6ee3910a621e8dd1d4 100644 --- a/commands.go +++ b/commands.go @@ -1,10 +1,10 @@ package main import ( + "github.com/bwmarrin/discordgo" "regexp" "strconv" "strings" - "github.com/bwmarrin/discordgo" ) //ParseForCommands parses input for Commands, returns message if no command specified, else return is empty @@ -122,7 +122,7 @@ func ParseForCommands(line string) string { } Msg(TextMsg, "name -> %s\n", newName) return "" - } + } return line } diff --git a/config.go b/config.go index 68dbdbced7dcfc2df88af83bb96df0f416612e4b..5761fba5d50f8c1a9f3be3368b4606ad4379170c 100644 --- a/config.go +++ b/config.go @@ -1,34 +1,35 @@ package main import ( + "bitbucket.org/mischief/libauth" "bufio" "fmt" + "github.com/mischief/ndb" "log" "os" "os/user" -sc "strconv" + sc "strconv" "strings" - "bitbucket.org/mischief/libauth" - "github.com/mischief/ndb" ) // Types of auth we can do ­ add handling for new modes to atoam() type AuthModes int + const ( - Pass AuthModes = iota + Pass AuthModes = iota Factotum - Unknown // Placeholder + Unknown // Placeholder ) //Configuration is a struct that contains all configuration fields type Configuration struct { - AuthMode AuthModes - Username string - LoadBacklog bool - Messages int - PromptChar string - TimestampChar string - password string + AuthMode AuthModes + Username string + LoadBacklog bool + Messages int + PromptChar string + TimestampChar string + password string } // Config is the global configuration of discord-cli @@ -50,15 +51,15 @@ func atob(s string) bool { // Convert a string such as "factotum" into factotum func atoam(s string) AuthModes { s = strings.ToLower(s) - + if s == "pass" { return Pass } - + if s == "factotum" { return Factotum } - + return Unknown } @@ -87,18 +88,18 @@ Start: if err != nil { log.Fatal("error: Could not ") } - + Config.Username = ndb.Search("username", "").Search("username") Config.AuthMode = atoam(ndb.Search("auth", "").Search("auth")) - + if Config.AuthMode == Pass { Config.password = ndb.Search("username", "").Search("password") } - Config.LoadBacklog = atob(ndb.Search("loadbacklog", "").Search("loadbacklog")) - Config.Messages, _ = sc.Atoi(ndb.Search("messages", "").Search("messages")) - Config.PromptChar = ndb.Search("promptchar", "").Search("promptchar") - Config.TimestampChar = ndb.Search("timestampchar", "").Search("timestampchar") + Config.LoadBacklog = atob(ndb.Search("loadbacklog", "").Search("loadbacklog")) + Config.Messages, _ = sc.Atoi(ndb.Search("messages", "").Search("messages")) + Config.PromptChar = ndb.Search("promptchar", "").Search("promptchar") + Config.TimestampChar = ndb.Search("timestampchar", "").Search("timestampchar") } @@ -118,14 +119,14 @@ func CreateConfig() { raw := fmt.Sprintf("auth=pass\nloadbacklog=true\nmessages=10\npromptchar=→\ntimestampchar=>\n\nusername=%s password=\n", scan.Text()) // Create File - os.Mkdir(usr.HomeDir + "/lib", 0775) - + os.Mkdir(usr.HomeDir+"/lib", 0775) + file, err := os.Create(usr.HomeDir + ConfigPath) - + if err != nil { log.Fatalln(err) } - + file.Chmod(0600) // PrintToFile @@ -150,9 +151,9 @@ func CheckState() { if Config.Username == "" { log.Fatalln("Error: No Username Specified, please edit " + usr.HomeDir + ConfigPath) } - + // Check and handle password loading - switch(Config.AuthMode){ + switch Config.AuthMode { case Factotum: // Acquire password from factotum userPwd, err := libauth.Getuserpasswd("proto=pass service=discord user=%s server=discordapp.com", Config.Username) @@ -171,8 +172,8 @@ func CheckState() { default: // Password is already loaded in auth=pass mode } - - if(Config.password == "") { + + if Config.password == "" { log.Fatalln("Error: No password loaded, cannot auth. Are you missing a factotum key or password= tuple?") } } diff --git a/events.go b/events.go index 690265dbacd8cd1aa1b86c7824ea8a261615aef5..05b6e5b2fc2209fbe6950fa25775aaed78567eb7 100644 --- a/events.go +++ b/events.go @@ -38,7 +38,7 @@ func newMessage(s *discordgo.Session, m *discordgo.MessageCreate) { } DMs, err := Session.DiscordGo.UserChannels() if err != nil { - // No DMs + // No DMs return } for _, channel := range DMs { diff --git a/main.go b/main.go index 632284835bc3bc96f46a36d7d3c11b31aa0586ee..c08a2bbdf056e0b833014cbc6e869412de3b0ea2 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,7 @@ func main() { //fmt.Print("> ") //line, _ := rl.Readline() line, err := reader.ReadString('\n') - + if err == io.EOF { break } @@ -89,7 +89,7 @@ func main() { for { subline, _ := reader.ReadString('\n') line += subline - if strings.Index(subline, "```") != -1 { + if strings.Index(subline, "```") != -1 { break } } @@ -163,7 +163,7 @@ func ParseForMentions(line string) string { return lineByte } -//ReplaceMentions replaces mentions to ID +//ReplaceMentions replaces mentions to ID func ReplaceMentions(input string) string { // Check for guild members that match for _, member := range State.Guild.Members { diff --git a/menu.go b/menu.go index 603bfccb7b146c8c0bb34c2836afd41ca5e5fa81..96803d899e2a1f3eff697bee83455ef977919b6f 100644 --- a/menu.go +++ b/menu.go @@ -305,39 +305,39 @@ func AddUserChannelMenu() { if State.Channel.GuildID == "" { Msg(ErrorMsg, "Currently in a user channel, move to a guild with :g\n") } else { - SelectMap := make(map[int]string) -Start: - SelectID := 0 - for _, Member := range State.Members { - SelectMap[SelectID] = Member.User.ID - Msg(TextMsg, "[%d] %s\n", SelectID, Member.User.Username) - SelectID++ - } - var response string - fmt.Scanf("%s\n", &response) + SelectMap := make(map[int]string) + Start: + SelectID := 0 + for _, Member := range State.Members { + SelectMap[SelectID] = Member.User.ID + Msg(TextMsg, "[%d] %s\n", SelectID, Member.User.Username) + SelectID++ + } + var response string + fmt.Scanf("%s\n", &response) - if response == "b" { - return - } + if response == "b" { + return + } - ResponseInteger, err := strconv.Atoi(response) - if err != nil { - Msg(ErrorMsg, "(CH) Conversion Error: %s\n", err) - goto Start - } + ResponseInteger, err := strconv.Atoi(response) + if err != nil { + Msg(ErrorMsg, "(CH) Conversion Error: %s\n", err) + goto Start + } - if ResponseInteger > SelectID-1 || ResponseInteger < 0 { - Msg(ErrorMsg, "(CH) Error: ID is out of bound\n") - goto Start - } - Chan, err := Session.DiscordGo.UserChannelCreate(SelectMap[ResponseInteger]) + if ResponseInteger > SelectID-1 || ResponseInteger < 0 { + Msg(ErrorMsg, "(CH) Error: ID is out of bound\n") + goto Start + } + Chan, err := Session.DiscordGo.UserChannelCreate(SelectMap[ResponseInteger]) - if Chan.LastMessageID == "" { - var firstMessage string - fmt.Scanf("%s\n", &firstMessage) - Session.DiscordGo.ChannelMessageSend(Chan.ID, "Test") - } - State.Channel = Chan + if Chan.LastMessageID == "" { + var firstMessage string + fmt.Scanf("%s\n", &firstMessage) + Session.DiscordGo.ChannelMessageSend(Chan.ID, "Test") + } + State.Channel = Chan } }