Skip to content

Commit

Permalink
Improve irc publish
Browse files Browse the repository at this point in the history
  • Loading branch information
waybackarchiver committed Aug 17, 2024
1 parent 4199e19 commit 5008fff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
18 changes: 16 additions & 2 deletions publish/relaychat/relaychat.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/wabarc/wayback"
"github.com/wabarc/wayback/config"
"github.com/wabarc/wayback/errors"
"github.com/wabarc/wayback/ingress"
"github.com/wabarc/wayback/metrics"
"github.com/wabarc/wayback/publish"
"github.com/wabarc/wayback/reduxer"
Expand Down Expand Up @@ -44,9 +45,22 @@ func (i *IRC) Publish(ctx context.Context, _ reduxer.Reduxer, cols []wayback.Col
// this value accessed from service module.
if i.conn == nil {
v := ctx.Value(publish.FlagIRC)
conn, ok := v.(*irc.Client)
client, ok := v.(*irc.Client)
if ok {
i.conn = conn
i.conn = client
} else {
config := irc.ClientConfig{
Nick: i.opts.IRCNick(),
User: i.opts.IRCNick(),
Name: i.opts.IRCName(),
Pass: i.opts.IRCPassword(),
}
dialer := ingress.Dialer()
conn, err := dialer.Dial("tcp", i.opts.IRCServer())
if err != nil {
return err
}
i.conn = irc.NewClient(conn, config)
}
}

Expand Down
4 changes: 2 additions & 2 deletions template/render/relaychat.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func (i *Relaychat) main() *bytes.Buffer {
func (i *Relaychat) join(buf *bytes.Buffer) *bytes.Buffer {
tmplBytes := &bytes.Buffer{}
tmplBytes.WriteString("***** List of Archives *****")
tmplBytes.WriteString("\n \n") // blank line
tmplBytes.WriteString("\n")
tmplBytes.Write(buf.Bytes())
tmplBytes.WriteString("\n \n") // blank line
tmplBytes.WriteString("\n")
tmplBytes.WriteString("***** End of Archives *****")
return tmplBytes
}
2 changes: 0 additions & 2 deletions template/render/relaychat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

func TestRenderForIRC(t *testing.T) {
expected := `***** List of Archives *****
‹ Example ›
• Source
Expand All @@ -26,7 +25,6 @@ func TestRenderForIRC(t *testing.T) {
> https://ipfs.io/ipfs/QmTbDmpvQ3cPZG6TA5tnar4ZG6q9JMBYVmX2n3wypMQMtr
• Telegraph:
> http://telegra.ph/title-01-01
***** End of Archives *****`

got := ForPublish(&Relaychat{Cols: collects, Data: bundleExample}).String()
Expand Down

0 comments on commit 5008fff

Please sign in to comment.