summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--discord/pylon.lua19
1 files changed, 18 insertions, 1 deletions
diff --git a/discord/pylon.lua b/discord/pylon.lua
index 7f7549b..d38b8a7 100644
--- a/discord/pylon.lua
+++ b/discord/pylon.lua
@@ -4,12 +4,14 @@ local websocket = require'http.websocket'
local json = require 'dkjson'
local Queue = require 'queue'
local exec_webhook = require'discord.the'
+local http_request = require'http.request'
local cqueues = require 'cqueues'
local pylon = require 'pylon'
local pprint = require 'pprint'
local Channel = require 'channel'
local Discord = pylon.subclass "discord"
+local API_BASE = "https://discord.com/api/v10/"
function Discord.init(self)
self:check_config "token"
@@ -29,11 +31,26 @@ local function identify_payload(token)
}
end
+function Discord._req_get(self, url)
+ local req = http_request.new_from_uri(API_BASE..url)
+ req.headers:upsert('content-type','application/json')
+ req.headers:upsert(':method','GET')
+ req.headers:upsert('authorization','Bot '..self.token)
+ req.headers:upsert('user-agent','wilson (https://g.gh0.pw/wilson/, v0.0)')
+ local head,body = assert(req:go())
+ local status = head:get':status'
+ assert(status:sub(1,1)=='2','status was '..status)
+ return body:get_body_as_string()
+end
+
function Discord._connect(self)
local uri = "wss://gateway.discord.gg/?v=10&encoding=json"
self.ws = websocket.new_from_uri(uri)
assert(self.ws:connect())
self.ws:send(identify_payload(self.token), 'text')
+
+ local me = self:_req_get"users/@me"
+ pprint('I AM ',me)
end
function Discord._heartbeat(self, interval_ms)
@@ -52,7 +69,7 @@ function Discord.recving(self)
for packet in self.ws:each() do
local event = json.decode(packet)
print(event.s, event.op, event.t)
- if event.op ~= opcodes.dispatch then
+ if true or event.op ~= opcodes.dispatch then
pprint(event.d)
end