diff options
Diffstat (limited to 'source.go')
-rw-r--r-- | source.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/source.go b/source.go new file mode 100644 index 0000000..8fc9848 --- /dev/null +++ b/source.go @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> + +package irc + +import "bytes" + +type Source interface { + AsSourceString() string +} + +func parseSource(s []byte) Source { + nick, userhost, found := bytes.Cut(s, []byte{'!'}) + if !found { + return Server{name: bytesToString(s)} + } + + user, host, found := bytes.Cut(userhost, []byte{'@'}) + if !found { + return Server{name: bytesToString(s)} + } + + return Client{ + Nick: bytesToString(nick), + User: bytesToString(user), + Host: 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 +} |