Add more fields to User type and create Member type. Also constructors
This commit is contained in:
parent
858ccf33c7
commit
140d173d8d
|
@ -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
|
||||||
|
|
50
src/user.nim
50
src/user.nim
|
@ -1,15 +1,39 @@
|
||||||
import discordobject
|
import json, discordobject, nimcordutils
|
||||||
|
|
||||||
type
|
type
|
||||||
User = ref object of DiscordObject
|
NitroSubscription* = enum
|
||||||
username*: string # username of the current user object
|
none = 0,
|
||||||
avatar_hash*: string # avatar hash of the current object
|
nitroClassic = 1,
|
||||||
discriminator*: uint16 # discriminator of the current user object
|
nitro = 2
|
||||||
flags: int # flags of the current user object
|
|
||||||
method GetDiscriminator(this: User): string = $(this.discriminator)
|
User* = object of DiscordObject
|
||||||
type
|
## This type is a discord user.
|
||||||
GuildMember = ref object of User
|
username*: string ## The user's username, not unique across the platform.
|
||||||
guild_id*: snowflake # id of the guild of the current member object
|
discriminator*: cushort ## The user's 4-digit discord-tag.
|
||||||
nickname*: string # nickname of the current member object
|
avatar*: string ## The user's avatar hash.
|
||||||
joined_at*: string # date the current member object joined at
|
bot*: bool ## Whether the user belongs to an OAuth2 application.
|
||||||
hierarchy*: int # role hierarchy for the current member object
|
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()
|
||||||
|
)
|
Reference in New Issue