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