Add some documentation
This commit is contained in:
parent
f5bab02a83
commit
58020c2cc7
|
@ -2,7 +2,7 @@ import json, discordobject, user, options, nimcordutils, message, httpcore, asyn
|
||||||
|
|
||||||
type
|
type
|
||||||
ChannelType* = enum
|
ChannelType* = enum
|
||||||
chanTypeNIL = -1,
|
## This enum shows the type of the channel.
|
||||||
chanTypeGuildText = 0,
|
chanTypeGuildText = 0,
|
||||||
chanTypeDM = 1,
|
chanTypeDM = 1,
|
||||||
chanTypeGuildVoice = 2,
|
chanTypeGuildVoice = 2,
|
||||||
|
@ -12,6 +12,7 @@ type
|
||||||
chanTypeGuildStore = 6
|
chanTypeGuildStore = 6
|
||||||
|
|
||||||
Channel* = ref object of DiscordObject
|
Channel* = ref object of DiscordObject
|
||||||
|
## Discord channel object.
|
||||||
`type`*: ChannelType ## The type of channel.
|
`type`*: ChannelType ## The type of channel.
|
||||||
guildID*: snowflake ## The id of the guild.
|
guildID*: snowflake ## The id of the guild.
|
||||||
position*: int ## Sorting position of the channel.
|
position*: int ## Sorting position of the channel.
|
||||||
|
@ -43,14 +44,8 @@ type
|
||||||
#permissionOverwrites*: seq[Permissions] ## Explicit permission overwrites for members and roles.
|
#permissionOverwrites*: seq[Permissions] ## Explicit permission overwrites for members and roles.
|
||||||
parentID*: Option[snowflake]
|
parentID*: Option[snowflake]
|
||||||
|
|
||||||
#[ proc newChannelModify*(name: Option[string], `type`: Option[ChannelType], position: Option[int],
|
|
||||||
topic: Option[string], nsfw: Option[bool], rateLimitPerUser: Option[int], bitrate: Option[int],
|
|
||||||
userLimit: Option[int], parentID: Option[snowflake]): ChannelModify =
|
|
||||||
|
|
||||||
return ChannelModify(name: name.get, `type`:`type`, position: position, nsfw: nsfw,
|
|
||||||
rateLimitPerUser: rateLimitPerUser, bitrate: bitrate, userLimit: userLimit, parentID: parentID) ]#
|
|
||||||
|
|
||||||
proc newChannel*(channel: JsonNode): Channel {.inline.} =
|
proc newChannel*(channel: JsonNode): Channel {.inline.} =
|
||||||
|
## Parses the channel from json.
|
||||||
var chan = Channel(
|
var chan = Channel(
|
||||||
id: getIDFromJson(channel["id"].getStr()),
|
id: getIDFromJson(channel["id"].getStr()),
|
||||||
`type`: ChannelType(channel["type"].getInt()),
|
`type`: ChannelType(channel["type"].getInt()),
|
||||||
|
@ -93,6 +88,7 @@ proc newChannel*(channel: JsonNode): Channel {.inline.} =
|
||||||
return chan
|
return chan
|
||||||
|
|
||||||
proc sendMessage*(channel: Channel, content: string, tts: bool = false): Message =
|
proc sendMessage*(channel: Channel, content: string, tts: bool = false): Message =
|
||||||
|
## Send a message through the channel.
|
||||||
let messagePayload = %*{"content": content, "tts": tts}
|
let messagePayload = %*{"content": content, "tts": tts}
|
||||||
|
|
||||||
return newMessage(sendRequest(endpoint("/channels/" & $channel.id & "/messages"), HttpPost,
|
return newMessage(sendRequest(endpoint("/channels/" & $channel.id & "/messages"), HttpPost,
|
||||||
|
@ -100,6 +96,14 @@ proc sendMessage*(channel: Channel, content: string, tts: bool = false): Message
|
||||||
RateLimitBucketType.channel, messagePayload))
|
RateLimitBucketType.channel, messagePayload))
|
||||||
|
|
||||||
proc modifyChannel*(channel: Channel, modify: ChannelModify): Future[Channel] {.async.} =
|
proc modifyChannel*(channel: Channel, modify: ChannelModify): Future[Channel] {.async.} =
|
||||||
|
## Modifies the channel.
|
||||||
|
##
|
||||||
|
## Examples:
|
||||||
|
## ```nim
|
||||||
|
## var chan = getChannel(703084913510973472)
|
||||||
|
## chan = chan.modifyChannel(ChannelModify(topic: some("This is the channel topic")))
|
||||||
|
## ```
|
||||||
|
|
||||||
var modifyPayload = %*{}
|
var modifyPayload = %*{}
|
||||||
|
|
||||||
if (modify.name.isSome):
|
if (modify.name.isSome):
|
||||||
|
@ -137,5 +141,6 @@ proc modifyChannel*(channel: Channel, modify: ChannelModify): Future[Channel] {.
|
||||||
channel.id, RateLimitBucketType.channel, modifyPayload))
|
channel.id, RateLimitBucketType.channel, modifyPayload))
|
||||||
|
|
||||||
proc deleteChannel*(channel: Channel) {.async.} =
|
proc deleteChannel*(channel: Channel) {.async.} =
|
||||||
|
## Delete the channel.
|
||||||
discard sendRequest(endpoint("/channels/" & $channel.id), HttpDelete,
|
discard sendRequest(endpoint("/channels/" & $channel.id), HttpDelete,
|
||||||
defaultHeaders(), channel.id, RateLimitBucketType.channel)
|
defaultHeaders(), channel.id, RateLimitBucketType.channel)
|
|
@ -1,6 +1,7 @@
|
||||||
import websocket, cache, user
|
import websocket, cache, user
|
||||||
|
|
||||||
type DiscordClient* = ref object ## Discord Client
|
type DiscordClient* = ref object
|
||||||
|
## Discord Client
|
||||||
token*: string
|
token*: string
|
||||||
clientUser*: User
|
clientUser*: User
|
||||||
cache*: Cache
|
cache*: Cache
|
||||||
|
|
Reference in New Issue