From 66de1621e9cc9311480b11d06272a9ebe7f2c9db Mon Sep 17 00:00:00 2001 From: Sean Hinchee Date: Wed, 12 Dec 2018 21:38:34 -0600 Subject: [PATCH] add aux/statusmsg notifications for 9 ;; fix -t timestamp bugs (both thanks to halfwit) --- TODO | 16 +++++++++++----- helper.go | 38 +++++++++++++++++++++++++++++++------- main.go | 7 ++++++- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/TODO b/TODO index 1dca0ee517b8bbd0f3ee02bd110de5f57c5f9cb2..552d89250d586c8b60ac0da9cd92d345f73984d6 100644 --- a/TODO +++ b/TODO @@ -6,6 +6,8 @@ Commands: :d [n] [file] -- dump backlog of last 'n' msgs to a file 'file' +:c [n] and :c ? to switch and list channels, respectively + Features: * remove JSON config @@ -14,16 +16,20 @@ Features: * delete disco.cfg on failure to log in for 400 bad request: password does not match -* ensure proper permissions -rw------- 0600 for discord.cfg +* verify proper permissions -rw------- 0600 for discord.cfg * if ``` entered, allow multi-line message (composition) * replace <:emoji:3lk4j12:> garbage with :emoji: -* clean up @'s - -* replace libnotify shenanigans, add a goroutine to check for pings +* fix @'s * flag for larger backlog loading -* CAPTCHA solution +* CAPTCHA solution -- http-proxy is a bad one + +* change > to → or whtever desired + +* fix pm's + +* aux/statusmsg backgrounds and doesn't steal input diff --git a/helper.go b/helper.go index 87671cee4a98bbe97cce1d47a8d96fe762d300e0..3fcf46da2a7ab0c68ace11b9fc0919ad5d2b5e1f 100644 --- a/helper.go +++ b/helper.go @@ -1,9 +1,11 @@ package main import ( + "io" "log" "os" "os/exec" + "runtime" "strings" "time" "fmt" @@ -67,6 +69,9 @@ func PrintMessages(Amount int) { //Notify uses Notify-Send from libnotify to send a notification when a mention arrives. func Notify(m *discordgo.Message) { + if *enableNotify == false { + return + } Channel, err := State.Session.DiscordGo.Channel(m.ChannelID) if err != nil { Msg(ErrorMsg, "(NOT) Channel Error: %s\n", err) @@ -76,24 +81,43 @@ func Notify(m *discordgo.Message) { Msg(ErrorMsg, "(NOT) Guild Error: %s\n", err) } Title := "@" + m.Author.Username + " : " + Guild.Name + "/" + Channel.Name - cmd := exec.Command("notify-send", Title, m.ContentWithMentionsReplaced()) - err = cmd.Start() - if err != nil { - Msg(ErrorMsg, "(NOT) Check if libnotify is installed, or disable notifications.\n") + switch runtime.GOOS { + case "plan9": + pr, pw := io.Pipe() + cmd := exec.Command("/bin/aux/statusmsg", "-k", *notifyFlag, Title) + cmd.Stdin = pr + go func() { + defer pw.Close() + fmt.Fprintf(pw, "%s\n", m.ContentWithMentionsReplaced()) + cmd.Wait() + }() + err = cmd.Start() + if err != nil { + Msg(ErrorMsg, "%s\n", err) + } + + default: + cmd := exec.Command("notify-send", Title, m.ContentWithMentionsReplaced()) + err = cmd.Start() + if err != nil { + Msg(ErrorMsg, "(NOT) Check if libnotify is installed, or disable notifications.\n") + } } + } //MessagePrint prints one correctly formatted Message to stdout func MessagePrint(Time, Username, Content string) { //var Color color.Attribute log.SetFlags(0) - if *timeStamp { + if *hideTimeStamp { + log.Printf("%s > %s\n", Username, Content) + } else { TimeStamp, _ := time.Parse(time.RFC3339, Time) LocalTime := TimeStamp.Local().Format("2006/01/02 15:04:05") log.Printf("%s > %s > %s\n", LocalTime, Username, Content) - } else { - log.Printf("%s > %s\n", Username, Content) + } log.SetFlags(log.LstdFlags) } diff --git a/main.go b/main.go index bebe3738a33227c626492e4038a68a4805ca3d80..7e7af762b55b76562c80401adb35a00b79c00134 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,9 @@ var State *DiscordState.State //MsgType is a string containing global message type type MsgType string -var timeStamp = flag.Bool("t", true, "Hide timestamps in channel log") +var hideTimeStamp = flag.Bool("t", false, "Hide timestamps in channel log") +var enableNotify = flag.Bool("n", false, "Enable notifications") +var notifyFlag = flag.String("w", "10,10,260,90", "Dimensions to pass through to statusmsg") func main() { @@ -43,6 +45,9 @@ func main() { flag.Usage() os.Exit(1) } + if flag.Lookup("w") != nil { + *notifyFlag = fmt.Sprintf("-w %s", *notifyFlag) + } //Initialize Config GetConfig() CheckState()