author | Mikael Berthe <mikael@lilotux.net> |
Sat, 17 Apr 2010 20:56:53 +0200 | |
changeset 29 | b3da9ca12427 |
parent 28 | 510849236c58 |
child 40 | 95ba0699f365 |
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" |
|
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 |
|
32 |
if h.groupchat and h.groupchat == "true" then |
|
33 |
muc = true |
|
34 |
end |
|
35 |
if muc == true then |
|
28 | 36 |
if h.delayed == "" then |
37 |
if mcabbot.cmdprefix and message:starts(mcabbot.cmdprefix) then |
|
38 |
perso = true |
|
39 |
elseif h.attention and h.attention == "true" and |
|
40 |
h.resource and h.resource ~= mcabbot.nickname then |
|
0 | 41 |
perso = true |
42 |
end |
|
43 |
end |
|
44 |
else |
|
45 |
if h.jid ~= mcabbot.jid then |
|
46 |
perso = true |
|
47 |
end |
|
48 |
end |
|
49 |
if perso == true then |
|
50 |
local cmd, msg |
|
51 |
if muc == true then |
|
52 |
cmd = "say_to -q "..h.jid.." "..h.resource..": " |
|
53 |
else |
|
54 |
cmd = "say_to -q "..h.jid.."/"..h.resource.." " |
|
55 |
end |
|
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
56 |
mcabbot.message = h |
27
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
24
diff
changeset
|
57 |
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
|
58 |
mcabbot.message = nil |
0 | 59 |
if res then |
60 |
msg = res |
|
61 |
elseif errmsg then |
|
62 |
msg = "! " .. errmsg |
|
63 |
end |
|
64 |
if (msg) then main.run(cmd..msg) end |
|
65 |
end |
|
66 |
end |
|
67 |
||
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
68 |
main.hook("hook-post-message-in", hk_message_in) |
24
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
69 |
main.hook("hook-subscription", hk_subscription) |