Compare commits
No commits in common. "2bd83701701e75fb2bb540b8e14f1222f3e63649" and "a58d2323e03d1818bb251e5ed441b796f5324c18" have entirely different histories.
2bd8370170
...
a58d2323e0
21
client.go
21
client.go
|
@ -1,4 +1,4 @@
|
||||||
package mppclientgo
|
package mppclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
@ -9,8 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
Ws *websocket.Conn
|
Ws *websocket.Conn
|
||||||
started bool
|
|
||||||
|
|
||||||
Uri string
|
Uri string
|
||||||
Token string
|
Token string
|
||||||
|
@ -85,29 +84,15 @@ func (c *Client) IsConnecting() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Start() {
|
func (c *Client) Start() {
|
||||||
if c.started {
|
// TODO
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.started = true
|
|
||||||
c.connect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Stop() {
|
func (c *Client) Stop() {
|
||||||
if !c.started {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.started = false
|
|
||||||
c.Ws.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) connect() {
|
func (c *Client) connect() {
|
||||||
// TODO
|
// TODO
|
||||||
|
|
||||||
if c.Ws == nil {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) bindEventListners() {
|
func (c *Client) bindEventListners() {
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
package events
|
|
||||||
|
|
||||||
type EventCallback func(args ...any)
|
|
||||||
|
|
||||||
type Event struct {
|
|
||||||
Evtn string
|
|
||||||
Callback EventCallback
|
|
||||||
Once bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type EventEmitter struct {
|
|
||||||
Events map[string][]Event
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewEventEmitter() EventEmitter {
|
|
||||||
return EventEmitter{
|
|
||||||
Events: map[string][]Event{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (evt *EventEmitter) On(evtn string, callback EventCallback) {
|
|
||||||
if evt.Events[evtn] == nil {
|
|
||||||
evt.Events[evtn] = []Event{}
|
|
||||||
}
|
|
||||||
|
|
||||||
evt.Events[evtn] = append(evt.Events[evtn], Event{
|
|
||||||
Evtn: evtn,
|
|
||||||
Callback: callback,
|
|
||||||
Once: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (evt *EventEmitter) Emit(evtn string, args ...any) {
|
|
||||||
if evt.Events[evtn] == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, e := range evt.Events[evtn] {
|
|
||||||
if e.Callback != nil {
|
|
||||||
e.Callback(args...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,8 +13,8 @@ type MppTimeMessage struct {
|
||||||
|
|
||||||
type HiMppMessage struct {
|
type HiMppMessage struct {
|
||||||
MppTimeMessage
|
MppTimeMessage
|
||||||
User User `json:"u"`
|
User MppUser `json:"u"`
|
||||||
Motd string `json:"motd"`
|
Motd string `json:"motd"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NoteQuotaMppMessage struct {
|
type NoteQuotaMppMessage struct {
|
||||||
|
@ -26,8 +26,8 @@ type NoteQuotaMppMessage struct {
|
||||||
|
|
||||||
type ChatMppMessage struct {
|
type ChatMppMessage struct {
|
||||||
MppTimeMessage
|
MppTimeMessage
|
||||||
Message string `json:"a"`
|
Message string `json:"a"`
|
||||||
Part Participant `json:"p"`
|
Part MppParticipant `json:"p"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TimeMppMessage struct {
|
type TimeMppMessage struct {
|
||||||
|
@ -37,6 +37,6 @@ type TimeMppMessage struct {
|
||||||
|
|
||||||
type ChannelMppMessage struct {
|
type ChannelMppMessage struct {
|
||||||
MppMessage
|
MppMessage
|
||||||
Channel Channel `json:"ch"`
|
Channel MppChannel `json:"ch"`
|
||||||
Participants []Participant `json:"ppl"`
|
Participants []MppParticipant `json:"ppl"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package mppclientgo
|
package mppclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -11,10 +11,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Hri7566/mpp-client-go/events"
|
|
||||||
"github.com/Hri7566/mpp-client-go/mpp"
|
"github.com/Hri7566/mpp-client-go/mpp"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
"github.com/joho/godotenv"
|
||||||
v8 "rogchap.com/v8go"
|
v8 "rogchap.com/v8go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,32 +24,20 @@ var token string
|
||||||
var ctx *v8.Context
|
var ctx *v8.Context
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
evt := events.NewEventEmitter()
|
ctx = v8.NewContext()
|
||||||
|
|
||||||
log := func(args ...any) {
|
helpCommands = commands
|
||||||
fmt.Println(args[0])
|
flag.Parse()
|
||||||
|
log.SetFlags(0)
|
||||||
|
|
||||||
|
err := godotenv.Load()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
evt.On("log", log)
|
token = os.Getenv("MPPNET_TOKEN")
|
||||||
|
|
||||||
evt.Emit("log", "hello, world")
|
StartSocket(addr)
|
||||||
|
|
||||||
/*
|
|
||||||
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) {
|
func StartSocket(address *string) {
|
||||||
|
|
Loading…
Reference in New Issue