summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2025-02-25 23:36:28 +0000
committerubq323 <ubq323@ubq323.website>2025-02-25 23:36:28 +0000
commite03937bbe51f3dd8e0d8ecc732999f5c4578fa94 (patch)
tree7c4e9c9427eade79d122d1175e273cc1eae170be
parent7d396195e4f97a094610fecc658aed6a67fd464d (diff)
mostly getting it to just go, also start on discord
-rw-r--r--config.lua2
-rw-r--r--discord/consts.lua45
-rw-r--r--discord/pylon.lua40
-rw-r--r--discord/the.lua (renamed from discord.lua)0
-rw-r--r--irc.lua3
-rw-r--r--main.lua1
-rw-r--r--wilson.ini35
-rw-r--r--wilson_ex.ini35
-rw-r--r--xmpp.lua23
9 files changed, 146 insertions, 38 deletions
diff --git a/config.lua b/config.lua
index a8838c8..c19a087 100644
--- a/config.lua
+++ b/config.lua
@@ -24,7 +24,7 @@ local function parse_file(file)
local line_handler = function() error("line outside of block") end
for line in file:lines() do
- line = line:gsub("#.*$",""):gsub("^%s*",""):gsub("%s*$","")
+ line = line:gsub(";.*$",""):gsub("^%s*",""):gsub("%s*$","")
if line == '' then goto next end
local block_type, block_name = line:match"%[%s*(%S+)%s+(%S+)%s*%]"
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.lua b/discord/the.lua
index 27e0644..27e0644 100644
--- a/discord.lua
+++ b/discord/the.lua
diff --git a/irc.lua b/irc.lua
index fe35753..a2fb7bf 100644
--- a/irc.lua
+++ b/irc.lua
@@ -3,6 +3,7 @@ local socket = require'cqueues.socket'
local pprint = require'pprint'
local rirc = require'rirc'
local Queue = require'queue'
+local Channel = require'channel'
local Irc = {}
@@ -89,7 +90,7 @@ function Irc.sending(self)
end
function Irc.post(self, dest_channel, message)
- self.inbox.enqueue(dest_channel, message)
+ self.inbox:enqueue(dest_channel, message)
end
return Irc
diff --git a/main.lua b/main.lua
index b347410..1f422e6 100644
--- a/main.lua
+++ b/main.lua
@@ -5,6 +5,7 @@ local Channel = require'channel'
local pylon_classes = {
irc = require'irc',
xmpp = require'xmpp',
+ discord = require'discord',
}
local Wilson = {}
diff --git a/wilson.ini b/wilson.ini
index df80e09..8aa1900 100644
--- a/wilson.ini
+++ b/wilson.ini
@@ -1,35 +1,16 @@
-# [pylon discord]
-# type=discord
-# token=abcdef123456
-
-[pylon apionet-irc]
+[pylon local-irc]
type=irc
-host=ubq323.website
-nick=wilson
+host=localhost
port=6667
-password=secretpassword
+password=mypassword
nodename=wilson.ubq323
[pylon ubq-xmpp]
type=xmpp
-jid=wilson@ubq323.website
-server=ubq323.website
-password=zyxw9876
-default-service=conference.ubq323.website
-resource=wilson
+server=localhost
component=wilson.ubq323.website
-component_secret=my_secret_password
-
-
-[bus a]
-# apionet a
-# discord 12345678 # esoserver #apionet
-# discord 98765432 # apionet discord #a
-ubq-xmpp a@
-apionet-irc a
-
-[bus ja]
-# discord 3141592654 # apionet discord #ja
-apionet-irc ja
-ubq-xmpp ja@
+component_secret=super_secret_wilson_password
+[bus test]
+ubq-xmpp d@conference.ubq323.website
+local-irc #test
diff --git a/wilson_ex.ini b/wilson_ex.ini
new file mode 100644
index 0000000..df80e09
--- /dev/null
+++ b/wilson_ex.ini
@@ -0,0 +1,35 @@
+# [pylon discord]
+# type=discord
+# token=abcdef123456
+
+[pylon apionet-irc]
+type=irc
+host=ubq323.website
+nick=wilson
+port=6667
+password=secretpassword
+nodename=wilson.ubq323
+
+[pylon ubq-xmpp]
+type=xmpp
+jid=wilson@ubq323.website
+server=ubq323.website
+password=zyxw9876
+default-service=conference.ubq323.website
+resource=wilson
+component=wilson.ubq323.website
+component_secret=my_secret_password
+
+
+[bus a]
+# apionet a
+# discord 12345678 # esoserver #apionet
+# discord 98765432 # apionet discord #a
+ubq-xmpp a@
+apionet-irc a
+
+[bus ja]
+# discord 3141592654 # apionet discord #ja
+apionet-irc ja
+ubq-xmpp ja@
+
diff --git a/xmpp.lua b/xmpp.lua
index 0b7a33d..5c3371b 100644
--- a/xmpp.lua
+++ b/xmpp.lua
@@ -1,4 +1,3 @@
-
local cqueues = require'cqueues'
local cqaux = require'cqueues.auxlib'
local socket = require'cqueues.socket'
@@ -9,6 +8,7 @@ local pprint=require'pprint'
local Queue = require'queue'
local base64 = require'base64'
local sha1 = require'sha1'
+local Channel = require'channel'
local Xmpp = {}
@@ -22,14 +22,16 @@ function Xmpp.make(wilson, conf)
name = conf.name,
wilson = wilson,
inbox = Queue.make(),
+ cq = wilson.cq, -- todo
+ nicks_inuse = {}, -- todo
}
local function conf_var(name)
assert(conf[name] ~= nil, 'missing conf field '..name)
self[name] = conf[name]
end
- conf_var 'jid'
+ -- conf_var 'jid'
conf_var 'server'
- conf_var 'resource'
+ -- conf_var 'resource'
conf_var 'component'
conf_var 'component_secret'
@@ -121,10 +123,11 @@ function Xmpp.recving(self)
if x.label == 'message' then
local fr = x.xarg.from
local t = x.xarg.to
- if body and fr:match"/" and t == 'wilson@'..self.component then
+ local from_nick = fr:match("/(.*)")
+ if not self.nicks_inuse[from_nick] and body and fr:match"/" and t == 'wilson@'..self.component then
self.wilson:deliver(Channel(self, THE_MUC), {
body = body,
- sender = '[x]'..x.xarg.from:match("/(.*)")
+ sender = '[x]'..from_nick
})
end
end
@@ -133,14 +136,13 @@ end
function Xmpp.sending(self)
local users_inuse = {}
- local nicks_inuse = {}
local function ensure_joined(muc,user,nick)
- if nicks_inuse[nick] then return end
+ if self.nicks_inuse[nick] then return end
user = user:gsub("[^a-zA-Z0-9%.]","."):match("^%.*(.-)%.*$")
while users_inuse[user] do user = user..'-' end
local jid = user..'@'..self.component
local mucjid = muc..'/'..nick
- nicks_inuse[nick] = true
+ self.nicks_inuse[nick] = true
users_inuse[user] = true
self.sock:write(xmlify(
@@ -156,10 +158,13 @@ function Xmpp.sending(self)
local jid = user..'@'..self.component
self.sock:write(xmlify(
X.message{to=THE_MUC, type='groupchat', from=jid,
- X.body{msg.body}}))
+ X.body{message.body}}))
end
end
+function Xmpp.post(self, dest_channel, message)
+ self.inbox:enqueue(dest_channel, message)
+end
return Xmpp