-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmod_post_muc.erl
69 lines (58 loc) · 2.21 KB
/
mod_post_muc.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
%%% File : mod_post_muc.erl
%%% Author : Nuno Horta <[email protected]>
%%% Copyright (C) 2015 Nuno Horta
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
-module(mod_post_muc).
-author('Nuno Horta').
-behaviour(gen_mod).
-export([start/2,
init/2,
stop/1,
post_muc/5]).
-define(PROCNAME, ?MODULE).
-include("ejabberd.hrl").
-include("jlib.hrl").
-include("logger.hrl").
start(Host, Opts) ->
?INFO_MSG("Starting mod_post_muc", [] ),
register(?PROCNAME,spawn(?MODULE, init, [Host, Opts])),
ok.
init(Host, _Opts) ->
inets:start(),
ssl:start(),
ejabberd_hooks:add(muc_filter_message, Host, ?MODULE, post_muc, 10),
ok.
stop(Host) ->
?INFO_MSG("Stopping mod_post_muc", [] ),
ejabberd_hooks:delete(muc_filter_message, Host,
?MODULE, post_muc, 10),
ok.
post_muc(Stanza, MUCState, RoomJID, FromJID, FromNick) ->
PostUrl = gen_mod:get_module_opt(FromJID#jid.lserver, ?MODULE, post_url, fun(S) -> iolist_to_binary(S) end, list_to_binary("")),
Body = xml:get_path_s(Stanza, [{elem, list_to_binary("body")}, cdata]),
if (Stanza /= "") ->
Sep = "&",
Post = ["to=", RoomJID#jid.luser, Sep,
"from=", FromJID#jid.luser, Sep,
"nick=", FromNick, Sep,
"body=", binary_to_list(Body)],
?INFO_MSG("Sending post request to ~s with body \"~s\"", [PostUrl, Post]),
httpc:request(post, {binary_to_list(PostUrl), [], "application/x-www-form-urlencoded", list_to_binary(Post)},[],[]),
Stanza;
true ->
Stanza
end.