Skip to content

Commit

Permalink
Fix golang linter
Browse files Browse the repository at this point in the history
  • Loading branch information
waybackarchiver committed Feb 22, 2024
1 parent 25cb233 commit b055291
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions service/relaychat/relaychat.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,39 +74,7 @@ func (i *IRC) Serve() error {
Name: i.opts.IRCName(),
Pass: i.opts.IRCPassword(),
Handler: irc.HandlerFunc(func(c *irc.Client, m *irc.Message) {
logger.Debug("received message: %#v", m)

if m.Command == "ERROR" {
logger.Error("failed to handle irc request: %s", m)
return
}

if m.Command == "001" && i.opts.IRCChannel() != "" {
if err := c.Writef("JOIN %s", i.opts.IRCChannel()); err != nil {
logger.Error("failed to join %q channel: %v", err)
}
return
}

if m.Command == "NOTICE" && m.Prefix.Name == "NickServ" && strings.Contains(m.Trailing(), "dentified") {
logger.Debug("received command %q skipped", m.Command)
return
}

if m.Command != "PRIVMSG" {
logger.Debug("received command %q, skipped", m.Command)
return
}

if c.FromChannel(m) {
logger.Debug("received message from channel, skipped")
return
}

if err := i.process(m); err != nil {
logger.Error("process failure, message: %s, error: %v", m, err)
return
}
i.handle(c, m)
}),

Check warning on line 78 in service/relaychat/relaychat.go

View check run for this annotation

Codecov / codecov/patch

service/relaychat/relaychat.go#L70-L78

Added lines #L70 - L78 were not covered by tests
PingFrequency: 3 * time.Second,
PingTimeout: time.Minute,
Expand Down Expand Up @@ -154,6 +122,42 @@ func (i *IRC) Shutdown() error {
return nil
}

func (i *IRC) handle(c *irc.Client, m *irc.Message) {
logger.Debug("received message: %#v", m)

if m.Command == "ERROR" {
logger.Error("failed to handle irc request: %s", m)
return
}

Check warning on line 131 in service/relaychat/relaychat.go

View check run for this annotation

Codecov / codecov/patch

service/relaychat/relaychat.go#L125-L131

Added lines #L125 - L131 were not covered by tests

if m.Command == "001" && i.opts.IRCChannel() != "" {
if err := c.Writef("JOIN %s", i.opts.IRCChannel()); err != nil {
logger.Error("failed to join %q channel: %v", err)
}
return

Check warning on line 137 in service/relaychat/relaychat.go

View check run for this annotation

Codecov / codecov/patch

service/relaychat/relaychat.go#L133-L137

Added lines #L133 - L137 were not covered by tests
}

if m.Command == "NOTICE" && m.Prefix.Name == "NickServ" && strings.Contains(m.Trailing(), "dentified") {
logger.Debug("received command %q skipped", m.Command)
return
}

Check warning on line 143 in service/relaychat/relaychat.go

View check run for this annotation

Codecov / codecov/patch

service/relaychat/relaychat.go#L140-L143

Added lines #L140 - L143 were not covered by tests

if m.Command != "PRIVMSG" {
logger.Debug("received command %q, skipped", m.Command)
return

Check warning on line 147 in service/relaychat/relaychat.go

View check run for this annotation

Codecov / codecov/patch

service/relaychat/relaychat.go#L145-L147

Added lines #L145 - L147 were not covered by tests
}

if c.FromChannel(m) {
logger.Debug("received message from channel, skipped")
return
}

Check warning on line 153 in service/relaychat/relaychat.go

View check run for this annotation

Codecov / codecov/patch

service/relaychat/relaychat.go#L150-L153

Added lines #L150 - L153 were not covered by tests

if err := i.process(m); err != nil {
logger.Error("process failure, message: %s, error: %v", m, err)
return
}

Check warning on line 158 in service/relaychat/relaychat.go

View check run for this annotation

Codecov / codecov/patch

service/relaychat/relaychat.go#L155-L158

Added lines #L155 - L158 were not covered by tests
}

func (i *IRC) process(m *irc.Message) error {
text := m.Trailing()
urls := service.MatchURL(i.opts, text)
Expand Down

0 comments on commit b055291

Please sign in to comment.