added edit server struct.
This commit is contained in:
parent
23077a7b70
commit
1d8511895c
@ -158,15 +158,6 @@ func (c *Channel) Edit(ec *EditChannel) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change channel struct
|
|
||||||
if ec.Name != "" {
|
|
||||||
c.Name = ec.Name
|
|
||||||
}
|
|
||||||
|
|
||||||
if ec.Description != "" {
|
|
||||||
c.Description = ec.Description
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
86
other.go
86
other.go
@ -53,18 +53,30 @@ type EditChannel struct {
|
|||||||
|
|
||||||
// Set name for struct.
|
// Set name for struct.
|
||||||
func (ec *EditChannel) SetName(name string) *EditChannel {
|
func (ec *EditChannel) SetName(name string) *EditChannel {
|
||||||
|
if len(name) < 1 || len(name) > 32 {
|
||||||
|
return ec
|
||||||
|
}
|
||||||
|
|
||||||
ec.Name = name
|
ec.Name = name
|
||||||
return ec
|
return ec
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set description for struct.
|
// Set description for struct.
|
||||||
func (ec *EditChannel) SetDescription(desc string) *EditChannel {
|
func (ec *EditChannel) SetDescription(desc string) *EditChannel {
|
||||||
|
if len(desc) > 1024 {
|
||||||
|
return ec
|
||||||
|
}
|
||||||
|
|
||||||
ec.Description = desc
|
ec.Description = desc
|
||||||
return ec
|
return ec
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set icon for struct.
|
// Set icon for struct.
|
||||||
func (ec *EditChannel) SetIcon(autumn_id string) *EditChannel {
|
func (ec *EditChannel) SetIcon(autumn_id string) *EditChannel {
|
||||||
|
if len(autumn_id) < 1 || len(autumn_id) > 128 {
|
||||||
|
return ec
|
||||||
|
}
|
||||||
|
|
||||||
ec.Icon = autumn_id
|
ec.Icon = autumn_id
|
||||||
return ec
|
return ec
|
||||||
}
|
}
|
||||||
@ -78,3 +90,77 @@ func (ec *EditChannel) RemoveItem(item string) *EditChannel {
|
|||||||
ec.Remove = item
|
ec.Remove = item
|
||||||
return ec
|
return ec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Edit server struct.
|
||||||
|
// Please see https://developers.revolt.chat/api/#tag/Server-Information/paths/~1servers~1:server/patch for more detail.
|
||||||
|
type EditServer struct {
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
Description string `json:"description,omitempty"`
|
||||||
|
Icon string `json:"icon,omitempty"`
|
||||||
|
Banner string `json:"banner,omitempty"`
|
||||||
|
Categories []*ServerCategory `json:"categories,omitempty"`
|
||||||
|
SystemMessages *SystemMessages `json:"system_messages,omitempty"`
|
||||||
|
Remove string `json:"remove,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set name for struct
|
||||||
|
func (es *EditServer) SetName(name string) *EditServer {
|
||||||
|
if len(name) < 1 || len(name) > 32 {
|
||||||
|
return es
|
||||||
|
}
|
||||||
|
|
||||||
|
es.Name = name
|
||||||
|
return es
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set description for struct.
|
||||||
|
func (es *EditServer) SetDescription(desc string) *EditServer {
|
||||||
|
if len(desc) > 1024 {
|
||||||
|
return es
|
||||||
|
}
|
||||||
|
|
||||||
|
es.Description = desc
|
||||||
|
return es
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set icon for struct.
|
||||||
|
func (es *EditServer) SetIcon(autumn_id string) *EditServer {
|
||||||
|
if len(autumn_id) < 1 || len(autumn_id) > 128 {
|
||||||
|
return es
|
||||||
|
}
|
||||||
|
|
||||||
|
es.Icon = autumn_id
|
||||||
|
return es
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set banner for struct.
|
||||||
|
func (es *EditServer) SetBanner(autumn_id string) *EditServer {
|
||||||
|
if len(autumn_id) < 1 || len(autumn_id) > 128 {
|
||||||
|
return es
|
||||||
|
}
|
||||||
|
|
||||||
|
es.Banner = autumn_id
|
||||||
|
return es
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a new category for struct.
|
||||||
|
func (es *EditServer) AddCategory(category *ServerCategory) *EditServer {
|
||||||
|
es.Categories = append(es.Categories, category)
|
||||||
|
return es
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set system messages for struct.
|
||||||
|
func (es *EditServer) SetSystemMessages(sm *SystemMessages) *EditServer {
|
||||||
|
es.SystemMessages = sm
|
||||||
|
return es
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set remove item.
|
||||||
|
func (es *EditServer) RemoveItem(item string) *EditServer {
|
||||||
|
if item != "Description" && item != "Banner" && item != "Icon" {
|
||||||
|
return es
|
||||||
|
}
|
||||||
|
|
||||||
|
es.Remove = item
|
||||||
|
return es
|
||||||
|
}
|
||||||
|
12
server.go
12
server.go
@ -17,7 +17,7 @@ type Server struct {
|
|||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
ChannelIds []string `json:"channels"`
|
ChannelIds []string `json:"channels"`
|
||||||
Categories []*ServerCategories `json:"categories"`
|
Categories []*ServerCategory `json:"categories"`
|
||||||
SystemMessages *SystemMessages `json:"system_messages"`
|
SystemMessages *SystemMessages `json:"system_messages"`
|
||||||
Roles map[string]interface{} `json:"roles"`
|
Roles map[string]interface{} `json:"roles"`
|
||||||
DefaultPermissions []interface{} `json:"default_permissions"`
|
DefaultPermissions []interface{} `json:"default_permissions"`
|
||||||
@ -26,7 +26,7 @@ type Server struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Server categories struct.
|
// Server categories struct.
|
||||||
type ServerCategories struct {
|
type ServerCategory struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
ChannelIds []string `json:"channels"`
|
ChannelIds []string `json:"channels"`
|
||||||
@ -34,10 +34,10 @@ type ServerCategories struct {
|
|||||||
|
|
||||||
// System messages struct.
|
// System messages struct.
|
||||||
type SystemMessages struct {
|
type SystemMessages struct {
|
||||||
UserJoined string `json:"user_joined"`
|
UserJoined string `json:"user_joined,omitempty"`
|
||||||
UserLeft string `json:"user_left"`
|
UserLeft string `json:"user_left,omitempty"`
|
||||||
UserKicked string `json:"user_kicker"`
|
UserKicked string `json:"user_kicker,omitempty"`
|
||||||
UserBanned string `json:"user_banned"`
|
UserBanned string `json:"user_banned,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate creation date and edit the struct.
|
// Calculate creation date and edit the struct.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user