Software /
code /
prosody-modules
Comparison
mod_swedishchef/mod_swedishchef.lua @ 22:8d49732cf7dc
mod_swedishchef: Initial commit
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Fri, 02 Oct 2009 02:04:55 +0200 |
child | 26:1fb5b8c20004 |
comparison
equal
deleted
inserted
replaced
21:4f18696f043a | 22:8d49732cf7dc |
---|---|
1 -- Copyright (C) 2009 Florian Zeitz | |
2 -- Copyright (C) 2009 Matthew Wild | |
3 -- | |
4 -- This project is MIT/X11 licensed. Please see the | |
5 -- COPYING file in the source package for more information. | |
6 -- | |
7 local st = require "util.stanza"; | |
8 | |
9 local chef = { | |
10 { th = "t" }, | |
11 | |
12 { ow = "o"}, | |
13 {["([^%w])o"] = "%1oo", | |
14 O = "Oo"}, | |
15 | |
16 {au = "oo", | |
17 u = "oo", U = "Oo"}, | |
18 {["([^o])o([^o])"] = "%1u%2"}, | |
19 {ir = "ur", | |
20 | |
21 an = "un", An = "Un", Au = "Oo"}, | |
22 | |
23 {e = "i", E = "I"}, | |
24 | |
25 { i = function () return select(math.random(2), "i", "ee"); end }, | |
26 | |
27 {a = "e", A = "E"}, | |
28 | |
29 {["e([^%w])"] = "e-a%1"}, | |
30 {f = "ff"}, | |
31 | |
32 {v = "f", V = "F"}, | |
33 {w = "v", W = "V"} }; | |
34 | |
35 function swedish(english) | |
36 local eng, url = english:match("(.*)(http://.*)$"); | |
37 if eng then english = eng; end | |
38 | |
39 for _,v in ipairs(chef) do | |
40 for k,v in pairs(v) do | |
41 english = english:gsub(k,v); | |
42 end | |
43 end | |
44 english = english:gsub("the", "zee"); | |
45 english = english:gsub("The", "Zee"); | |
46 english = english:gsub("tion", "shun"); | |
47 english = english:gsub("[.!?]$", "%1\nBork Bork Bork!"); | |
48 return tostring(english..((url and url) or "")); | |
49 end | |
50 | |
51 function check_message(data) | |
52 local origin, stanza = data.origin, data.stanza; | |
53 | |
54 local body, bodyindex; | |
55 for k,v in ipairs(stanza) do | |
56 if v.name == "body" then | |
57 body, bodyindex = v, k; | |
58 end | |
59 end | |
60 | |
61 if not body then return; end | |
62 body = body:get_text(); | |
63 | |
64 if body then | |
65 stanza[bodyindex][1] = swedish(body); | |
66 end | |
67 end | |
68 | |
69 module:hook("message/bare", check_message); | |
70 |