Software /
code /
prosody
Comparison
plugins/mod_scansion_record.lua @ 9344:d36fa7d164c0
mod_scansion_record: Unfinished code dump from Matthew
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 22 Sep 2018 13:50:00 +0200 |
child | 9345:3c5c0a2521d5 |
comparison
equal
deleted
inserted
replaced
9343:e767da06399d | 9344:d36fa7d164c0 |
---|---|
1 local names = { "Romeo", "Juliet", "Mercutio", "Tybalt", "Benvolio" }; | |
2 local devices = { "", "phone", "laptop", "tablet", "toaster", "fridge", "shoe" }; | |
3 local users = {}; | |
4 | |
5 local full_jids = {}; | |
6 | |
7 local id = require "util.id"; | |
8 | |
9 local record_file = | |
10 | |
11 local function record(string) | |
12 | |
13 | |
14 local function record_event(session, event) | |
15 end | |
16 | |
17 local function record_stanza(stanza, session, verb) | |
18 record(session.scansion_id.." "..verb..":\n\t"..tostring(stanza).."\n\n"; | |
19 end | |
20 | |
21 local function record_stanza_in(stanza, session) | |
22 end | |
23 | |
24 local function record_stanza_out(stanza, session) | |
25 end | |
26 | |
27 module:hook("resource-bind", function (event) | |
28 local session = event.session; | |
29 if not users[session.username] then | |
30 users[session.username] = { | |
31 character = table.remove(names, 1) or id.short(); | |
32 devices = {}; | |
33 n_devices = 0; | |
34 }; | |
35 end | |
36 local user = users[session.username]; | |
37 local device = user.devices[event.resource]; | |
38 if not device then | |
39 user.n_devices = user.n_devices + 1; | |
40 device = devices[user.n_devices] or ("device"..id.short()); | |
41 user.devices[event.resource] = device; | |
42 end | |
43 session.scansion_character = user.character; | |
44 session.scansion_device = device; | |
45 session.scansion_id = user.character..(device ~= "" and "'s "..device" or device); | |
46 | |
47 full_jids[session.full_jid] = session.scansion_id; | |
48 | |
49 module:log("warn", "Connected: %s's %s", user.character, device); | |
50 | |
51 filters.add_filter(session, "stanzas/in", record_stanza_in); | |
52 filters.add_filter(session, "stanzas/out", record_stanza_out); | |
53 end); | |
54 |