support parsing usercommands
This commit is contained in:
parent
086281dab2
commit
1a3e4fe072
@ -3,6 +3,7 @@ package libnmdc
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@ -244,9 +245,29 @@ func (this *HubConnection) processProtocolMessage(message string) {
|
||||
this.Hco.Address = HubAddress(commandParts[1])
|
||||
this.conn.Close() // we'll reconnect onto the new address
|
||||
|
||||
case "$UserCommand":
|
||||
// $UserCommand 1 1 Group chat\New group chat$<%[mynick]> !groupchat_new||
|
||||
if rx_userCommand.MatchString(commandParts[1]) {
|
||||
usc := rx_userCommand.FindStringSubmatch(commandParts[1])
|
||||
|
||||
typeInt, _ := strconv.Atoi(usc[1])
|
||||
contextInt, _ := strconv.Atoi(usc[2])
|
||||
|
||||
uscStruct := UserCommand{
|
||||
Type: UserCommandType(typeInt),
|
||||
Context: UserCommandContext(contextInt),
|
||||
Message: usc[3],
|
||||
Command: NMDCUnescape(usc[4]),
|
||||
}
|
||||
|
||||
this.processEvent(HubEvent{EventType: EVENT_USERCOMMAND, UserCommand: &uscStruct})
|
||||
|
||||
} else {
|
||||
this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: "Malformed usercommand '" + commandParts[1] + "'"})
|
||||
}
|
||||
|
||||
// IGNORABLE COMMANDS
|
||||
case "$Supports":
|
||||
case "$UserCommand": // TODO $UserCommand 1 1 Group chat\New group chat$<%[mynick]> !groupchat_new||
|
||||
case "$HubTopic":
|
||||
case "$Search":
|
||||
case "$ConnectToMe":
|
||||
|
@ -11,6 +11,7 @@ const (
|
||||
EVENT_CONNECTION_STATE_CHANGED = 8
|
||||
EVENT_HUBNAME_CHANGED = 9
|
||||
EVENT_DEBUG_MESSAGE = 10
|
||||
EVENT_USERCOMMAND = 11
|
||||
)
|
||||
|
||||
type HubEventType int
|
||||
@ -20,4 +21,5 @@ type HubEvent struct {
|
||||
Nick string
|
||||
Message string
|
||||
StateChange ConnectionState
|
||||
UserCommand *UserCommand
|
||||
}
|
||||
|
26
UserCommand.go
Normal file
26
UserCommand.go
Normal file
@ -0,0 +1,26 @@
|
||||
package libnmdc
|
||||
|
||||
type UserCommandType uint8
|
||||
|
||||
const (
|
||||
USERCOMMAND_TYPE_SEPARATOR UserCommandType = 0
|
||||
USERCOMMAND_TYPE_RAW UserCommandType = 1
|
||||
USERCOMMAND_TYPE_NICKLIMITED UserCommandType = 2
|
||||
USERCOMMAND_TYPE_CLEARALL UserCommandType = 255
|
||||
)
|
||||
|
||||
type UserCommandContext uint8
|
||||
|
||||
const (
|
||||
USERCOMMAND_CONTEXT_HUB UserCommandContext = 1
|
||||
USERCOMMAND_CONTEXT_USER UserCommandContext = 2
|
||||
USERCOMMAND_CONTEXT_SEARCH UserCommandContext = 4
|
||||
USERCOMMAND_CONTEXT_FILELIST UserCommandContext = 8
|
||||
)
|
||||
|
||||
type UserCommand struct {
|
||||
Type UserCommandType
|
||||
Context UserCommandContext
|
||||
Message string
|
||||
Command string
|
||||
}
|
@ -19,12 +19,14 @@ const (
|
||||
var rx_protocolMessage *regexp.Regexp
|
||||
var rx_publicChat *regexp.Regexp
|
||||
var rx_incomingTo *regexp.Regexp
|
||||
var rx_userCommand *regexp.Regexp
|
||||
var ErrNotConnected error = errors.New("Not connected")
|
||||
|
||||
func init() {
|
||||
rx_protocolMessage = regexp.MustCompile("(?ms)^[^|]*\\|")
|
||||
rx_publicChat = regexp.MustCompile("(?ms)^<([^>]*)> (.*)$")
|
||||
rx_incomingTo = regexp.MustCompile("(?ms)^([^ ]+) From: ([^ ]+) \\$<([^>]*)> (.*)")
|
||||
rx_userCommand = regexp.MustCompile(`(?ms)^(\d+) (\d+)\s?([^\$]*)\$?(.*)`)
|
||||
}
|
||||
|
||||
func NMDCUnescape(encoded string) string {
|
||||
|
Loading…
Reference in New Issue
Block a user