author | Mikael Berthe <mikael@lilotux.net> |
Sun, 16 May 2010 13:43:31 +0200 | |
changeset 41 | 5c0a2db896f5 |
parent 40 | 95ba0699f365 |
child 66 | d9c00a9fe9d5 |
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" |
|
40 | 12 |
mcabbot.jid = "mcbot@lilotux.net" |
27
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
24
diff
changeset
|
13 |
mcabbot.cmdprefix = "%%" |
0 | 14 |
|
24
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
15 |
local function hk_subscription (h) |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
16 |
if h.type == "subscribe" then |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
17 |
-- Let's authorize them... |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
18 |
main.run("authorization allow "..h.jid) |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
19 |
-- ... and subscribe to their own presence |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
20 |
main.run("authorization request "..h.jid) |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
21 |
return 1 |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
22 |
elseif h.type == "unsubscribe" or h.type == "unsubscribed" then |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
23 |
main.run("authorization cancel "..h.jid) |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
24 |
end |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
25 |
return 0 |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
26 |
end |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
27 |
|
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
28 |
local function hk_message_in (h) |
0 | 29 |
local perso = false |
30 |
local muc = false |
|
31 |
local message = h.message |
|
41
5c0a2db896f5
Ignore incoming error messages
Mikael Berthe <mikael@lilotux.net>
parents:
40
diff
changeset
|
32 |
|
5c0a2db896f5
Ignore incoming error messages
Mikael Berthe <mikael@lilotux.net>
parents:
40
diff
changeset
|
33 |
if h.error and h.error == "true" then return end |
5c0a2db896f5
Ignore incoming error messages
Mikael Berthe <mikael@lilotux.net>
parents:
40
diff
changeset
|
34 |
|
0 | 35 |
if h.groupchat and h.groupchat == "true" then |
36 |
muc = true |
|
37 |
end |
|
38 |
if muc == true then |
|
28 | 39 |
if h.delayed == "" then |
40 |
if mcabbot.cmdprefix and message:starts(mcabbot.cmdprefix) then |
|
41 |
perso = true |
|
42 |
elseif h.attention and h.attention == "true" and |
|
43 |
h.resource and h.resource ~= mcabbot.nickname then |
|
0 | 44 |
perso = true |
45 |
end |
|
46 |
end |
|
47 |
else |
|
48 |
if h.jid ~= mcabbot.jid then |
|
49 |
perso = true |
|
50 |
end |
|
51 |
end |
|
52 |
if perso == true then |
|
53 |
local cmd, msg |
|
54 |
if muc == true then |
|
55 |
cmd = "say_to -q "..h.jid.." "..h.resource..": " |
|
56 |
else |
|
57 |
cmd = "say_to -q "..h.jid.."/"..h.resource.." " |
|
58 |
end |
|
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
59 |
mcabbot.message = h |
27
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
24
diff
changeset
|
60 |
local res, errmsg = process(message, mcabbot, muc, mcabbot.cmdprefix) |
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
61 |
mcabbot.message = nil |
0 | 62 |
if res then |
63 |
msg = res |
|
64 |
elseif errmsg then |
|
65 |
msg = "! " .. errmsg |
|
66 |
end |
|
67 |
if (msg) then main.run(cmd..msg) end |
|
68 |
end |
|
69 |
end |
|
70 |
||
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
71 |
main.hook("hook-post-message-in", hk_message_in) |
24
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
72 |
main.hook("hook-subscription", hk_subscription) |