From 28649645e3c1e949f8dfc8a24f09944f3b26c07b Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Thu, 18 Jun 2020 18:27:03 -0500 Subject: [PATCH] Add new permissions constructor and create Role type --- src/permission.nim | 4 ++++ src/role.nim | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/role.nim diff --git a/src/permission.nim b/src/permission.nim index f0b41d2..12da17d 100644 --- a/src/permission.nim +++ b/src/permission.nim @@ -44,6 +44,10 @@ type denyPerms*: uint 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 = ## Parses a `Permissions` from json. result = Permissions( diff --git a/src/role.nim b/src/role.nim new file mode 100644 index 0000000..66d183c --- /dev/null +++ b/src/role.nim @@ -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() + ) \ No newline at end of file