Read token from file.

This commit is contained in:
SeanOMik 2020-05-31 01:13:57 -05:00
parent 5d33830255
commit 512239b986
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
1 changed files with 20 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import websocket, asyncnet, asyncdispatch, json, httpClient, strformat, eventdispatcher, eventhandler import websocket, asyncnet, asyncdispatch, json, httpClient, strformat, eventdispatcher, eventhandler, streams
type type
DiscordOpCode = enum DiscordOpCode = enum
@ -100,12 +100,27 @@ proc startConnection*(client: DiscordClient) {.async.} =
e.msg = "Failed to get gateway url, token may of been incorrect!" e.msg = "Failed to get gateway url, token may of been incorrect!"
raise e raise e
var bot = DiscordClient(token: var tokenStream = newFileStream("../token.txt", fmWrite)
"TOKEN") var tkn: string
if (not isNil(tokenStream)):
discard tokenStream.readLine(tkn)
tokenStream.close()
var bot = DiscordClient(token: tkn)
registerEventListener(EventType.evtReady, proc(bEvt: BaseEvent) = registerEventListener(EventType.evtReady, proc(bEvt: BaseEvent) =
let event: ReadyEvent = ReadyEvent(bEvt) let event = ReadyEvent(bEvt)
echo "Ready and connected!" 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() waitFor bot.startConnection()