From 33d2b5948b04570e696262bdf3ba6e859451831c Mon Sep 17 00:00:00 2001 From: Wayback Archiver <66856220+waybackarchiver@users.noreply.github.com> Date: Sat, 10 Aug 2024 04:00:55 +0000 Subject: [PATCH] Improve irc publish --- publish/relaychat/relaychat.go | 18 ++++++++++++++++-- template/render/relaychat.go | 4 ++-- template/render/relaychat_test.go | 2 -- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/publish/relaychat/relaychat.go b/publish/relaychat/relaychat.go index 1153c307..b12cc0be 100644 --- a/publish/relaychat/relaychat.go +++ b/publish/relaychat/relaychat.go @@ -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" @@ -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) } } diff --git a/template/render/relaychat.go b/template/render/relaychat.go index 5f4040d6..73dadd9b 100644 --- a/template/render/relaychat.go +++ b/template/render/relaychat.go @@ -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 } diff --git a/template/render/relaychat_test.go b/template/render/relaychat_test.go index bd968c99..204c837e 100644 --- a/template/render/relaychat_test.go +++ b/template/render/relaychat_test.go @@ -10,7 +10,6 @@ import ( func TestRenderForIRC(t *testing.T) { expected := `***** List of Archives ***** - ‹ Example › • Source @@ -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()