From 9f0e48cf02a4684d4ef99209958e95f80b02df7b Mon Sep 17 00:00:00 2001 From: Wayback Archiver <66856220+waybackarchiver@users.noreply.github.com> Date: Fri, 6 Sep 2024 13:26:36 +0000 Subject: [PATCH] Fix IRC publish (#568) * Improve irc publish * Update docs/changelog.md --- docs/changelog.md | 1 + publish/relaychat/relaychat.go | 18 ++++++++++++++++-- template/render/relaychat.go | 4 ++-- template/render/relaychat_test.go | 2 -- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 9b255799..331a0cc1 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix playback from discord no response +- Improve IRC publish ## [0.20.1] - 2024-07-02 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()