mirror of
https://github.com/vbatts/flaming-happiness.git
synced 2025-07-28 13:10:27 +00:00
some accomodations for zmq2 -> zmq3
This commit is contained in:
parent
a197592e7b
commit
a8de7de3ec
4 changed files with 153 additions and 70 deletions
81
common/common.go
Normal file
81
common/common.go
Normal file
|
@ -0,0 +1,81 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
notify "github.com/mqu/go-notify"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
ignoreList = []string{}
|
||||
)
|
||||
|
||||
func SetIgnores(ignores string) {
|
||||
ignoreList = strings.Split(ignores, ",")
|
||||
}
|
||||
|
||||
func Display(noti_msg IrcNotify, linger int64, quiet bool) {
|
||||
if !quiet {
|
||||
log.Printf("%#v", noti_msg)
|
||||
}
|
||||
if ShouldIgnore(noti_msg.Channel) {
|
||||
if !quiet {
|
||||
log.Printf("Ignoring: %s", noti_msg.Channel)
|
||||
}
|
||||
return
|
||||
}
|
||||
hello := notify.NotificationNew(noti_msg.Server+","+noti_msg.Channel,
|
||||
noti_msg.Message,
|
||||
"")
|
||||
|
||||
if hello == nil {
|
||||
log.Println("ERROR: Unable to create a new notification")
|
||||
return
|
||||
}
|
||||
notify.NotificationSetTimeout(hello, 0)
|
||||
|
||||
if e := notify.NotificationShow(hello); e != nil && len(e.Message()) > 0 {
|
||||
log.Printf("ERROR: %s", e.Message())
|
||||
return
|
||||
}
|
||||
time.Sleep(time.Duration(linger) * time.Second)
|
||||
notify.NotificationClose(hello)
|
||||
}
|
||||
|
||||
func ShouldIgnore(channel string) bool {
|
||||
for _, ignore := range ignoreList {
|
||||
if strings.Contains(channel, ignore) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type IrcNotify struct {
|
||||
Highlight bool `json:"highlight"`
|
||||
Type string `json:"type"`
|
||||
Channel string `json:"channel"`
|
||||
Message string `json:"message"`
|
||||
Server string `json:"server"`
|
||||
Date string `json:"date"`
|
||||
Tags []string `json:"tags"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
notify.Init("IRC-noti")
|
||||
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
signal.Notify(c, os.Kill)
|
||||
go func() {
|
||||
for sig := range c {
|
||||
// sig is a ^C, handle it
|
||||
log.Printf("captured %v, stopping profiler and exiting..", sig)
|
||||
notify.UnInit()
|
||||
os.Exit(0)
|
||||
}
|
||||
}()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue