diff options
author | ubq323 <ubq323@ubq323.website> | 2025-02-25 23:36:28 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2025-02-25 23:36:28 +0000 |
commit | e03937bbe51f3dd8e0d8ecc732999f5c4578fa94 (patch) | |
tree | 7c4e9c9427eade79d122d1175e273cc1eae170be /discord | |
parent | 7d396195e4f97a094610fecc658aed6a67fd464d (diff) |
mostly getting it to just go, also start on discord
Diffstat (limited to 'discord')
-rw-r--r-- | discord/consts.lua | 45 | ||||
-rw-r--r-- | discord/pylon.lua | 40 | ||||
-rw-r--r-- | discord/the.lua | 24 |
3 files changed, 109 insertions, 0 deletions
diff --git a/discord/consts.lua b/discord/consts.lua new file mode 100644 index 0000000..4727ef6 --- /dev/null +++ b/discord/consts.lua @@ -0,0 +1,45 @@ +local function flip(t) +for k,v in pairs(t) do t[v]=k end return t end + +local opcodes = flip { +[0] = "dispatch", +[1] = "heartbeat", +[2] = "identify", +[3] = "presence update", +[4] = "voice state update", +[6] = "resume", +[7] = "reconnect", +[8] = "request guild members", +[9] = "invalid session", +[10] = "hello", +[11] = "heartbeat ack", +[31] = "request soundboard sounds", +} + +local intents = flip { +guilds = 1 << 0, +guild_members = 1 << 1, +guild_moderation = 1 << 2, +guild_expressions = 1 << 3, +guild_integrations = 1 << 4, +guild_webhooks = 1 << 5, +guild_invites = 1 << 6, +guild_voice_states = 1 << 7, +guild_presences = 1 << 8, +guild_messages = 1 << 9, +guild_message_reactions = 1 << 10, +guild_message_typing = 1 << 11, +direct_messages = 1 << 12, +direct_message_reactions = 1 << 13, +direct_message_typing = 1 << 14, +message_content = 1 << 15, +guild_scheduled_events = 1 << 16, +auto_moderation_configuration = 1 << 20, +auto_moderation_execution = 1 << 21, +guild_message_polls = 1 << 24, +direct_message_polls = 1 << 25, +} +return { + opcodes = opcodes, + intents = intents, +} diff --git a/discord/pylon.lua b/discord/pylon.lua new file mode 100644 index 0000000..0200208 --- /dev/null +++ b/discord/pylon.lua @@ -0,0 +1,40 @@ +local consts = require'discord.consts' +local websocket = require'http.websocket' +local json = require 'dkjson' + +local Discord = {} + +function Discord.make(wilson,conf) + local self = { +end + + +local function identify_payload(token) + local I = consts.intents + return json.encode{ + op = consts.opcodes.identify, + d = { + properties = { + os = "wilson", + browser = "wilson", + device = "wilson", + }, + intents = I.guilds + I.guild_messages + I.message_content, + token = token, + } + } +end + +local token = 'NzY1NTMyNjgzMTQ4MzI4OTcw.GJCRVk.uvplnizyiRKxONvmKD4b8lq7Ju0QSqoPAmqj1w' + +local function connect() + local uri = "wss://gateway.discord.gg/?v=10&encoding=json" + local ws = websocket.new_from_uri(uri) + print(ws:connect()) + ws:send(identify_payload(token), 'text') + for a,b in ws:each() do + print('its',a,b) + end +end + +connect() diff --git a/discord/the.lua b/discord/the.lua new file mode 100644 index 0000000..27e0644 --- /dev/null +++ b/discord/the.lua @@ -0,0 +1,24 @@ +local http_request = require'http.request' +local dkjson = require'dkjson' +local url = 'https://discord.com/api/v8/webhooks/1277689699254800436/gzYU3voeunQsEdC797-hgXdTIbJDk09IVuj6l1t2alqbX9xS0d_St7bDWRkagUuQ3sat' + +local function exec_webhook(url, payload, debug) + local req = http_request.new_from_uri(url) + req.headers:upsert('content-type','application/json') + req.headers:upsert(':method','POST') + req:set_body(dkjson.encode(payload)) + local resp_head, resp_body = assert(req:go()) + local status = resp_head:get':status' + if debug then + resp_head:dump() + print() + print(resp_body:get_body_as_string()) + end + assert(status:sub(1,1) == '2', 'status was '..status..' not 2xx') +end + +return { grom = function(from,body) print(body) exec_webhook(url, { + content=body, + username=from, + }, true) end } + |