From 512239b986816d740882c4707bb8763110d485a4 Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Sun, 31 May 2020 01:13:57 -0500 Subject: [PATCH] Read token from file. --- src/client.nim | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/client.nim b/src/client.nim index 0515ea4..368bc77 100644 --- a/src/client.nim +++ b/src/client.nim @@ -1,4 +1,4 @@ -import websocket, asyncnet, asyncdispatch, json, httpClient, strformat, eventdispatcher, eventhandler +import websocket, asyncnet, asyncdispatch, json, httpClient, strformat, eventdispatcher, eventhandler, streams type DiscordOpCode = enum @@ -100,12 +100,27 @@ proc startConnection*(client: DiscordClient) {.async.} = e.msg = "Failed to get gateway url, token may of been incorrect!" raise e -var bot = DiscordClient(token: - "TOKEN") +var tokenStream = newFileStream("../token.txt", fmWrite) +var tkn: string +if (not isNil(tokenStream)): + discard tokenStream.readLine(tkn) + tokenStream.close() + +var bot = DiscordClient(token: tkn) registerEventListener(EventType.evtReady, proc(bEvt: BaseEvent) = - let event: ReadyEvent = ReadyEvent(bEvt) - echo "Ready and connected!" + let event = ReadyEvent(bEvt) + echo "Ready and connected 1!" +) + +registerEventListener(EventType.evtReady, proc(bEvt: BaseEvent) = + let event = ReadyEvent(bEvt) + echo "Ready and connected 2!" +) + +registerEventListener(EventType.evtMessageCreate, proc(bEvt: BaseEvent) = + let event = MessageCreateEvent(bEvt) + echo "Message was created!" ) waitFor bot.startConnection() \ No newline at end of file