aboutsummaryrefslogtreecommitdiff
path: root/msg.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2024-12-08 08:45:13 +0800
committerRunxi Yu <me@runxiyu.org>2024-12-08 01:20:26 +0800
commitd810d12355873d3eaf61ed3f7f0ae52db06c2c96 (patch)
tree5cfa6d11c31377b459b06f4e3399bcc0542c57d8 /msg.go
parentSlight refactor (diff)
downloadmeseircd-d810d12355873d3eaf61ed3f7f0ae52db06c2c96.tar.gz
meseircd-d810d12355873d3eaf61ed3f7f0ae52db06c2c96.tar.zst
meseircd-d810d12355873d3eaf61ed3f7f0ae52db06c2c96.zip
Add basic command handling
Diffstat (limited to 'msg.go')
-rw-r--r--msg.go45
1 files changed, 39 insertions, 6 deletions
diff --git a/msg.go b/msg.go
index 7e778f3..1743116 100644
--- a/msg.go
+++ b/msg.go
@@ -4,19 +4,52 @@ import (
"strings"
)
-type Msg struct {
- RawMessage string
+type RMsg struct {
RawSource string
Command string
Tags map[string]string
Params []string
}
-// Partially adapted from https://github.com/ergochat/irc-go.git
-func parseIRCMsg(line string) (msg Msg, err error) {
- msg = Msg{
- RawMessage: line,
+type Sourceable interface {
+ ClientSource() string
+ ServerSource() string
+}
+
+type SMsg struct {
+ Source *Sourceable
+ Command string
+ Tags map[string]string
+ Params []string
+}
+
+func (msg *SMsg) ClientSerialize() (final string) {
+ if msg.Tags != nil && len(msg.Tags) != 0 {
+ final = "@"
+ for k, v := range msg.Tags{
+ // TODO: Tag values must be escaped
+ final += k + "=" + v + ";"
+ }
+ final += " "
}
+ if msg.Source != nil {
+ final += ":" + (*msg.Source).ClientSource() + " "
+ }
+ final += msg.Command + " "
+
+ if len(msg.Params) > 0 {
+ for i := 0; i < len(msg.Params) - 1; i++ {
+ final += msg.Params[i] + " "
+ }
+ final += ":" + msg.Params[len(msg.Params) - 1]
+ }
+ final += "\n"
+ return
+}
+
+// Partially adapted from https://github.com/ergochat/irc-go.git
+func parseIRCMsg(line string) (msg RMsg, err error) {
+ msg = RMsg{}
line = strings.TrimSuffix(line, "\n")
line = strings.TrimSuffix(line, "\r")