diff --git a/src/member.nim b/src/member.nim new file mode 100644 index 0000000..33346b5 --- /dev/null +++ b/src/member.nim @@ -0,0 +1,28 @@ +import discordobject, user, json + +type GuildMember* = object of DiscordObject + ## This type is a guild member. + user*: User ## The user this guild member represents. + nick*: string ## This users guild nickname. + #roles*: seq[Role] ## Array of roles. + joinedAt*: string ## When the user joined the guild. + premiumSince*: string ## When the user started boosting the guild. + deaf*: bool ## Whether the user is deafened in voice channels. + mute*: bool ## Whether the user is muted in voice channels. + + +proc newGuildMember*(json: JsonNode): GuildMember = + var member = GuildMember( + nick: json["nick"].getStr(), + #roles: seq[Role] + joinedAt: json["joined_at"].getStr(), + premiumSince: json["premium_since"].getStr(), + deaf: json["deaf"].getBool(), + mute: json["mute"].getBool() + ) + + if (json.contains("user")): + member.user = newUser(json["user"]) + + return member + \ No newline at end of file diff --git a/src/user.nim b/src/user.nim index 5f41469..bf1eedc 100644 --- a/src/user.nim +++ b/src/user.nim @@ -1,15 +1,39 @@ -import discordobject +import json, discordobject, nimcordutils -type - User = ref object of DiscordObject - username*: string # username of the current user object - avatar_hash*: string # avatar hash of the current object - discriminator*: uint16 # discriminator of the current user object - flags: int # flags of the current user object - method GetDiscriminator(this: User): string = $(this.discriminator) -type - GuildMember = ref object of User - guild_id*: snowflake # id of the guild of the current member object - nickname*: string # nickname of the current member object - joined_at*: string # date the current member object joined at - hierarchy*: int # role hierarchy for the current member object +type + NitroSubscription* = enum + none = 0, + nitroClassic = 1, + nitro = 2 + + User* = object of DiscordObject + ## This type is a discord user. + username*: string ## The user's username, not unique across the platform. + discriminator*: cushort ## The user's 4-digit discord-tag. + avatar*: string ## The user's avatar hash. + bot*: bool ## Whether the user belongs to an OAuth2 application. + system*: bool ## Whether the user is an Official Discord System user (part of the urgent message system). + mfaEnabled*: bool ## Whether the user has two factor enabled on their account . + locale*: string ## The user's chosen language option . + verified*: bool ## Whether the email on this account has been verified. + email*: string ## The user's email. + flags*: int ## The flags on a user's account. + premiumType*: NitroSubscription ## The type of Nitro subscription on a user's account. + publicFlags*: int ## The public flags on a user's account. + +proc newUser*(json: json.JsonNode): User = + return User( + id: getIDFromJson(json["id"].getStr()), + username: json["username"].getStr(), + discriminator: cushort(json["discriminator"].getInt()), + avatar: json["avatar"].getStr(), + bot: json{"bot"}.getBool(), + system: json{"system"}.getBool(), + mfaEnabled: json{"mfa_enabled"}.getBool(), + locale: json{"locale"}.getStr(), + verified: json["verified"].getBool(), + email: json["email"].getStr(), + flags: json["flags"].getInt(), + premiumType: NitroSubscription(json["premium_type"].getInt()), + publicFlags: json["public_flags"].getInt() + ) \ No newline at end of file