Mercurial > prosody-modules
annotate mod_test_data/mod_test_data.lua @ 5173:460f78654864
mod_muc_rtbl: also filter messages
This was a bit tricky because we don't want to run the JIDs
through SHA256 on each message. Took a while to come up with this
simple plan of just caching the SHA256 of the JIDs on the
occupants.
This will leave some dirt in the occupants after unloading the
module, but that should be ok; once they cycle the room, the
hashes will be gone.
This is direly needed, otherwise, there is a tight race between
the moderation activities and the actors joining the room.
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Tue, 21 Feb 2023 21:37:27 +0100 |
parents | af824168729a |
children |
rev | line source |
---|---|
3357
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local users = { "fezziwig", "badger", "nupkins", "pumblechook", "rouncewell" }; |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local host = "localhost"; |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local id = require "util.id"; |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local st = require "util.stanza"; |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local sm = require "core.storagemanager"; |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 -- Return a random number from 1..max excluding n |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 function random_other(n, max) return ((math.random(1, max-1)+(n-1))%max)+1; end |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local new_time; |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 do |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local _current_time = os.time(); |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 function new_time() |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 _current_time = _current_time + math.random(1, 3600); |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 return _current_time; |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 end |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 function module.command(arg) --luacheck: ignore arg |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 sm.initialize_host(host); |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 local archive = sm.open(host, "archive", "archive"); |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 for _ = 1, 100000 do |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local random = math.random(1, #users); |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 local user, contact = users[random], users[random_other(random, #users)]; |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 local user_jid, contact_jid = user.."@"..host, contact.."@"..host; |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 local stanza = st.message({ to = contact_jid, from = user_jid, type="chat" }) |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 :tag("body"):text(id.long()); |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 archive:append(user, nil, stanza, new_time(), contact_jid) |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 local stanza2 = st.clone(stanza); |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 stanza2.attr.from, stanza2.attr.to = stanza.attr.to, stanza.attr.from; |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 archive:append(contact, nil, stanza2, new_time(), user_jid) |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
af824168729a
mod_test_data: New module to generate test data in Prosody's data store
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 end |