mirror of
https://github.com/IllusionMan1212/gorc.git
synced 2026-10-24 02:12:33 +00:00
feat: parse tags and negotiate message-tags capability
This commit is contained in:
@@ -77,6 +77,7 @@ func (c Client) Register(nick string, password string, channel string) {
|
|||||||
c.SendCommand("NICK", nick)
|
c.SendCommand("NICK", nick)
|
||||||
c.SendCommand("USER", nick, "0", "*", nick)
|
c.SendCommand("USER", nick, "0", "*", nick)
|
||||||
// TODO: CAP REQ :whatever capability the client recognizes and supports
|
// TODO: CAP REQ :whatever capability the client recognizes and supports
|
||||||
|
c.SendCommand("CAP", "REQ", ":message-tags")
|
||||||
c.SendCommand("CAP", "END")
|
c.SendCommand("CAP", "END")
|
||||||
c.SendCommand("JOIN", channel)
|
c.SendCommand("JOIN", channel)
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-8
@@ -21,21 +21,33 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type IRCMessage struct {
|
type IRCMessage struct {
|
||||||
Tags []Tag // starts with @ | Optional
|
Tags Tags // starts with @ | Optional
|
||||||
Source string // starts with : | Optional
|
Source string // starts with : | Optional
|
||||||
Command string // can either be a string or a numeric value | Required
|
Command string // can either be a string or a numeric value | Required
|
||||||
Parameters []string // Optional (Dependant on command)
|
Parameters []string // Optional (Dependant on command)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Tag struct {
|
type Tags map[string]string
|
||||||
key string
|
|
||||||
value string
|
func parseTags(rawTags string) Tags {
|
||||||
|
tags := make(Tags, 0)
|
||||||
|
rawTagsSlice := strings.Split(rawTags, ";")
|
||||||
|
|
||||||
|
for _, tag := range rawTagsSlice {
|
||||||
|
str := strings.Split(tag, "=")
|
||||||
|
|
||||||
|
key := str[0]
|
||||||
|
value := ""
|
||||||
|
|
||||||
|
// we need to make sure a "value" exists before accessing str[1]
|
||||||
|
if len(str) > 1 {
|
||||||
|
value = str[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTags(rawTags string) []Tag {
|
tags[key] = value
|
||||||
// TODO:
|
}
|
||||||
// TOOD: some tags don't have an "=" and they're basically considered "true"
|
|
||||||
return nil
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseIRCMessage(line string) IRCMessage {
|
func ParseIRCMessage(line string) IRCMessage {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
|
|||||||
return s, s.readFromServer
|
return s, s.readFromServer
|
||||||
case ReceivedIRCCommandMsg:
|
case ReceivedIRCCommandMsg:
|
||||||
message := parser.ParseIRCMessage(msg.Msg)
|
message := parser.ParseIRCMessage(msg.Msg)
|
||||||
fullMsg := fmt.Sprintf("%s %s %s", message.Source, message.Command, strings.Join(message.Parameters, " "))
|
fullMsg := fmt.Sprintf("%s %s %s %s", message.Tags, message.Source, message.Command, strings.Join(message.Parameters, " "))
|
||||||
s.content += fullMsg
|
s.content += fullMsg
|
||||||
|
|
||||||
// TODO: handle different commands
|
// TODO: handle different commands
|
||||||
|
|||||||
Reference in New Issue
Block a user