added create date calculator for channel.
This commit is contained in:
		
							
								
								
									
										16
									
								
								channel.go
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								channel.go
									
									
									
									
									
								
							| @@ -4,11 +4,15 @@ import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"reflect" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/oklog/ulid/v2" | ||||
| ) | ||||
|  | ||||
| // Channel struct. | ||||
| type Channel struct { | ||||
| 	Client    *Client | ||||
| 	CreatedAt time.Time | ||||
|  | ||||
| 	Id                 string      `json:"_id"` | ||||
| 	ChannelType        string      `json:"channel_type"` | ||||
| @@ -32,6 +36,18 @@ type FetchedMessages struct { | ||||
| 	Users    []*User    `json:"users"` | ||||
| } | ||||
|  | ||||
| // Calculate creation date and edit the struct. | ||||
| func (c *Channel) CalculateCreationDate() error { | ||||
| 	ulid, err := ulid.Parse(c.Id) | ||||
|  | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	c.CreatedAt = time.UnixMilli(int64(ulid.Time())) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // Send a message to the channel. | ||||
| func (c Channel) SendMessage(message *SendMessage) (*Message, error) { | ||||
| 	if message.Nonce == "" { | ||||
|   | ||||
							
								
								
									
										5
									
								
								http.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								http.go
									
									
									
									
									
								
							| @@ -2,6 +2,7 @@ package revoltgo | ||||
|  | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"fmt" | ||||
| 	"io/ioutil" | ||||
| 	"net/http" | ||||
| ) | ||||
| @@ -26,6 +27,10 @@ func (c Client) Request(method, path string, data []byte) ([]byte, error) { | ||||
| 		return []byte{}, err | ||||
| 	} | ||||
|  | ||||
| 	if !(resp.StatusCode >= 200 && resp.StatusCode < 300) { | ||||
| 		return []byte{}, fmt.Errorf(resp.Status) | ||||
| 	} | ||||
|  | ||||
| 	defer resp.Body.Close() | ||||
| 	body, err := ioutil.ReadAll(resp.Body) | ||||
|  | ||||
|   | ||||
| @@ -1,8 +1,11 @@ | ||||
| package revoltgo | ||||
|  | ||||
| import "time" | ||||
|  | ||||
| // Message struct | ||||
| type Message struct { | ||||
| 	Client    *Client | ||||
| 	CreatedAt time.Time | ||||
|  | ||||
| 	Id          string          `json:"_id"` | ||||
| 	Nonce       string          `json:"nonce"` | ||||
|   | ||||
							
								
								
									
										8
									
								
								other.go
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								other.go
									
									
									
									
									
								
							| @@ -45,10 +45,10 @@ func (sms *SendMessage) CreateNonce() *SendMessage { | ||||
| // Edit channel struct. | ||||
| // Please see: https://developers.revolt.chat/api/#tag/Channel-Information/paths/~1channels~1:channel/patch for more information. | ||||
| type EditChannel struct { | ||||
| 	Name        string `json:"name"` | ||||
| 	Description string `json:"description"` | ||||
| 	Icon        string `json:"icon"` | ||||
| 	Remove      string `json:"remove"` | ||||
| 	Name        string `json:"name,omitempty"` | ||||
| 	Description string `json:"description,omitempty"` | ||||
| 	Icon        string `json:"icon,omitempty"` | ||||
| 	Remove      string `json:"remove,omitempty"` | ||||
| } | ||||
|  | ||||
| // Set name for struct. | ||||
|   | ||||
							
								
								
									
										3
									
								
								user.go
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								user.go
									
									
									
									
									
								
							| @@ -1,8 +1,11 @@ | ||||
| package revoltgo | ||||
|  | ||||
| import "time" | ||||
|  | ||||
| // User struct. | ||||
| type User struct { | ||||
| 	Client    *Client | ||||
| 	CreatedAt time.Time | ||||
|  | ||||
| 	Id             string           `json:"_id"` | ||||
| 	Username       string           `json:"username"` | ||||
|   | ||||
		Reference in New Issue
	
	Block a user