mirror of
https://github.com/IllusionMan1212/gorc.git
synced 2026-10-24 02:12:33 +00:00
fix: fixed some stuff
* include token when replying to a PING with a PONG * fixed parsing of a single param with a colon * fixed client's SendCommand() to properly send single and multi param messages
This commit is contained in:
+21
-9
@@ -89,17 +89,29 @@ func (c Client) SendCommand(cmd string, params ...string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
paramsString := ""
|
paramsString := ""
|
||||||
if len(params) > 0 {
|
|
||||||
paramsString = " " + strings.Join(params, " ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we have more than 1 param then replace the last param's space with a " :"
|
// if we have more than 1 param
|
||||||
if len(params) > 1 {
|
if len(params) > 1 {
|
||||||
i := strings.LastIndex(paramsString, " ")
|
lastParam := params[len(params)-1]
|
||||||
paramsString = paramsString[:i] + strings.Replace(paramsString[i:], " ", " :", 1)
|
// if the last param is a trailing param
|
||||||
// if we have more exactly 1 param and it contains spaces, we prepend colon to the param
|
// we prepend a colon to it
|
||||||
} else if len(params) == 1 && strings.Contains(params[0], " ") {
|
if strings.Contains(lastParam, " ") {
|
||||||
paramsString = ":" + paramsString
|
lastParam = " :" + lastParam
|
||||||
|
} else {
|
||||||
|
lastParam = " " + lastParam
|
||||||
|
}
|
||||||
|
|
||||||
|
paramsString = " " + strings.Join(params[:len(params)-1], " ")
|
||||||
|
paramsString += lastParam
|
||||||
|
|
||||||
|
// if we have exactly 1 param
|
||||||
|
} else if len(params) == 1 {
|
||||||
|
// if this 1 param contains spaces, we prepend a colon
|
||||||
|
if strings.Contains(params[0], " ") {
|
||||||
|
paramsString = " :" + params[0]
|
||||||
|
} else {
|
||||||
|
paramsString = " " + params[0]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.TlsConn != nil {
|
if c.TlsConn != nil {
|
||||||
|
|||||||
@@ -93,6 +93,11 @@ func ParseIRCMessage(line string) IRCMessage {
|
|||||||
parameters = append(parameters, params[1])
|
parameters = append(parameters, params[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we have 1 param and it starts with a colon
|
||||||
|
if len(parameters) == 1 && parameters[0][0] == ':' {
|
||||||
|
parameters[0] = parameters[0][1:]
|
||||||
|
}
|
||||||
|
|
||||||
ircMessage.Parameters = parameters
|
ircMessage.Parameters = parameters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ func (s State) Update(msg tea.Msg) (State, tea.Cmd) {
|
|||||||
// TODO: handle different commands
|
// TODO: handle different commands
|
||||||
switch message.Command {
|
switch message.Command {
|
||||||
case "PING":
|
case "PING":
|
||||||
s.Client.SendCommand("PONG")
|
s.Client.SendCommand("PONG", message.Parameters[0])
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user