Add new permissions constructor and create Role type

This commit is contained in:
SeanOMik 2020-06-18 18:27:03 -05:00
parent 153b5ee764
commit 28649645e3
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
2 changed files with 26 additions and 0 deletions

View File

@ -44,6 +44,10 @@ type
denyPerms*: uint denyPerms*: uint
permissionType*: PermissionType permissionType*: PermissionType
proc newPermissions*(id: snowflake, `type`: PermissionType, byteSet: uint): Permissions =
## Create a new `Permissions` using an id, type, and byte set.
result = Permissions(roleUserID: id, permissionType: `type`, allowPerms: byteSet)
proc newPermissions*(json: JsonNode): Permissions = proc newPermissions*(json: JsonNode): Permissions =
## Parses a `Permissions` from json. ## Parses a `Permissions` from json.
result = Permissions( result = Permissions(

22
src/role.nim Normal file
View File

@ -0,0 +1,22 @@
import json, nimcordutils, discordobject, permission
type Role* = ref object of DiscordObject
name*: string
color*: uint
hoist*: bool
position*: uint
permissions*: Permissions
managed*: bool
mentionable*: bool
proc newRole*(json: JsonNode): Role =
result = Role(
id: getIDFromJson(json["id"].getStr()),
name: json["name"].getStr(),
color: uint(json["color"].getInt()),
hoist: json["hoist"].getBool(),
position: uint(json["position"].getInt()),
permissions: newPermissions(json["permissions"]),
managed: json["managed"].getBool(),
mentionable: json["mentionable"].getBool()
)