annotate mod_roster_allinall/mod_roster_allinall.lua @ 4579:b305814bd930

mod_muc_dicebot: A thing to roll dice Do you see what happens, Jitsi? Do you see what happens when you make it hard for me to use a proper bot? This is what happens, Jitsi. This is what happens when you meet a stranger in the alps! Ahem. In all seriousness, this is more of a quick hack than anything else. It will look for `.r` in MUC messages and if it finds it, it'll interpret it as an instruction to roll a few dice. Injects the results in the body of the message. Eats the message alive if it is malformed.
author Jonas Schäfer <jonas@wielicki.name>
date Sat, 29 May 2021 15:17:05 +0200
parents 3ae8c81a348b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1545
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local rostermanager = require"core.rostermanager";
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local jid_join = require"util.jid".join;
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local host = module.host;
1798
3ae8c81a348b mod_roster_allinall: Cleanup, remove unused variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1545
diff changeset
4 local sessions = prosody.hosts[host].sessions;
1545
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 -- Make a *one-way* subscription. User will see when contact is online,
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 -- contact will not see when user is online.
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local function subscribe(user, contact)
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local user_jid, contact_jid = jid_join(user, host), jid_join(contact, host);
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 -- Update user's roster to say subscription request is pending...
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 rostermanager.set_contact_pending_out(user, host, contact_jid);
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 -- Update contact's roster to say subscription request is pending...
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 rostermanager.set_contact_pending_in(contact, host, user_jid);
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 -- Update contact's roster to say subscription request approved...
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 rostermanager.subscribed(contact, host, user_jid);
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 -- Update user's roster to say subscription request approved...
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 rostermanager.process_inbound_subscription_approval(user, host, contact_jid);
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19
1798
3ae8c81a348b mod_roster_allinall: Cleanup, remove unused variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1545
diff changeset
20 -- Push updates to both rosters
1545
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 rostermanager.roster_push(user, host, contact_jid);
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 rostermanager.roster_push(contact, host, user_jid);
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 end
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 module:hook("resource-bind", function(event)
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 local session = event.session;
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 local user = session.username;
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 local user_jid = jid_join(user, host);
1798
3ae8c81a348b mod_roster_allinall: Cleanup, remove unused variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1545
diff changeset
30 for contact in pairs(sessions) do
1545
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 if contact ~= user then
1798
3ae8c81a348b mod_roster_allinall: Cleanup, remove unused variables [luacheck]
Kim Alvefur <zash@zash.se>
parents: 1545
diff changeset
32 local contact_jid = jid_join(contact, host);
1545
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 if not rostermanager.is_contact_subscribed(user, host, contact_jid) then
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 subscribe(contact, user);
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 end
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 if not rostermanager.is_contact_subscribed(contact, host, user_jid) then
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 subscribe(user, contact);
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 end
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 end
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 end);
a104a159697d mod_roster_allinall: Adds all online users to the roster of newly signed in users, for a lazy everyone-in-everyones roster setup
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42