summaryrefslogtreecommitdiff
path: root/discord/pylon.lua
diff options
context:
space:
mode:
Diffstat (limited to 'discord/pylon.lua')
-rw-r--r--discord/pylon.lua37
1 files changed, 11 insertions, 26 deletions
diff --git a/discord/pylon.lua b/discord/pylon.lua
index 1ecc042..f84db64 100644
--- a/discord/pylon.lua
+++ b/discord/pylon.lua
@@ -1,23 +1,15 @@
local consts = require'discord.consts'
local websocket = require'http.websocket'
local json = require 'dkjson'
-local Queue = require 'util.queue'
+local Queue = require 'queue'
local exec_webhook = require'discord.the'
local cqueues = require 'cqueues'
+local pylon = require 'pylon'
-local Discord = {}
+local Discord = pylon.subclass "discord"
-function Discord.make(wilson, conf)
- local self = setmetatable(conf, {__index=Discord})
-
- for k,v in pairs {
- wilson = wilson,
- inbox = Queue.make(),
- } do self[k] = v end
-
- assert(self.token)
-
- return self
+function Discord.init(self)
+ self:check_config "token"
end
local function identify_payload(token)
@@ -44,14 +36,6 @@ function Discord._connect(self)
-- end
end
-function Discord.run(self)
- local cq = cqueues.new()
- self:_connect()
- cq:wrap(self.recving, self)
- cq:wrap(self.sending, self)
- print('discord', cq:loop())
-end
-
function Discord.recving(self)
for event in self.ws:each() do
print(event)
@@ -59,11 +43,12 @@ function Discord.recving(self)
end
function Discord.sending(self)
- local i = 1
- while true do
- exec_webhook(self.temp_wh, { username = "god", content = "h"..("i"):rep(i) })
- i = i + 1
- cqueues.sleep(1)
+ for dest_channel, message in self.inbox:iter() do
+ print('DDD',message.sender,message.body)
+ exec_webhook(self.temp_wh, {
+ username = message.sender,
+ content = message.body,
+ })
end
end