aboutsummaryrefslogtreecommitdiff
path: root/forged/internal/irc/source.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-04-06 10:01:02 +0800
committerRunxi Yu <me@runxiyu.org>2025-04-06 10:02:40 +0800
commit44ccf133dd44211ce1200595c7a9bea8e7609c1e (patch)
treea27ef21a3dcbbcafa2ca1d748501fe708d67ced2 /forged/internal/irc/source.go
parentAdd more documentation comments (diff)
downloadforge-44ccf133dd44211ce1200595c7a9bea8e7609c1e.tar.gz
forge-44ccf133dd44211ce1200595c7a9bea8e7609c1e.tar.zst
forge-44ccf133dd44211ce1200595c7a9bea8e7609c1e.zip
irc: Move everything from lindenii-irc
Diffstat (limited to 'forged/internal/irc/source.go')
-rw-r--r--forged/internal/irc/source.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/forged/internal/irc/source.go b/forged/internal/irc/source.go
new file mode 100644
index 0000000..d955f45
--- /dev/null
+++ b/forged/internal/irc/source.go
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: MIT
+// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
+
+package irc
+
+import (
+ "bytes"
+
+ "go.lindenii.runxiyu.org/forge/forged/internal/misc"
+)
+
+type Source interface {
+ AsSourceString() string
+}
+
+func parseSource(s []byte) Source {
+ nick, userhost, found := bytes.Cut(s, []byte{'!'})
+ if !found {
+ return Server{name: misc.BytesToString(s)}
+ }
+
+ user, host, found := bytes.Cut(userhost, []byte{'@'})
+ if !found {
+ return Server{name: misc.BytesToString(s)}
+ }
+
+ return Client{
+ Nick: misc.BytesToString(nick),
+ User: misc.BytesToString(user),
+ Host: misc.BytesToString(host),
+ }
+}
+
+type Server struct {
+ name string
+}
+
+func (s Server) AsSourceString() string {
+ return s.name
+}
+
+type Client struct {
+ Nick string
+ User string
+ Host string
+}
+
+func (c Client) AsSourceString() string {
+ return c.Nick + "!" + c.User + "@" + c.Host
+}