Skip to content

Commit

Permalink
Join IRC channel before connect
Browse files Browse the repository at this point in the history
  • Loading branch information
web-flow committed Apr 27, 2021
1 parent 8eefd28 commit 91960c7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ func TestIRCChannel(t *testing.T) {
t.Fatalf(`Parsing environment variables failed: %v`, err)
}

expected := "foo"
expected := "#foo"
got := opts.IRCChannel()

if got != expected {
Expand Down
5 changes: 4 additions & 1 deletion config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ func (o *Options) IRCPassword() string {

// IRCChannel returns channel of IRC
func (o *Options) IRCChannel() string {
return o.irc.channel
if strings.HasPrefix(o.irc.channel, "#") {
return o.irc.channel
}
return "#" + o.irc.channel
}

// IRCServer returns server of IRC
Expand Down
6 changes: 4 additions & 2 deletions publish/relaychat.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ func (i *IRC) ToChannel(ctx context.Context, text string) bool {
return false
}

i.conn.Join(config.Opts.IRCChannel())
i.conn.Privmsg(config.Opts.IRCChannel(), text)
go func() {
// i.conn.Join(config.Opts.IRCChannel())
i.conn.Privmsg(config.Opts.IRCChannel(), text)
}()

return true
}
Expand Down
3 changes: 3 additions & 0 deletions service/relaychat/relaychat.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func (i *IRC) Serve(ctx context.Context) error {
}
logger.Debug("[irc] Serving IRC instance: %s", config.Opts.IRCServer())

if config.Opts.IRCChannel() != "" {
i.conn.AddCallback("001", func(ev *irc.Event) { i.conn.Join(config.Opts.IRCChannel()) })
}
i.conn.AddCallback("PRIVMSG", func(ev *irc.Event) {
go func(ev *irc.Event) {
if err := i.process(context.Background(), ev); err != nil {
Expand Down

0 comments on commit 91960c7

Please sign in to comment.