annotate mod_swedishchef/mod_swedishchef.lua @ 2481:854aaa1f01b2

mod_migrate/README: Document the ability to specify multiple comma separated stores to migrate
author Kim Alvefur <zash@zash.se>
date Thu, 02 Feb 2017 20:19:37 +0100
parents 7dbde05b48a9
children 2615facc461b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
1 -- Copyright (C) 2009 Florian Zeitz
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
2 -- Copyright (C) 2009 Matthew Wild
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 985
diff changeset
3 --
22
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
4 -- This project is MIT/X11 licensed. Please see the
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
5 -- COPYING file in the source package for more information.
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6 --
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
7
985
93ef813dfd06 mod_swedishchef: Use newer config API
Kim Alvefur <zash@zash.se>
parents: 26
diff changeset
8 local trigger_string = module:get_option_string("swedishchef_trigger");
26
1fb5b8c20004 mod_swedishchef: Added configurable trigger
Florian Zeitz <florob@babelmonkeys.de>
parents: 22
diff changeset
9 trigger_string = (trigger_string and trigger_string .. " ") or "";
1fb5b8c20004 mod_swedishchef: Added configurable trigger
Florian Zeitz <florob@babelmonkeys.de>
parents: 22
diff changeset
10
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 985
diff changeset
11 local chef = {
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 985
diff changeset
12 { th = "t" },
22
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
13
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
14 { ow = "o"},
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
15 {["([^%w])o"] = "%1oo",
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
16 O = "Oo"},
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
17
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
18 {au = "oo",
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
19 u = "oo", U = "Oo"},
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
20 {["([^o])o([^o])"] = "%1u%2"},
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
21 {ir = "ur",
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
22
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
23 an = "un", An = "Un", Au = "Oo"},
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
24
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
25 {e = "i", E = "I"},
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
26
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
27 { i = function () return select(math.random(2), "i", "ee"); end },
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
28
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
29 {a = "e", A = "E"},
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
30
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
31 {["e([^%w])"] = "e-a%1"},
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 985
diff changeset
32 {f = "ff"},
22
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
33
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
34 {v = "f", V = "F"},
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
35 {w = "v", W = "V"} };
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 985
diff changeset
36
22
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
37 function swedish(english)
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
38 local eng, url = english:match("(.*)(http://.*)$");
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
39 if eng then english = eng; end
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
40
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
41 for _,v in ipairs(chef) do
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
42 for k,v in pairs(v) do
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
43 english = english:gsub(k,v);
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
44 end
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
45 end
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
46 english = english:gsub("the", "zee");
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
47 english = english:gsub("The", "Zee");
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
48 english = english:gsub("tion", "shun");
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
49 english = english:gsub("[.!?]$", "%1\nBork Bork Bork!");
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
50 return tostring(english..((url and url) or ""));
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
51 end
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
52
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
53 function check_message(data)
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
54 local origin, stanza = data.origin, data.stanza;
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 985
diff changeset
55
22
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
56 local body, bodyindex;
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
57 for k,v in ipairs(stanza) do
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
58 if v.name == "body" then
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
59 body, bodyindex = v, k;
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
60 end
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
61 end
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 985
diff changeset
62
22
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
63 if not body then return; end
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
64 body = body:get_text();
1343
7dbde05b48a9 all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 985
diff changeset
65
26
1fb5b8c20004 mod_swedishchef: Added configurable trigger
Florian Zeitz <florob@babelmonkeys.de>
parents: 22
diff changeset
66 if body and (body:find(trigger_string, 1, true) == 1) then
1fb5b8c20004 mod_swedishchef: Added configurable trigger
Florian Zeitz <florob@babelmonkeys.de>
parents: 22
diff changeset
67 module:log("debug", body:find(trigger_string, 1, true));
1fb5b8c20004 mod_swedishchef: Added configurable trigger
Florian Zeitz <florob@babelmonkeys.de>
parents: 22
diff changeset
68 stanza[bodyindex][1] = swedish(body:gsub("^" .. trigger_string, "", 1));
22
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
69 end
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
70 end
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
71
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
72 module:hook("message/bare", check_message);
8d49732cf7dc mod_swedishchef: Initial commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
73