From 2bd83701701e75fb2bb540b8e14f1222f3e63649 Mon Sep 17 00:00:00 2001 From: Hri7566 Date: Mon, 8 Jul 2024 23:36:45 -0400 Subject: [PATCH] Fix message.go --- client.go | 21 ++++++++++++++++++--- mpp/message.go | 12 ++++++------ test.go | 36 ++++++++++++++++++++++++------------ 3 files changed, 48 insertions(+), 21 deletions(-) mode change 100755 => 100644 test.go diff --git a/client.go b/client.go index 2ec1272..62d01f7 100644 --- a/client.go +++ b/client.go @@ -1,4 +1,4 @@ -package mppclient +package mppclientgo import ( "log" @@ -9,7 +9,8 @@ import ( ) type Client struct { - Ws *websocket.Conn + Ws *websocket.Conn + started bool Uri string Token string @@ -84,15 +85,29 @@ func (c *Client) IsConnecting() bool { } func (c *Client) Start() { - // TODO + if c.started { + return + } + + c.started = true + c.connect() } func (c *Client) Stop() { + if !c.started { + return + } + c.started = false + c.Ws.Close() } func (c *Client) connect() { // TODO + + if c.Ws == nil { + + } } func (c *Client) bindEventListners() { diff --git a/mpp/message.go b/mpp/message.go index 798ebe9..b161d30 100755 --- a/mpp/message.go +++ b/mpp/message.go @@ -13,8 +13,8 @@ type MppTimeMessage struct { type HiMppMessage struct { MppTimeMessage - User MppUser `json:"u"` - Motd string `json:"motd"` + User User `json:"u"` + Motd string `json:"motd"` } type NoteQuotaMppMessage struct { @@ -26,8 +26,8 @@ type NoteQuotaMppMessage struct { type ChatMppMessage struct { MppTimeMessage - Message string `json:"a"` - Part MppParticipant `json:"p"` + Message string `json:"a"` + Part Participant `json:"p"` } type TimeMppMessage struct { @@ -37,6 +37,6 @@ type TimeMppMessage struct { type ChannelMppMessage struct { MppMessage - Channel MppChannel `json:"ch"` - Participants []MppParticipant `json:"ppl"` + Channel Channel `json:"ch"` + Participants []Participant `json:"ppl"` } diff --git a/test.go b/test.go old mode 100755 new mode 100644 index c25601c..581d8eb --- a/test.go +++ b/test.go @@ -1,4 +1,4 @@ -package mppclient +package mppclientgo import ( "encoding/json" @@ -11,10 +11,10 @@ import ( "strings" "time" + "github.com/Hri7566/mpp-client-go/events" "github.com/Hri7566/mpp-client-go/mpp" "github.com/gorilla/websocket" - "github.com/joho/godotenv" v8 "rogchap.com/v8go" ) @@ -24,20 +24,32 @@ var token string var ctx *v8.Context func main() { - ctx = v8.NewContext() + evt := events.NewEventEmitter() - helpCommands = commands - flag.Parse() - log.SetFlags(0) - - err := godotenv.Load() - if err != nil { - log.Fatal(err) + log := func(args ...any) { + fmt.Println(args[0]) } - token = os.Getenv("MPPNET_TOKEN") + evt.On("log", log) - StartSocket(addr) + evt.Emit("log", "hello, world") + + /* + ctx = v8.NewContext() + + helpCommands = commands + flag.Parse() + log.SetFlags(0) + + err := godotenv.Load() + if err != nil { + log.Fatal(err) + } + + token = os.Getenv("MPPNET_TOKEN") + + StartSocket(addr) + */ } func StartSocket(address *string) {