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