Browse Source

Added support for setting channel permission overrides, closes #20

Bruce Marriner 9 years ago
parent
commit
57a5245657
2 changed files with 25 additions and 0 deletions
  1. 1 0
      endpoints.go
  2. 24 0
      restapi.go

+ 1 - 0
endpoints.go

@@ -69,6 +69,7 @@ var (
 
 	CHANNEL             = func(cID string) string { return CHANNELS + cID }
 	CHANNEL_PERMISSIONS = func(cID string) string { return CHANNELS + cID + "/permissions" }
+	CHANNEL_PERMISSION  = func(cID, tID string) string { return CHANNELS + cID + "/permissions/" + tID }
 	CHANNEL_INVITES     = func(cID string) string { return CHANNELS + cID + "/invites" }
 	CHANNEL_TYPING      = func(cID string) string { return CHANNELS + cID + "/typing" }
 	CHANNEL_MESSAGES    = func(cID string) string { return CHANNELS + cID + "/messages" }

+ 24 - 0
restapi.go

@@ -560,6 +560,30 @@ func (s *Session) ChannelInviteCreate(channelID string, i Invite) (st Invite, er
 	return
 }
 
+// ChannelPermissionSet creates a Permission Override for the given channel.
+// NOTE: This func name may changed.  Using Set instead of Create because
+// you can both create a new override or update an override with this function.
+func (s *Session) ChannelPermissionSet(channelID, targetID, targetType string, allow, deny int) (err error) {
+
+	data := struct {
+		ID    string `json:"id"`
+		Type  string `json:"type"`
+		Allow int    `json:"allow"`
+		Deny  int    `json:"deny"`
+	}{targetID, targetType, allow, deny}
+
+	_, err = s.Request("PUT", CHANNEL_PERMISSION(channelID, targetID), data)
+	return
+}
+
+// ChannelPermissionDelete deletes a specific permission override for the given channel.
+// NOTE: Name of this func may change.
+func (s *Session) ChannelPermissionDelete(channelID, targetID string) (err error) {
+
+	_, err = s.Request("DELETE", CHANNEL_PERMISSION(channelID, targetID), nil)
+	return
+}
+
 // ------------------------------------------------------------------------------------------------
 // Functions specific to Discord Invites
 // ------------------------------------------------------------------------------------------------