author | Mikael Berthe <mikael@lilotux.net> |
Sat, 17 Apr 2010 15:33:23 +0200 | |
changeset 26 | c12be727375b |
parent 24 | 77a72b227d59 |
child 27 | a166e9ab8065 |
permissions | -rw-r--r-- |
0 | 1 |
|
2 |
local home = os.getenv("HOME") |
|
3 |
package.path = package.path.. |
|
4 |
";"..home.."/.mcabber/lua/?.lua".. |
|
5 |
";"..home.."/.mcabber/lua/mcbot/?.lua" |
|
6 |
home = nil |
|
7 |
||
8 |
require "mcbot.mcbot_engine" |
|
9 |
||
10 |
local mcabbot = {} |
|
11 |
mcabbot.nickname = "McBot" |
|
12 |
mcabbot.jid = "mcabbot@lilotux.net" |
|
13 |
||
24
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
14 |
local function hk_subscription (h) |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
15 |
if h.type == "subscribe" then |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
16 |
-- Let's authorize them... |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
17 |
main.run("authorization allow "..h.jid) |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
18 |
-- ... and subscribe to their own presence |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
19 |
main.run("authorization request "..h.jid) |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
20 |
return 1 |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
21 |
elseif h.type == "unsubscribe" or h.type == "unsubscribed" then |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
22 |
main.run("authorization cancel "..h.jid) |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
23 |
end |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
24 |
return 0 |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
25 |
end |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
26 |
|
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
27 |
local function hk_message_in (h) |
0 | 28 |
local perso = false |
29 |
local muc = false |
|
30 |
local message = h.message |
|
31 |
if h.groupchat and h.groupchat == "true" then |
|
32 |
muc = true |
|
33 |
end |
|
34 |
if muc == true then |
|
35 |
if h.delayed == "" and h.attention and h.attention == "true" then |
|
36 |
if h.resource and h.resource ~= mcabbot.nickname then |
|
37 |
perso = true |
|
38 |
end |
|
39 |
end |
|
40 |
else |
|
41 |
if h.jid ~= mcabbot.jid then |
|
42 |
perso = true |
|
43 |
end |
|
44 |
end |
|
45 |
if perso == true then |
|
46 |
local cmd, msg |
|
47 |
if muc == true then |
|
48 |
cmd = "say_to -q "..h.jid.." "..h.resource..": " |
|
49 |
else |
|
50 |
cmd = "say_to -q "..h.jid.."/"..h.resource.." " |
|
51 |
end |
|
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
52 |
mcabbot.message = h |
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
53 |
local res, errmsg = process(message, mcabbot, muc) |
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
54 |
mcabbot.message = nil |
0 | 55 |
if res then |
56 |
msg = res |
|
57 |
elseif errmsg then |
|
58 |
msg = "! " .. errmsg |
|
59 |
end |
|
60 |
if (msg) then main.run(cmd..msg) end |
|
61 |
end |
|
62 |
end |
|
63 |
||
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
64 |
main.hook("hook-post-message-in", hk_message_in) |
24
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
65 |
main.hook("hook-subscription", hk_subscription) |