Set members presence's and fix Activity constructor.
This commit is contained in:
parent
4a1798c346
commit
b40fe05df4
|
@ -1,6 +1,6 @@
|
|||
import json, discordobject, channel, member, options, nimcordutils, emoji
|
||||
import role, permission, httpcore, strformat, image, asyncdispatch, user
|
||||
import permission
|
||||
import permission, presence, tables
|
||||
|
||||
type
|
||||
VerificationLevel* = enum
|
||||
|
@ -244,7 +244,18 @@ proc newGuild*(json: JsonNode): Guild {.inline.} =
|
|||
if (json.contains("channels")):
|
||||
for channel in json["channels"]:
|
||||
g.channels.insert(newChannel(channel))
|
||||
#TODO: presences
|
||||
if (json.contains("presences")):
|
||||
# Parse all presences
|
||||
var tmpPresences = initTable[snowflake, Presence]()
|
||||
for presence in json["presences"]:
|
||||
tmpPresences.add(getIDFromJson(presence["user"]["id"].getStr()), newPresence(presence))
|
||||
|
||||
# Check if the `tmpPresences` variable has a presence for the member,
|
||||
# if it does, then update the member to include its presence.
|
||||
for member in g.members:
|
||||
if (tmpPresences.hasKey(member.user.id)):
|
||||
member.presence = tmpPresences[member.user.id]
|
||||
|
||||
if (json.contains("max_presences")):
|
||||
g.maxPresences = json["max_presences"].getInt()
|
||||
if (json.contains("max_members")):
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import discordobject, user, json, role, options, asyncdispatch, nimcordutils, httpcore, strformat, strutils
|
||||
import discordobject, user, json, role, options, asyncdispatch, nimcordutils, httpcore, strformat, strutils, presence
|
||||
|
||||
type GuildMember* = ref object of DiscordObject
|
||||
## This type is a guild member.
|
||||
|
@ -10,6 +10,7 @@ type GuildMember* = ref object of DiscordObject
|
|||
deaf*: bool ## Whether the user is deafened in voice channels.
|
||||
mute*: bool ## Whether the user is muted in voice channels.
|
||||
guildID*: snowflake ## The guild this member is in.
|
||||
presence*: Presence ## The member's presence.
|
||||
|
||||
proc newGuildMember*(json: JsonNode, guild: snowflake): GuildMember {.inline.} =
|
||||
## Construct a GuildMember using json.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import json, discordobject, emoji, nimcordutils, times
|
||||
import json, discordobject, emoji, nimcordutils, tables, times
|
||||
|
||||
type
|
||||
ClientStatus* = enum
|
||||
|
@ -12,7 +12,7 @@ type
|
|||
activityTypeGame = 0,
|
||||
activityTypeStreaming = 1,
|
||||
activityTypeListening = 2,
|
||||
activityTypeCustom = 3
|
||||
activityTypeCustom = 4
|
||||
|
||||
ActivityFlag* = enum
|
||||
activityFlagInstance = 0,
|
||||
|
@ -59,7 +59,7 @@ type
|
|||
flags*: uint
|
||||
|
||||
Presence* = ref object
|
||||
status*: ClientStatus
|
||||
status*: string
|
||||
game*: Activity
|
||||
activities*: seq[Activity]
|
||||
afk*: bool
|
||||
|
@ -74,9 +74,6 @@ proc newActivity*(json: JsonNode, guildID: snowflake): Activity =
|
|||
applicationID: getIDFromJson(json{"application_id"}.getStr()),
|
||||
details: json{"details"}.getStr(),
|
||||
state: json{"state"}.getStr(),
|
||||
#party?
|
||||
#assets?
|
||||
#secrets
|
||||
instance: json{"instance"}.getBool(),
|
||||
flags: uint(json{"flags"}.getInt()),
|
||||
)
|
||||
|
@ -122,10 +119,23 @@ proc newActivity*(json: JsonNode, guildID: snowflake): Activity =
|
|||
if (json["secrets"].contains("match")):
|
||||
secrets.match = json["secrets"]["match"].getStr()
|
||||
|
||||
proc newPresence*(json: JsonNode): Presence =
|
||||
## Parses Presence type from json.
|
||||
result = Presence(
|
||||
status: json["status"].getStr()
|
||||
)
|
||||
|
||||
if (json.contains("game") and json["game"].getFields().len > 0):
|
||||
result.game = newActivity(json["game"], getIDFromJson(json{"guild_id"}.getStr()))
|
||||
|
||||
if json.contains("activities"):
|
||||
for activity in json["activities"]:
|
||||
result.activities.add(newActivity(json["game"], getIDFromJson(json{"guild_id"}.getStr())))
|
||||
|
||||
proc newPresence*(text: string, `type`: ActivityType, status: ClientStatus, afk: bool = false): Presence =
|
||||
## Used to create a presence that you can use to update the presence of your bot's user.
|
||||
return Presence(
|
||||
status: status,
|
||||
status: $status,
|
||||
afk: afk,
|
||||
game: Activity(
|
||||
name: text,
|
||||
|
|
Reference in New Issue