author | Mikael Berthe <mikael@lilotux.net> |
Fri, 03 Apr 2015 22:49:15 +0200 | |
changeset 71 | 63ee968309d4 |
parent 67 | 5c756a9d7d8c |
permissions | -rw-r--r-- |
66
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
1 |
|
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
2 |
-- McBot / mcabbot project |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
3 |
-- |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
4 |
-- Copyright (C) 2010-2012 Mikael Berthe <mikael@lilotux.net> |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
5 |
-- |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
6 |
-- This program is free software; you can redistribute it and/or modify |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
7 |
-- it under the terms of the GNU General Public License as published by |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
8 |
-- the Free Software Foundation; either version 2 of the License, or (at |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
9 |
-- your option) any later version. |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
10 |
-- |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
11 |
-- Please check the license in the COPYING file at the root of the tree. |
d9c00a9fe9d5
Add notices before public release
Mikael Berthe <mikael@lilotux.net>
parents:
41
diff
changeset
|
12 |
-- |
0 | 13 |
|
14 |
local home = os.getenv("HOME") |
|
15 |
package.path = package.path.. |
|
67
5c756a9d7d8c
Quick'n dirty hack to remove hardcoded paths
Mikael Berthe <mikael@lilotux.net>
parents:
66
diff
changeset
|
16 |
";"..home.."/.mcabber/mcabbot/?.lua".. |
5c756a9d7d8c
Quick'n dirty hack to remove hardcoded paths
Mikael Berthe <mikael@lilotux.net>
parents:
66
diff
changeset
|
17 |
";"..home.."/.mcabber/mcabbot/mcbot/?.lua" |
0 | 18 |
home = nil |
19 |
||
20 |
require "mcbot.mcbot_engine" |
|
21 |
||
22 |
local mcabbot = {} |
|
23 |
mcabbot.nickname = "McBot" |
|
40 | 24 |
mcabbot.jid = "mcbot@lilotux.net" |
27
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
24
diff
changeset
|
25 |
mcabbot.cmdprefix = "%%" |
0 | 26 |
|
24
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
27 |
local function hk_subscription (h) |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
28 |
if h.type == "subscribe" then |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
29 |
-- Let's authorize them... |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
30 |
main.run("authorization allow "..h.jid) |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
31 |
-- ... and subscribe to their own presence |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
32 |
main.run("authorization request "..h.jid) |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
33 |
return 1 |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
34 |
elseif h.type == "unsubscribe" or h.type == "unsubscribed" then |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
35 |
main.run("authorization cancel "..h.jid) |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
36 |
end |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
37 |
return 0 |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
38 |
end |
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
39 |
|
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
40 |
local function hk_message_in (h) |
0 | 41 |
local perso = false |
42 |
local muc = false |
|
43 |
local message = h.message |
|
41
5c0a2db896f5
Ignore incoming error messages
Mikael Berthe <mikael@lilotux.net>
parents:
40
diff
changeset
|
44 |
|
5c0a2db896f5
Ignore incoming error messages
Mikael Berthe <mikael@lilotux.net>
parents:
40
diff
changeset
|
45 |
if h.error and h.error == "true" then return end |
5c0a2db896f5
Ignore incoming error messages
Mikael Berthe <mikael@lilotux.net>
parents:
40
diff
changeset
|
46 |
|
0 | 47 |
if h.groupchat and h.groupchat == "true" then |
48 |
muc = true |
|
49 |
end |
|
50 |
if muc == true then |
|
28 | 51 |
if h.delayed == "" then |
52 |
if mcabbot.cmdprefix and message:starts(mcabbot.cmdprefix) then |
|
53 |
perso = true |
|
54 |
elseif h.attention and h.attention == "true" and |
|
55 |
h.resource and h.resource ~= mcabbot.nickname then |
|
0 | 56 |
perso = true |
57 |
end |
|
58 |
end |
|
59 |
else |
|
60 |
if h.jid ~= mcabbot.jid then |
|
61 |
perso = true |
|
62 |
end |
|
63 |
end |
|
64 |
if perso == true then |
|
65 |
local cmd, msg |
|
66 |
if muc == true then |
|
67 |
cmd = "say_to -q "..h.jid.." "..h.resource..": " |
|
68 |
else |
|
69 |
cmd = "say_to -q "..h.jid.."/"..h.resource.." " |
|
70 |
end |
|
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
71 |
mcabbot.message = h |
27
a166e9ab8065
Add command prefix (useful for MUC rooms)
Mikael Berthe <mikael@lilotux.net>
parents:
24
diff
changeset
|
72 |
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
|
73 |
mcabbot.message = nil |
0 | 74 |
if res then |
75 |
msg = res |
|
76 |
elseif errmsg then |
|
77 |
msg = "! " .. errmsg |
|
78 |
end |
|
79 |
if (msg) then main.run(cmd..msg) end |
|
80 |
end |
|
81 |
end |
|
82 |
||
1
cca972635e5e
Provid more data to the bot functions
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
83 |
main.hook("hook-post-message-in", hk_message_in) |
24
77a72b227d59
Handle subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
1
diff
changeset
|
84 |
main.hook("hook-subscription", hk_subscription) |