Lindenii Project Forge
Warning: Due to various recent migrations, viewing non-HEAD refs may be broken.
/source.go (raw)
// 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
}