Fix code blocks and add documentation for some client procs.
This commit is contained in:
parent
6d7897a100
commit
9e4da6a718
|
@ -144,9 +144,10 @@ proc modifyChannel*(channel: Channel, modify: ChannelModify): Future[Channel] {.
|
||||||
## Modifies the channel.
|
## Modifies the channel.
|
||||||
##
|
##
|
||||||
## Examples:
|
## Examples:
|
||||||
|
##
|
||||||
## .. code-block:: nim
|
## .. code-block:: nim
|
||||||
## var chan = getChannel(703084913510973472)
|
## var chan = getChannel(703084913510973472)
|
||||||
## chan = chan.modifyChannel(ChannelModify(topic: some("This is the channel topic")))
|
## chan = chan.modifyChannel(ChannelModify(topic: some("This is the channel topic")))
|
||||||
|
|
||||||
var modifyPayload = %*{}
|
var modifyPayload = %*{}
|
||||||
|
|
||||||
|
@ -204,6 +205,7 @@ proc getMessages*(channel: Channel, request: MessagesGetRequest): seq[Message] =
|
||||||
## Gets messages from the channel.
|
## Gets messages from the channel.
|
||||||
##
|
##
|
||||||
## Examples:
|
## Examples:
|
||||||
|
##
|
||||||
## .. code-block:: nim
|
## .. code-block:: nim
|
||||||
## var chan = getChannel(703084913510973472)
|
## var chan = getChannel(703084913510973472)
|
||||||
## channel.getMessages(MessagesGetRequest(limit: some(15), before: some(723030179760570428)))
|
## channel.getMessages(MessagesGetRequest(limit: some(15), before: some(723030179760570428)))
|
||||||
|
@ -302,6 +304,7 @@ proc createChannelInvite*(channel: Channel, fields: CreateInviteFields): Invite
|
||||||
## Requires the CREATE_INSTANT_INVITE permission.
|
## Requires the CREATE_INSTANT_INVITE permission.
|
||||||
##
|
##
|
||||||
## Examples:
|
## Examples:
|
||||||
|
##
|
||||||
## .. code-block:: nim
|
## .. code-block:: nim
|
||||||
## var chan = getChannel(703084913510973472)
|
## var chan = getChannel(703084913510973472)
|
||||||
## # Create an invite that lasts 1 day, and can only be used 10 times
|
## # Create an invite that lasts 1 day, and can only be used 10 times
|
||||||
|
|
|
@ -21,13 +21,9 @@ type
|
||||||
opHello = 10,
|
opHello = 10,
|
||||||
opHeartbeatAck = 11
|
opHeartbeatAck = 11
|
||||||
|
|
||||||
proc defaultHeaders*(client: DiscordClient, added: HttpHeaders = newHttpHeaders()): HttpHeaders =
|
|
||||||
added.add("Authorization", fmt("Bot {client.token}"))
|
|
||||||
added.add("User-Agent", "NimCord (https://github.com/SeanOMik/nimcord, v0.0.0)")
|
|
||||||
added.add("X-RateLimit-Precision", "millisecond")
|
|
||||||
return added;
|
|
||||||
|
|
||||||
proc sendGatewayRequest*(client: DiscordClient, request: JsonNode, msg: string = "") {.async.} =
|
proc sendGatewayRequest*(client: DiscordClient, request: JsonNode, msg: string = "") {.async.} =
|
||||||
|
## Send a gateway request.
|
||||||
|
## Don't use this unless you know what you're doing!
|
||||||
if (msg.len == 0):
|
if (msg.len == 0):
|
||||||
echo "Sending gateway payload: ", request
|
echo "Sending gateway payload: ", request
|
||||||
else:
|
else:
|
||||||
|
@ -79,7 +75,21 @@ proc handleWebsocketPacket(client: DiscordClient) {.async.} =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc startConnection*(client: DiscordClient) {.async.} =
|
proc startConnection*(client: DiscordClient) {.async.} =
|
||||||
let urlResult = sendRequest(endpoint("/gateway/bot"), HttpMethod.HttpGet, client.defaultHeaders())
|
## Start a bot connection.
|
||||||
|
##
|
||||||
|
## Examples:
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## var tokenStream = newFileStream("token.txt", fmRead)
|
||||||
|
## var tkn: string
|
||||||
|
## if (not isNil(tokenStream)):
|
||||||
|
## discard tokenStream.readLine(tkn)
|
||||||
|
## echo "Read token from the file: ", tkn
|
||||||
|
##
|
||||||
|
## tokenStream.close()
|
||||||
|
##
|
||||||
|
## var bot = newDiscordClient(tkn)
|
||||||
|
let urlResult = sendRequest(endpoint("/gateway/bot"), HttpMethod.HttpGet, defaultHeaders())
|
||||||
if (urlResult.contains("url")):
|
if (urlResult.contains("url")):
|
||||||
let url = urlResult["url"].getStr()
|
let url = urlResult["url"].getStr()
|
||||||
|
|
||||||
|
@ -93,6 +103,7 @@ proc startConnection*(client: DiscordClient) {.async.} =
|
||||||
raise newException(IOError, "Failed to get gateway url, token may of been incorrect!")
|
raise newException(IOError, "Failed to get gateway url, token may of been incorrect!")
|
||||||
|
|
||||||
proc newDiscordClient(tkn: string): DiscordClient =
|
proc newDiscordClient(tkn: string): DiscordClient =
|
||||||
|
## Create a DiscordClient using a token.
|
||||||
globalToken = tkn
|
globalToken = tkn
|
||||||
|
|
||||||
var cac: Cache
|
var cac: Cache
|
||||||
|
|
Reference in New Issue