feat: show irc channel status

This commit is contained in:
Ludvig Lundgren 2022-01-09 02:41:19 +01:00
parent f103dff221
commit 140fc97398
3 changed files with 155 additions and 119 deletions

View file

@ -30,10 +30,17 @@ type channelHealth struct {
lastAnnounce time.Time
}
// SetLastAnnounce set last announce to now
func (h *channelHealth) SetLastAnnounce() {
h.lastAnnounce = time.Now()
}
// SetMonitoring set monitoring and time
func (h *channelHealth) SetMonitoring() {
h.monitoring = true
h.monitoringSince = time.Now()
}
type Handler struct {
network *domain.IrcNetwork
filterService filter.Service
@ -48,7 +55,6 @@ type Handler struct {
cancel context.CancelFunc
lastPing time.Time
lastAnnounce time.Time
connected bool
connectedSince time.Time
// tODO disconnectedTime
@ -366,8 +372,6 @@ func (s *Handler) onMessage(msg *irc.Message) error {
cleanedMsg := cleanMessage(message)
log.Debug().Msgf("%v: %v %v: %v", s.network.Server, *channel, *announcer, cleanedMsg)
s.setLastAnnounce()
if err := s.sendToAnnounceProcessor(*channel, cleanedMsg); err != nil {
log.Error().Stack().Err(err).Msgf("could not queue line: %v", cleanedMsg)
return err
@ -440,8 +444,7 @@ func (s *Handler) HandleJoinChannel(channel string, password string) error {
// only set values if channel is found in map
v, ok := s.channelHealth[channel]
if ok {
v.monitoring = true
v.monitoringSince = time.Now()
v.SetMonitoring()
}
return nil
@ -607,6 +610,7 @@ func (s *Handler) handlePing(msg *irc.Message) error {
return nil
}
// check if announcer is one from the list in the definition
func (s *Handler) isValidAnnouncer(nick string) bool {
_, ok := s.validAnnouncers[nick]
if !ok {
@ -616,6 +620,7 @@ func (s *Handler) isValidAnnouncer(nick string) bool {
return true
}
// check if channel is one from the list in the definition
func (s *Handler) isValidChannel(channel string) bool {
_, ok := s.validChannels[channel]
if !ok {
@ -625,22 +630,6 @@ func (s *Handler) isValidChannel(channel string) bool {
return true
}
func (s *Handler) setLastAnnounce() {
s.lastAnnounce = time.Now()
}
func (s *Handler) GetLastAnnounce() time.Time {
return s.lastAnnounce
}
//func (s *Handler) setConnectedSince() {
// s.network.ConnectedSince = time.Now()
//}
//
//func (s *Handler) GetConnectedSince() time.Time {
// return s.lastAnnounce
//}
func (s *Handler) setLastPing() {
s.lastPing = time.Now()
}
@ -649,10 +638,6 @@ func (s *Handler) GetLastPing() time.Time {
return s.lastPing
}
func (s *Handler) GetChannelHealth() map[string]*channelHealth {
return s.channelHealth
}
// irc line can contain lots of extra stuff like color so lets clean that
func cleanMessage(message string) string {
var regexMessageClean = `\x0f|\x1f|\x02|\x03(?:[\d]{1,2}(?:,[\d]{1,2})?)?`