diff --git a/src/channel.nim b/src/channel.nim index 35b44c0..af0ba36 100644 --- a/src/channel.nim +++ b/src/channel.nim @@ -144,9 +144,10 @@ proc modifyChannel*(channel: Channel, modify: ChannelModify): Future[Channel] {. ## Modifies the channel. ## ## Examples: + ## ## .. code-block:: nim - ## var chan = getChannel(703084913510973472) - ## chan = chan.modifyChannel(ChannelModify(topic: some("This is the channel topic"))) + ## var chan = getChannel(703084913510973472) + ## chan = chan.modifyChannel(ChannelModify(topic: some("This is the channel topic"))) var modifyPayload = %*{} @@ -204,6 +205,7 @@ proc getMessages*(channel: Channel, request: MessagesGetRequest): seq[Message] = ## Gets messages from the channel. ## ## Examples: + ## ## .. code-block:: nim ## var chan = getChannel(703084913510973472) ## 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. ## ## Examples: + ## ## .. code-block:: nim ## var chan = getChannel(703084913510973472) ## # Create an invite that lasts 1 day, and can only be used 10 times diff --git a/src/client.nim b/src/client.nim index 8786dff..87140d2 100644 --- a/src/client.nim +++ b/src/client.nim @@ -21,13 +21,9 @@ type opHello = 10, 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.} = + ## Send a gateway request. + ## Don't use this unless you know what you're doing! if (msg.len == 0): echo "Sending gateway payload: ", request else: @@ -79,7 +75,21 @@ proc handleWebsocketPacket(client: DiscordClient) {.async.} = discard 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")): 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!") proc newDiscordClient(tkn: string): DiscordClient = + ## Create a DiscordClient using a token. globalToken = tkn var cac: Cache