# HG changeset patch # User Kim Alvefur # Date 1537617000 -7200 # Node ID d36fa7d164c013596a3cd7ef63b4de6561c8be42 # Parent e767da06399d1a668375b3c1e515ebc3d1b8cbee mod_scansion_record: Unfinished code dump from Matthew diff -r e767da06399d -r d36fa7d164c0 plugins/mod_scansion_record.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/mod_scansion_record.lua Sat Sep 22 13:50:00 2018 +0200 @@ -0,0 +1,54 @@ +local names = { "Romeo", "Juliet", "Mercutio", "Tybalt", "Benvolio" }; +local devices = { "", "phone", "laptop", "tablet", "toaster", "fridge", "shoe" }; +local users = {}; + +local full_jids = {}; + +local id = require "util.id"; + +local record_file = + +local function record(string) + + +local function record_event(session, event) +end + +local function record_stanza(stanza, session, verb) + record(session.scansion_id.." "..verb..":\n\t"..tostring(stanza).."\n\n"; +end + +local function record_stanza_in(stanza, session) +end + +local function record_stanza_out(stanza, session) +end + +module:hook("resource-bind", function (event) + local session = event.session; + if not users[session.username] then + users[session.username] = { + character = table.remove(names, 1) or id.short(); + devices = {}; + n_devices = 0; + }; + end + local user = users[session.username]; + local device = user.devices[event.resource]; + if not device then + user.n_devices = user.n_devices + 1; + device = devices[user.n_devices] or ("device"..id.short()); + user.devices[event.resource] = device; + end + session.scansion_character = user.character; + session.scansion_device = device; + session.scansion_id = user.character..(device ~= "" and "'s "..device" or device); + + full_jids[session.full_jid] = session.scansion_id; + + module:log("warn", "Connected: %s's %s", user.character, device); + + filters.add_filter(session, "stanzas/in", record_stanza_in); + filters.add_filter(session, "stanzas/out", record_stanza_out); +end); +