Compare commits
No commits in common. "main" and "v0.3.0" have entirely different histories.
@ -20,7 +20,7 @@ Revoltgo is a go package for writing bots / self-bots in revolt easily.
|
||||
|
||||
## API Reference
|
||||
|
||||
Click [here](https://pkg.go.dev/github.com/5elenay/revoltgo@v0.3.1) for api reference.
|
||||
Click [here](https://pkg.go.dev/github.com/5elenay/revoltgo@v0.3.0) for api reference.
|
||||
|
||||
## Ping Pong Example (Bot)
|
||||
|
||||
|
10
channel.go
10
channel.go
@ -220,13 +220,3 @@ func (c Channel) DeleteGroupRecipient(user_id string) error {
|
||||
_, err := c.Client.Request("DELETE", "/channels/"+c.Id+"/recipients/"+user_id, []byte{})
|
||||
return err
|
||||
}
|
||||
|
||||
// Send a typing start event to the channel.
|
||||
func (c *Channel) BeginTyping() {
|
||||
c.Client.Socket.SendText(fmt.Sprintf("{\"type\":\"BeginTyping\",\"channel\":\"%s\"}", c.Id))
|
||||
}
|
||||
|
||||
// End the typing event in the channel.
|
||||
func (c *Channel) EndTyping() {
|
||||
c.Client.Socket.SendText(fmt.Sprintf("{\"type\":\"EndTyping\",\"channel\":\"%s\"}", c.Id))
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
WS_URL = "wss://ws.divolt.xyz"
|
||||
API_URL = "https://api.divolt.xyz"
|
||||
WS_URL = "wss://ws.revolt.chat"
|
||||
API_URL = "https://api.revolt.chat"
|
||||
)
|
||||
|
||||
// Client struct.
|
||||
@ -189,7 +189,7 @@ func (c *Client) Auth() error {
|
||||
return fmt.Errorf("can't auth user (not a self-bot.)")
|
||||
}
|
||||
|
||||
resp, err := c.Request("POST", "/auth/session/login", []byte("{\"email\":\""+c.SelfBot.Email+"\",\"password\":\""+c.SelfBot.Password+"\",\"name\":\"Revoltgo\"}"))
|
||||
resp, err := c.Request("POST", "/auth/login", []byte("{\"email\":\""+c.SelfBot.Email+"\",\"password\":\""+c.SelfBot.Password+"\",\"captcha\": \"\"}"))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
||||
module git.cesium.pw/matthew/revoltgo
|
||||
module github.com/5elenay/revoltgo
|
||||
|
||||
go 1.17
|
||||
|
||||
|
1
http.go
1
http.go
@ -23,6 +23,7 @@ func (c Client) Request(method, path string, data []byte) ([]byte, error) {
|
||||
if c.SelfBot == nil {
|
||||
req.Header.Set("x-bot-token", c.Token)
|
||||
} else if c.SelfBot.SessionToken != "" && c.SelfBot.UserId != "" {
|
||||
req.Header.Set("x-user-id", c.SelfBot.UserId)
|
||||
req.Header.Set("x-session-token", c.SelfBot.SessionToken)
|
||||
}
|
||||
|
||||
|
34
other.go
34
other.go
@ -7,27 +7,14 @@ import (
|
||||
|
||||
// Similar to message, but created for send message function.
|
||||
type SendMessage struct {
|
||||
Content string `json:"content"`
|
||||
Nonce string `json:"nonce,omitempty"`
|
||||
Attachments []string `json:"attachments,omitempty"`
|
||||
Replies []Replies `json:"replies,omitempty"`
|
||||
Embeds []SendableEmbed `json:"embeds,omitempty"`
|
||||
DeleteAfter uint `json:"-"`
|
||||
}
|
||||
|
||||
type SendableEmbed struct {
|
||||
Type string `json:"type"`
|
||||
IconUrl string `json:"icon_url,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Media string `json:"media,omitempty"`
|
||||
Colour string `json:"colour,omitempty"`
|
||||
}
|
||||
|
||||
type Replies struct {
|
||||
Id string `json:"id"`
|
||||
Mention bool `json:"mention"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Attachments []string `json:"attachments,omitempty"`
|
||||
Nonce string `json:"nonce,omitempty"`
|
||||
DeleteAfter uint `json:"-"`
|
||||
Replies []struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
Mention bool `json:"mention"`
|
||||
} `json:"replies,omitempty"`
|
||||
}
|
||||
|
||||
// Set content.
|
||||
@ -56,7 +43,10 @@ func (sms *SendMessage) AddAttachment(attachment string) *SendMessage {
|
||||
|
||||
// Add a new reply.
|
||||
func (sms *SendMessage) AddReply(id string, mention bool) *SendMessage {
|
||||
sms.Replies = append(sms.Replies, Replies{
|
||||
sms.Replies = append(sms.Replies, struct {
|
||||
Id string "json:\"id,omitempty\""
|
||||
Mention bool "json:\"mention\""
|
||||
}{
|
||||
Id: id,
|
||||
Mention: mention,
|
||||
})
|
||||
|
@ -25,8 +25,6 @@ func (c *Client) Start() {
|
||||
}
|
||||
|
||||
c.Socket.OnTextMessage = func(message string, _ gowebsocket.Socket) {
|
||||
fmt.Println(message)
|
||||
|
||||
// Parse data
|
||||
rawData := &struct {
|
||||
Type string `json:"type"`
|
||||
@ -56,7 +54,7 @@ func (c *Client) handleWebsocketAuth() {
|
||||
if c.SelfBot == nil {
|
||||
c.Socket.SendText(fmt.Sprintf("{\"type\":\"Authenticate\",\"token\":\"%s\"}", c.Token))
|
||||
} else {
|
||||
c.Socket.SendText(fmt.Sprintf("{\"type\":\"Authenticate\",\"result\":\"Success\",\"_id\":\"%s\",\"token\":\"%s\",\"user_id\":\"%s\",\"name\":\"Revoltgo\"}", c.SelfBot.Id, c.SelfBot.SessionToken, c.SelfBot.UserId))
|
||||
c.Socket.SendText(fmt.Sprintf("{\"type\":\"Authenticate\",\"id\":\"%s\",\"session_token\":\"%s\",\"user_id\":\"%s\"}", c.SelfBot.Id, c.SelfBot.SessionToken, c.SelfBot.UserId))
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +67,7 @@ func (c *Client) Destroy() {
|
||||
func (c *Client) ping() {
|
||||
for {
|
||||
time.Sleep(30 * time.Second)
|
||||
c.Socket.SendText("{\"type\":\"Ping\",\"data\":0}")
|
||||
c.Socket.SendText(fmt.Sprintf("{\"type\":\"Ping\",\"time\":%d}", time.Now().Unix()))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user